diff --git a/custom_components/tahoma_extended/__init__.py b/custom_components/tahoma_extended/__init__.py index 4f72404..be60b43 100755 --- a/custom_components/tahoma_extended/__init__.py +++ b/custom_components/tahoma_extended/__init__.py @@ -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]) diff --git a/custom_components/tahoma_extended/climate.py b/custom_components/tahoma_extended/climate.py index b54323f..5fd661d 100755 --- a/custom_components/tahoma_extended/climate.py +++ b/custom_components/tahoma_extended/climate.py @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/custom_components/tahoma_extended/light.py b/custom_components/tahoma_extended/light.py index 65de238..ac115e7 100644 --- a/custom_components/tahoma_extended/light.py +++ b/custom_components/tahoma_extended/light.py @@ -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() @@ -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() diff --git a/custom_components/tahoma_extended/pyhoma.py b/custom_components/tahoma_extended/pyhoma.py index 0478f13..6b366dd 100644 --- a/custom_components/tahoma_extended/pyhoma.py +++ b/custom_components/tahoma_extended/pyhoma.py @@ -70,9 +70,10 @@ def login(self): self.__logged_in = True return self.__logged_in - def get_user(self): + def get_user(self, retries: int = 3): """Get the user informations from the server. + :param retries: maximum number of retries :return: a dict with all the informations :rtype: dict @@ -80,16 +81,16 @@ def get_user(self): :Example: - >>> "creationTime":