Skip to content
This repository was archived by the owner on Jun 12, 2020. It is now read-only.

Commit c29079c

Browse files
committed
Reduce calls to api bu combining multiple calls into a single. Add retries limit.
1 parent fc8ffee commit c29079c

File tree

5 files changed

+161
-121
lines changed

5 files changed

+161
-121
lines changed

custom_components/tahoma_extended/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ def device_state_attributes(self):
163163
"tahoma_device_id": self.tahoma_device.url,
164164
}
165165

166-
def apply_action(self, cmd_name, *args):
166+
def apply_action(self, commands):
167167
"""Apply Action to Device."""
168168

169169
action = Action(self.tahoma_device.url)
170-
action.add_command(cmd_name, *args)
170+
for command in commands:
171+
action.add_command(*command)
171172
self.controller.apply_actions("HomeAssistant", [action])

custom_components/tahoma_extended/climate.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ def update(self):
216216

217217
@property
218218
def hvac_action(self):
219-
"""Return the current running hvac operation if supported.
220-
221-
Need to be one of CURRENT_HVAC_*.
222-
"""
219+
"""Return the current running hvac operation if supported."""
223220
return self._current_hvac_mode
224221

225222
@property
@@ -342,16 +339,15 @@ def _apply_action(self, target_temperature):
342339
target_temperature = 16
343340
if self.tahoma_device.active_states['core:DerogatedTargetTemperatureState'] != target_temperature:
344341
from time import sleep
345-
self.apply_action("refreshState")
346-
self.apply_action("setModeTemperature", "manualMode", target_temperature)
347-
self.apply_action("setDerogation", target_temperature, "further_notice")
348-
self.apply_action("refreshState")
342+
self.apply_action([["setModeTemperature", "manualMode", target_temperature],
343+
["setDerogation", target_temperature, "further_notice"],
344+
["refreshState"]])
349345
sleep(20)
350346

351347
async def _async_heater_turn_on(self):
352348
"""Turn heater toggleable device on."""
353349
if self._type == "io":
354-
self.apply_action("setHeatingLevel", "comfort")
350+
self.apply_action([["setHeatingLevel", "comfort"]])
355351
elif self._type == "thermostat":
356352
self._apply_action(self.target_temperature)
357353
self._current_hvac_mode = CURRENT_HVAC_HEAT
@@ -362,7 +358,7 @@ async def _async_heater_turn_on(self):
362358
async def _async_heater_turn_off(self):
363359
"""Turn heater toggleable device off."""
364360
if self._type == "io":
365-
self.apply_action("setHeatingLevel", "off")
361+
self.apply_action([["setHeatingLevel", "off"]])
366362
elif self._type == "thermostat":
367363
self._apply_action(self.target_temperature)
368364
self._current_hvac_mode = CURRENT_HVAC_IDLE
@@ -393,10 +389,6 @@ async def async_set_temperature(self, **kwargs):
393389
if temperature is None:
394390
return
395391
self._target_temp = temperature
396-
# if self._type == "thermostat":
397-
# self.apply_action(
398-
# "setModeTemperature", "manualMode", self.target_temperature
399-
# )
400392
await self._async_control_heating()
401393
# self.update()
402394

custom_components/tahoma_extended/light.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ async def async_turn_on(self, **kwargs) -> None:
7878

7979
if ATTR_BRIGHTNESS in kwargs:
8080
self._brightness = int(float(kwargs[ATTR_BRIGHTNESS]) / 255 * 100)
81-
self.apply_action("setIntensity", self._brightness)
81+
self.apply_action([["setIntensity", self._brightness]])
8282
elif ATTR_EFFECT in kwargs:
8383
self._effect = kwargs[ATTR_EFFECT]
84-
self.apply_action("wink", 100)
84+
self.apply_action([["wink", 100]])
8585
else:
8686
self._brightness = 100
87-
self.apply_action("on")
87+
self.apply_action([["on"]])
8888

8989

9090
self.async_write_ha_state()
@@ -94,7 +94,7 @@ async def async_turn_off(self, **kwargs) -> None:
9494
_LOGGER.debug("[THM] Called to turn off")
9595
self._state = False
9696
self._skip_update = True
97-
self.apply_action("off")
97+
self.apply_action([["off"]])
9898

9999
self.async_write_ha_state()
100100

0 commit comments

Comments
 (0)