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

Commit

Permalink
Reduce calls to api bu combining multiple calls into a single. Add re…
Browse files Browse the repository at this point in the history
…tries limit.
  • Loading branch information
vlebourl committed Jun 3, 2020
1 parent fc8ffee commit c29079c
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 121 deletions.
5 changes: 3 additions & 2 deletions custom_components/tahoma_extended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ def device_state_attributes(self):
"tahoma_device_id": self.tahoma_device.url,
}

def apply_action(self, cmd_name, *args):
def apply_action(self, commands):
"""Apply Action to Device."""

action = Action(self.tahoma_device.url)
action.add_command(cmd_name, *args)
for command in commands:
action.add_command(*command)
self.controller.apply_actions("HomeAssistant", [action])
20 changes: 6 additions & 14 deletions custom_components/tahoma_extended/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ def update(self):

@property
def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
"""Return the current running hvac operation if supported."""
return self._current_hvac_mode

@property
Expand Down Expand Up @@ -342,16 +339,15 @@ def _apply_action(self, target_temperature):
target_temperature = 16
if self.tahoma_device.active_states['core:DerogatedTargetTemperatureState'] != target_temperature:
from time import sleep
self.apply_action("refreshState")
self.apply_action("setModeTemperature", "manualMode", target_temperature)
self.apply_action("setDerogation", target_temperature, "further_notice")
self.apply_action("refreshState")
self.apply_action([["setModeTemperature", "manualMode", target_temperature],
["setDerogation", target_temperature, "further_notice"],
["refreshState"]])
sleep(20)

async def _async_heater_turn_on(self):
"""Turn heater toggleable device on."""
if self._type == "io":
self.apply_action("setHeatingLevel", "comfort")
self.apply_action([["setHeatingLevel", "comfort"]])
elif self._type == "thermostat":
self._apply_action(self.target_temperature)
self._current_hvac_mode = CURRENT_HVAC_HEAT
Expand All @@ -362,7 +358,7 @@ async def _async_heater_turn_on(self):
async def _async_heater_turn_off(self):
"""Turn heater toggleable device off."""
if self._type == "io":
self.apply_action("setHeatingLevel", "off")
self.apply_action([["setHeatingLevel", "off"]])
elif self._type == "thermostat":
self._apply_action(self.target_temperature)
self._current_hvac_mode = CURRENT_HVAC_IDLE
Expand Down Expand Up @@ -393,10 +389,6 @@ async def async_set_temperature(self, **kwargs):
if temperature is None:
return
self._target_temp = temperature
# if self._type == "thermostat":
# self.apply_action(
# "setModeTemperature", "manualMode", self.target_temperature
# )
await self._async_control_heating()
# self.update()

Expand Down
8 changes: 4 additions & 4 deletions custom_components/tahoma_extended/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ async def async_turn_on(self, **kwargs) -> None:

if ATTR_BRIGHTNESS in kwargs:
self._brightness = int(float(kwargs[ATTR_BRIGHTNESS]) / 255 * 100)
self.apply_action("setIntensity", self._brightness)
self.apply_action([["setIntensity", self._brightness]])
elif ATTR_EFFECT in kwargs:
self._effect = kwargs[ATTR_EFFECT]
self.apply_action("wink", 100)
self.apply_action([["wink", 100]])
else:
self._brightness = 100
self.apply_action("on")
self.apply_action([["on"]])


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

self.async_write_ha_state()

Expand Down
Loading

0 comments on commit c29079c

Please sign in to comment.