Skip to content

Commit e409069

Browse files
committed
Expose more properties and generic send_command function
1 parent 5ad0c64 commit e409069

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

pydanfossally/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def handleDeviceData(self, device: dict):
7777
"leaving_home_setting",
7878
"pause_setting",
7979
"holiday_setting",
80+
"temp_set"
8081
]:
8182
setpoint = float(status["value"])
8283
setpoint = setpoint / 10
@@ -89,15 +90,16 @@ def handleDeviceData(self, device: dict):
8990
elif status["code"] == "MeasuredValue" and bHasFloorSensor: # Floor sensor
9091
temperature = float(status["value"])
9192
temperature = temperature / 10
92-
self.devices[device["id"]]["floor temperature"] = temperature
93-
elif status["code"] == "upper_temp":
94-
temperature = float(status["value"])
95-
temperature = temperature / 10
96-
self.devices[device["id"]]["upper_temp"] = temperature
97-
elif status["code"] == "lower_temp":
93+
self.devices[device["id"]]["floor_temperature"] = temperature
94+
elif status["code"] in [
95+
"upper_temp",
96+
"lower_temp",
97+
"floor_temp_min",
98+
"floor_temp_max"
99+
]:
98100
temperature = float(status["value"])
99101
temperature = temperature / 10
100-
self.devices[device["id"]]["lower_temp"] = temperature
102+
self.devices[device["id"]][status["code"]] = temperature
101103
elif status["code"] == "va_temperature":
102104
temperature = float(status["value"])
103105
temperature = temperature / 10
@@ -116,7 +118,7 @@ def handleDeviceData(self, device: dict):
116118
else:
117119
self.devices[device["id"]]["window_open"] = False
118120

119-
if status["code"] in ["child_lock", "mode", "work_state", "banner_ctrl"]:
121+
if status["code"] in ["child_lock", "mode", "work_state", "banner_ctrl", "window_toggle", "switch", "switch_state"]:
120122
self.devices[device["id"]][status["code"]] = status["value"]
121123

122124
def getDevice(self, device_id: str) -> None:
@@ -152,3 +154,9 @@ def setMode(self, device_id: str, mode: str) -> bool:
152154
result = self._api.set_mode(device_id, mode)
153155

154156
return result
157+
158+
def sendCommand(self, device_id: str, listofcommands: list[Tuple[str, str]]) -> bool:
159+
"""Send list of commands for given device."""
160+
result = self._api.send_command(device_id, listofcommands)
161+
162+
return result

pydanfossally/danfossallyapi.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _call(
3939

4040
try:
4141
if payload:
42+
_LOGGER.debug("Send command: %s: %s", path, json.dumps(payload))
4243
req = requests.post(
4344
API_HOST + path, json=payload, headers=headers_data, timeout=10
4445
)
@@ -48,6 +49,8 @@ def _call(
4849
req.raise_for_status()
4950
except requests.exceptions.HTTPError as err:
5051
code = err.response.status_code
52+
if payload:
53+
_LOGGER.debug("Http status code: %s", code)
5154
if code == 401:
5255
raise UnauthorizedError
5356
if code == 404:
@@ -60,9 +63,11 @@ def _call(
6063
except:
6164
raise UnexpectedError
6265

63-
json = req.json()
64-
print("JSON: ", json)
65-
return json
66+
response = req.json()
67+
if payload:
68+
_LOGGER.debug("Command response: %s", response)
69+
print("JSON: ", response)
70+
return response
6671

6772
def _refresh_token(self) -> bool:
6873
"""Refresh OAuth2 token if expired."""
@@ -176,6 +181,22 @@ def set_mode(self, device_id: str, mode: str) -> bool:
176181

177182
return callData["result"]
178183

184+
185+
def send_command(self, device_id: str, listofcommands: list[Tuple[str, str]]) -> bool:
186+
"""Send commands."""
187+
188+
commands = []
189+
for code,value in listofcommands:
190+
commands += [{"code": code, "value": value}]
191+
request_body = {"commands": commands}
192+
193+
callData = self._call(
194+
"/ally/devices/" + device_id + "/commands", payload=request_body
195+
)
196+
197+
return callData["result"]
198+
199+
179200
@property
180201
def token(self) -> str:
181202
"""Return token."""

0 commit comments

Comments
 (0)