-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermostats.py
449 lines (386 loc) · 17.2 KB
/
thermostats.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
from typing import Optional, Any, List, Dict, Union
from ..client import SeamHttpClient
from .models import AbstractThermostats, ActionAttempt, Device
from .thermostats_schedules import ThermostatsSchedules
from .thermostats_simulate import ThermostatsSimulate
from ..modules.action_attempts import resolve_action_attempt
class Thermostats(AbstractThermostats):
def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):
self.client = client
self.defaults = defaults
self._schedules = ThermostatsSchedules(client=client, defaults=defaults)
self._simulate = ThermostatsSimulate(client=client, defaults=defaults)
@property
def schedules(self) -> ThermostatsSchedules:
return self._schedules
@property
def simulate(self) -> ThermostatsSimulate:
return self._simulate
def activate_climate_preset(
self,
*,
climate_preset_key: str,
device_id: str,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if climate_preset_key is not None:
json_payload["climate_preset_key"] = climate_preset_key
if device_id is not None:
json_payload["device_id"] = device_id
res = self.client.post(
"/thermostats/activate_climate_preset", json=json_payload
)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def cool(
self,
*,
device_id: str,
cooling_set_point_celsius: Optional[float] = None,
cooling_set_point_fahrenheit: Optional[float] = None,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if cooling_set_point_celsius is not None:
json_payload["cooling_set_point_celsius"] = cooling_set_point_celsius
if cooling_set_point_fahrenheit is not None:
json_payload["cooling_set_point_fahrenheit"] = cooling_set_point_fahrenheit
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/thermostats/cool", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def create_climate_preset(
self,
*,
climate_preset_key: str,
device_id: str,
cooling_set_point_celsius: Optional[float] = None,
cooling_set_point_fahrenheit: Optional[float] = None,
fan_mode_setting: Optional[str] = None,
heating_set_point_celsius: Optional[float] = None,
heating_set_point_fahrenheit: Optional[float] = None,
hvac_mode_setting: Optional[str] = None,
manual_override_allowed: Optional[bool] = None,
name: Optional[str] = None
) -> None:
json_payload = {}
if climate_preset_key is not None:
json_payload["climate_preset_key"] = climate_preset_key
if device_id is not None:
json_payload["device_id"] = device_id
if cooling_set_point_celsius is not None:
json_payload["cooling_set_point_celsius"] = cooling_set_point_celsius
if cooling_set_point_fahrenheit is not None:
json_payload["cooling_set_point_fahrenheit"] = cooling_set_point_fahrenheit
if fan_mode_setting is not None:
json_payload["fan_mode_setting"] = fan_mode_setting
if heating_set_point_celsius is not None:
json_payload["heating_set_point_celsius"] = heating_set_point_celsius
if heating_set_point_fahrenheit is not None:
json_payload["heating_set_point_fahrenheit"] = heating_set_point_fahrenheit
if hvac_mode_setting is not None:
json_payload["hvac_mode_setting"] = hvac_mode_setting
if manual_override_allowed is not None:
json_payload["manual_override_allowed"] = manual_override_allowed
if name is not None:
json_payload["name"] = name
self.client.post("/thermostats/create_climate_preset", json=json_payload)
return None
def delete_climate_preset(self, *, climate_preset_key: str, device_id: str) -> None:
json_payload = {}
if climate_preset_key is not None:
json_payload["climate_preset_key"] = climate_preset_key
if device_id is not None:
json_payload["device_id"] = device_id
self.client.post("/thermostats/delete_climate_preset", json=json_payload)
return None
def heat(
self,
*,
device_id: str,
heating_set_point_celsius: Optional[float] = None,
heating_set_point_fahrenheit: Optional[float] = None,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if heating_set_point_celsius is not None:
json_payload["heating_set_point_celsius"] = heating_set_point_celsius
if heating_set_point_fahrenheit is not None:
json_payload["heating_set_point_fahrenheit"] = heating_set_point_fahrenheit
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/thermostats/heat", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def heat_cool(
self,
*,
device_id: str,
cooling_set_point_celsius: Optional[float] = None,
cooling_set_point_fahrenheit: Optional[float] = None,
heating_set_point_celsius: Optional[float] = None,
heating_set_point_fahrenheit: Optional[float] = None,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if cooling_set_point_celsius is not None:
json_payload["cooling_set_point_celsius"] = cooling_set_point_celsius
if cooling_set_point_fahrenheit is not None:
json_payload["cooling_set_point_fahrenheit"] = cooling_set_point_fahrenheit
if heating_set_point_celsius is not None:
json_payload["heating_set_point_celsius"] = heating_set_point_celsius
if heating_set_point_fahrenheit is not None:
json_payload["heating_set_point_fahrenheit"] = heating_set_point_fahrenheit
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/thermostats/heat_cool", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def list(
self,
*,
connect_webview_id: Optional[str] = None,
connected_account_id: Optional[str] = None,
connected_account_ids: Optional[List[str]] = None,
created_before: Optional[str] = None,
custom_metadata_has: Optional[Dict[str, Any]] = None,
device_ids: Optional[List[str]] = None,
device_type: Optional[str] = None,
device_types: Optional[List[str]] = None,
exclude_if: Optional[List[str]] = None,
include_if: Optional[List[str]] = None,
limit: Optional[float] = None,
manufacturer: Optional[str] = None,
unstable_location_id: Optional[str] = None,
user_identifier_key: Optional[str] = None
) -> List[Device]:
json_payload = {}
if connect_webview_id is not None:
json_payload["connect_webview_id"] = connect_webview_id
if connected_account_id is not None:
json_payload["connected_account_id"] = connected_account_id
if connected_account_ids is not None:
json_payload["connected_account_ids"] = connected_account_ids
if created_before is not None:
json_payload["created_before"] = created_before
if custom_metadata_has is not None:
json_payload["custom_metadata_has"] = custom_metadata_has
if device_ids is not None:
json_payload["device_ids"] = device_ids
if device_type is not None:
json_payload["device_type"] = device_type
if device_types is not None:
json_payload["device_types"] = device_types
if exclude_if is not None:
json_payload["exclude_if"] = exclude_if
if include_if is not None:
json_payload["include_if"] = include_if
if limit is not None:
json_payload["limit"] = limit
if manufacturer is not None:
json_payload["manufacturer"] = manufacturer
if unstable_location_id is not None:
json_payload["unstable_location_id"] = unstable_location_id
if user_identifier_key is not None:
json_payload["user_identifier_key"] = user_identifier_key
res = self.client.post("/thermostats/list", json=json_payload)
return [Device.from_dict(item) for item in res["devices"]]
def off(
self,
*,
device_id: str,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/thermostats/off", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def set_fallback_climate_preset(
self, *, climate_preset_key: str, device_id: str
) -> None:
json_payload = {}
if climate_preset_key is not None:
json_payload["climate_preset_key"] = climate_preset_key
if device_id is not None:
json_payload["device_id"] = device_id
self.client.post("/thermostats/set_fallback_climate_preset", json=json_payload)
return None
def set_fan_mode(
self,
*,
device_id: str,
fan_mode: Optional[str] = None,
fan_mode_setting: Optional[str] = None,
sync: Optional[bool] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if fan_mode is not None:
json_payload["fan_mode"] = fan_mode
if fan_mode_setting is not None:
json_payload["fan_mode_setting"] = fan_mode_setting
if sync is not None:
json_payload["sync"] = sync
res = self.client.post("/thermostats/set_fan_mode", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def set_hvac_mode(
self,
*,
device_id: str,
hvac_mode_setting: str,
cooling_set_point_celsius: Optional[float] = None,
cooling_set_point_fahrenheit: Optional[float] = None,
heating_set_point_celsius: Optional[float] = None,
heating_set_point_fahrenheit: Optional[float] = None,
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None
) -> ActionAttempt:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if hvac_mode_setting is not None:
json_payload["hvac_mode_setting"] = hvac_mode_setting
if cooling_set_point_celsius is not None:
json_payload["cooling_set_point_celsius"] = cooling_set_point_celsius
if cooling_set_point_fahrenheit is not None:
json_payload["cooling_set_point_fahrenheit"] = cooling_set_point_fahrenheit
if heating_set_point_celsius is not None:
json_payload["heating_set_point_celsius"] = heating_set_point_celsius
if heating_set_point_fahrenheit is not None:
json_payload["heating_set_point_fahrenheit"] = heating_set_point_fahrenheit
res = self.client.post("/thermostats/set_hvac_mode", json=json_payload)
wait_for_action_attempt = (
self.defaults.get("wait_for_action_attempt")
if wait_for_action_attempt is None
else wait_for_action_attempt
)
return resolve_action_attempt(
client=self.client,
action_attempt=ActionAttempt.from_dict(res["action_attempt"]),
wait_for_action_attempt=wait_for_action_attempt,
)
def set_temperature_threshold(
self,
*,
device_id: str,
lower_limit_celsius: Optional[float] = None,
lower_limit_fahrenheit: Optional[float] = None,
upper_limit_celsius: Optional[float] = None,
upper_limit_fahrenheit: Optional[float] = None
) -> None:
json_payload = {}
if device_id is not None:
json_payload["device_id"] = device_id
if lower_limit_celsius is not None:
json_payload["lower_limit_celsius"] = lower_limit_celsius
if lower_limit_fahrenheit is not None:
json_payload["lower_limit_fahrenheit"] = lower_limit_fahrenheit
if upper_limit_celsius is not None:
json_payload["upper_limit_celsius"] = upper_limit_celsius
if upper_limit_fahrenheit is not None:
json_payload["upper_limit_fahrenheit"] = upper_limit_fahrenheit
self.client.post("/thermostats/set_temperature_threshold", json=json_payload)
return None
def update_climate_preset(
self,
*,
climate_preset_key: str,
device_id: str,
manual_override_allowed: bool,
cooling_set_point_celsius: Optional[float] = None,
cooling_set_point_fahrenheit: Optional[float] = None,
fan_mode_setting: Optional[str] = None,
heating_set_point_celsius: Optional[float] = None,
heating_set_point_fahrenheit: Optional[float] = None,
hvac_mode_setting: Optional[str] = None,
name: Optional[str] = None
) -> None:
json_payload = {}
if climate_preset_key is not None:
json_payload["climate_preset_key"] = climate_preset_key
if device_id is not None:
json_payload["device_id"] = device_id
if manual_override_allowed is not None:
json_payload["manual_override_allowed"] = manual_override_allowed
if cooling_set_point_celsius is not None:
json_payload["cooling_set_point_celsius"] = cooling_set_point_celsius
if cooling_set_point_fahrenheit is not None:
json_payload["cooling_set_point_fahrenheit"] = cooling_set_point_fahrenheit
if fan_mode_setting is not None:
json_payload["fan_mode_setting"] = fan_mode_setting
if heating_set_point_celsius is not None:
json_payload["heating_set_point_celsius"] = heating_set_point_celsius
if heating_set_point_fahrenheit is not None:
json_payload["heating_set_point_fahrenheit"] = heating_set_point_fahrenheit
if hvac_mode_setting is not None:
json_payload["hvac_mode_setting"] = hvac_mode_setting
if name is not None:
json_payload["name"] = name
self.client.post("/thermostats/update_climate_preset", json=json_payload)
return None