11from seamapi .types import (
22 AbstractThermostats ,
3+ ActionAttempt ,
34 ConnectWebview ,
45 ConnectWebviewId ,
56 ConnectedAccount ,
@@ -50,7 +51,9 @@ def __init__(self, seam: Seam):
5051 """
5152
5253 self .seam = seam
53- self .climate_setting_schedules = ClimateSettingSchedules (seam = self .seam )
54+ self .climate_setting_schedules = ClimateSettingSchedules (
55+ seam = self .seam
56+ )
5457
5558 @report_error
5659 def list (
@@ -91,7 +94,7 @@ def list(
9194 connect_webview
9295 )
9396 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 ]
9598
9699 res = self .seam .make_request (
97100 "GET" ,
@@ -183,13 +186,28 @@ def update(
183186 return True
184187
185188 @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.
188198
189199 Parameters
190200 ----------
191201 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
193211
194212 Raises
195213 ------
@@ -198,17 +216,38 @@ def delete(self, device: Union[DeviceId, Device]) -> bool:
198216
199217 Returns
200218 ------
201- None
219+ ActionAttempt
202220 """
203221
204222 if not device :
205- raise Exception ("device is required" )
223+ raise Exception ("Device is required" )
206224
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" ]
212251 )
213252
214- return None
253+ return ActionAttempt . from_dict ( updated_action_attempt )
0 commit comments