-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive-dyson.py
84 lines (77 loc) · 3.4 KB
/
interactive-dyson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Bypass SSL Warning
import requests
import getpass
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Import Dyson Modules
from libpurecoollink.dyson import DysonAccount
from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation, \
FanState, StandbyMonitoring, QualityTarget, ResetFilter, HeatMode, \
FocusMode, HeatTarget
# Get Username and Password Inputs using Interactive Input:
dyson_username = input("Enter Dyson Account Username: ")
dyson_password = getpass.getpass("Enter Dyson Account Password: ")
# Override with static values if you want:
# dyson_username = "[email protected]"
# dyson_password = "my_cool_password"
# Log to Dyson account
dyson_account = DysonAccount(dyson_username, dyson_password, "GB")
logged = dyson_account.login()
# If Error, Stop
if not logged:
print('Unable to login to Dyson account. Exiting.')
exit(1)
# Connect to Dyson Fan (first and only device assumed)
devices = dyson_account.devices()
connected = devices[0].auto_connect()
# Chat Loop
while(True):
# Commands are help, status, on, off, oscillate, night, speed, sleep or heat
command = input("Enter a Command (try help): ")
if(command == "help"):
print("Available Commands: ")
print(" - on")
print(" - off")
print(" - status")
print(" - speed 1-10")
print(" - 'heat 15-30'C")
print(" -'oscillate on/off")
print(" - 'sleep 0-60' minutes")
elif(command == "status"):
print("Fan Mode: " + devices[0].state.fan_mode);
print("Speed: " + devices[0].state.speed)
print("Oscillation: " + devices[0].state.oscillation)
print("Tilt: " + devices[0].state.tilt)
print("Heat Mode: " + devices[0].state.heat_mode)
print("Heat State: " + devices[0].state.heat_state)
print("Heat Target: " + devices[0].state.heat_target)
elif(command == "on"):
print("Turning Dyson On")
devices[0].set_configuration(fan_mode=FanMode.FAN)
elif(command == "off"):
print("Turning Dyson Off")
devices[0].set_configuration(fan_mode=FanMode.OFF)
elif("oscillate" in command):
if(command[-1] == "n"):
devices[0].set_configuration(oscillation=Oscillation.OSCILLATION_ON)
elif(command[-1] == "f"):
devices[0].set_configuration(oscillation=Oscillation.OSCILLATION_OFF)
elif("night" in command):
if(command[-1] == "n"):
devices[0].set_configuration(night_mode=NightMode.NIGHT_MODE_ON)
elif(command[-1] == "f"):
devices[0].set_configuration(night_mode=NightMode.NIGHT_MODE_OFF)
else:
# At this point, we're dealing with parameters with numbers (speed, heat and sleep)
if("speed" in command):
parameter = command.split()[-1]
print("Setting Speed to " + parameter)
devices[0].set_configuration(fan_speed=FanSpeed["FAN_SPEED_" + parameter])
elif("heat" in command):
parameter = command.split()[-1]
print("Setting Heat to " + parameter + "C")
devices[0].set_configuration(heat_target=HeatTarget.celsius(parameter))
elif("sleep" in command):
parameter = int(command.split()[-1])
print("Sleeping in " + parameter + " minutes")
devices[0].set_configuration(sleep_timer=parameter)