-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
100 lines (81 loc) · 2.88 KB
/
handler.py
File metadata and controls
100 lines (81 loc) · 2.88 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from libpurecoollink.dyson import DysonAccount
import os
import json
def stats(event, context):
# Log to Dyson account
dyson_account = DysonAccount(os.environ['DYSON_EMAIL'], os.environ['DYSON_PASS'], os.environ['DYSON_LANG'])
logged = dyson_account.login()
if not logged:
body = {
"message": "Unable to login to Dyson account"
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
# List devices available on the Dyson account
devices = dyson_account.devices()
if os.environ['DYSON_ENDPOINT']:
# Connect using discovery to the first device
connected = devices[0].connect(os.environ['DYSON_ENDPOINT'])
else:
# Connect using discovery to the first device
connected = devices[0].auto_connect()
if connected:
body = {
"state": devices[0].state.fan_mode,
"fan_state": devices[0].state.fan_state,
"night_mode": devices[0].state.night_mode,
"speed": devices[0].state.speed,
"oscillation": devices[0].state.oscillation,
"filter_life": devices[0].state.filter_life,
"quality_target": devices[0].state.quality_target,
"standby_monitoring": devices[0].state.standby_monitoring,
"tilt": devices[0].state.tilt,
"focus_mode": devices[0].state.focus_mode,
"heat_mode": devices[0].state.heat_mode,
"heat_target": devices[0].state.heat_target,
"heat_state": devices[0].state.heat_state
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
# Disconnect
devices[0].disconnect()
return response
def sleep_timer(event, context):
# Log to Dyson account
dyson_account = DysonAccount(os.environ['DYSON_EMAIL'], os.environ['DYSON_PASS'], os.environ['DYSON_LANG'])
logged = dyson_account.login()
if not logged:
body = {
"message": "Unable to login to Dyson account"
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
# List devices available on the Dyson account
devices = dyson_account.devices()
if os.environ['DYSON_ENDPOINT']:
# Connect using discovery to the first device
connected = devices[0].connect(os.environ['DYSON_ENDPOINT'])
else:
# Connect using discovery to the first device
connected = devices[0].auto_connect()
if connected:
timer = event['sleep_timer']
devices[0].set_configuration(sleep_timer=timer)
body = {
"sleep_timer": timer
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
# Disconnect
devices[0].disconnect()
return response