1
1
from seamapi .types import (
2
2
AbstractThermostats ,
3
+ ActionAttempt ,
3
4
ConnectWebview ,
4
5
ConnectWebviewId ,
5
6
ConnectedAccount ,
@@ -50,7 +51,9 @@ def __init__(self, seam: Seam):
50
51
"""
51
52
52
53
self .seam = seam
53
- self .climate_setting_schedules = ClimateSettingSchedules (seam = self .seam )
54
+ self .climate_setting_schedules = ClimateSettingSchedules (
55
+ seam = self .seam
56
+ )
54
57
55
58
@report_error
56
59
def list (
@@ -91,7 +94,7 @@ def list(
91
94
connect_webview
92
95
)
93
96
if device_ids is not None :
94
- params ["device_ids" ] = [to_device_id (d ) for d in device_ids ]
97
+ params ["device_ids" ] = [to_device_id (d ) for d in device_ids ]
95
98
96
99
res = self .seam .make_request (
97
100
"GET" ,
@@ -183,13 +186,28 @@ def update(
183
186
return True
184
187
185
188
@report_error
186
- def delete (self , device : Union [DeviceId , Device ]) -> bool :
187
- """Deletes a device.
189
+ def set_mode (
190
+ self ,
191
+ device : Union [DeviceId , Device ],
192
+ automatic_heating_enabled : Optional [bool ] = None ,
193
+ automatic_cooling_enabled : Optional [bool ] = None ,
194
+ hvac_mode_setting : Optional [str ] = None ,
195
+ wait_for_action_attempt : Optional [bool ] = True ,
196
+ ) -> ActionAttempt :
197
+ """Sets a thermostat to a given mode.
188
198
189
199
Parameters
190
200
----------
191
201
device : DeviceId or Device
192
- Device id or Device to delete
202
+ Device id or Device to update
203
+ automatic_heating_enabled : bool, optional
204
+ Enable automatic heating
205
+ automatic_cooling_enabled : bool, optional
206
+ Enable cooling heating
207
+ hvac_mode_setting : str, optional
208
+ HVAC mode eg. "heat", "cool", "heatcool" or "off"
209
+ wait_for_action_attempt: bool, optional
210
+ Should wait for action attempt to resolve
193
211
194
212
Raises
195
213
------
@@ -198,17 +216,38 @@ def delete(self, device: Union[DeviceId, Device]) -> bool:
198
216
199
217
Returns
200
218
------
201
- None
219
+ ActionAttempt
202
220
"""
203
221
204
222
if not device :
205
- raise Exception ("device is required" )
223
+ raise Exception ("Device is required" )
206
224
207
- delete_payload = {"device_id" : to_device_id (device )}
208
- self .seam .make_request (
209
- "DELETE" ,
210
- "/thermostats/delete" ,
211
- json = delete_payload ,
225
+ params = {
226
+ "device_id" : to_device_id (device ),
227
+ }
228
+
229
+ arguments = {
230
+ "automatic_heating_enabled" : automatic_heating_enabled ,
231
+ "automatic_cooling_enabled" : automatic_cooling_enabled ,
232
+ "hvac_mode_setting" : hvac_mode_setting ,
233
+ }
234
+
235
+ for name in arguments :
236
+ if arguments [name ]:
237
+ params .update ({name : arguments [name ]})
238
+
239
+ res = self .seam .make_request (
240
+ "POST" ,
241
+ "/thermostats/set_mode" ,
242
+ json = params ,
243
+ )
244
+ action_attempt = res ["action_attempt" ]
245
+
246
+ if not wait_for_action_attempt :
247
+ return ActionAttempt .from_dict (action_attempt )
248
+
249
+ updated_action_attempt = self .seam .action_attempts .poll_until_ready (
250
+ action_attempt ["action_attempt_id" ]
212
251
)
213
252
214
- return None
253
+ return ActionAttempt . from_dict ( updated_action_attempt )
0 commit comments