File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 19
19
20
20
_LOGGER = logging .getLogger (__name__ )
21
21
22
+ _MODE_TO_LAST_CLICK_TIME_FORMAT_MAP = {
23
+ # The format was reverse engineered from experimentation with the API and the Danfoss Ally app
24
+ "at_home" : "010000" ,
25
+ "leaving_home" : "000101" ,
26
+ }
27
+ """Map mode to obscure format required by `last_click_time`"""
28
+
22
29
23
30
class DanfossAllyAPI :
24
31
def __init__ (self ) -> None :
@@ -175,12 +182,27 @@ def set_temperature(
175
182
176
183
def set_mode (self , device_id : str , mode : str ) -> bool :
177
184
"""Set device operating mode."""
178
- request_body = {"commands" : [{"code" : "mode" , "value" : mode }]}
185
+ commands = [{"code" : "mode" , "value" : mode }]
186
+
187
+ # Strangely, some modes require `last_click_time` to also be set to "YYYYmmddHHMM{{mode_in_last_click_time_format}}"
188
+ if mode in _MODE_TO_LAST_CLICK_TIME_FORMAT_MAP :
189
+ commands .append (
190
+ {
191
+ "code" : "last_click_time" ,
192
+ "value" : f"{ datetime .datetime .now ():%Y%m%d%H%M} { _MODE_TO_LAST_CLICK_TIME_FORMAT_MAP [mode ]} " ,
193
+ }
194
+ )
195
+
196
+ request_body = {"commands" : commands }
179
197
180
198
callData = self ._call (
181
199
"/ally/devices/" + device_id + "/commands" , payload = request_body
182
200
)
183
201
202
+ _LOGGER .debug (
203
+ "Set mode for device %s: %s" , device_id , json .dumps (request_body )
204
+ )
205
+
184
206
return callData ["result" ]
185
207
186
208
def send_command (
Original file line number Diff line number Diff line change 24
24
"Bug Tracker" : "https://github.com/mtrab/pydanfossally/issues" ,
25
25
},
26
26
install_requires = ["requests>=2.28.0" ],
27
- version = "0.0.29 " ,
27
+ version = "0.0.30 " ,
28
28
)
You can’t perform that action at this time.
0 commit comments