diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 699f14c..ad1c512 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -1191,7 +1191,7 @@ async def async_turn_aux_heat_off(self) -> None: raise NotImplementedError() - async def async_set_hvac_mode(self, hvac_mode): + async def async_set_hvac_mode(self, hvac_mode, need_control_heating=True): """Set new target hvac mode.""" _LOGGER.info("%s - Set hvac mode: %s", self, hvac_mode) @@ -1201,13 +1201,13 @@ async def async_set_hvac_mode(self, hvac_mode): self._hvac_mode = hvac_mode # Delegate to all underlying - need_control_heating = False + sub_need_control_heating = False for under in self._underlyings: - need_control_heating = ( + sub_need_control_heating = ( await under.set_hvac_mode(hvac_mode) or need_control_heating ) - if need_control_heating: + if need_control_heating and sub_need_control_heating: await self._async_control_heating(force=True) # Ensure we update the current operation after changing the mode @@ -1452,7 +1452,7 @@ async def try_window_condition(_): self, self._saved_hvac_mode, ) - await self.restore_hvac_mode() + await self.restore_hvac_mode(True) elif self._window_state == STATE_ON: _LOGGER.info( "%s - Window is open. Set hvac_mode to '%s'", self, HVACMode.OFF @@ -1857,7 +1857,7 @@ async def deactivate_window_auto(auto=False): ) # Set attributes self._window_auto_state = False - await self.restore_hvac_mode() + await self.restore_hvac_mode(True) if self._window_call_cancel: self._window_call_cancel() @@ -1953,9 +1953,9 @@ def save_hvac_mode(self): self._hvac_mode, ) - async def restore_hvac_mode(self): + async def restore_hvac_mode(self, need_control_heating=False): """Restore a previous hvac_mod""" - await self.async_set_hvac_mode(self._saved_hvac_mode) + await self.async_set_hvac_mode(self._saved_hvac_mode, need_control_heating) _LOGGER.debug( "%s - Restored hvac_mode - saved_hvac_mode is %s, hvac_mode is %s", self, @@ -2025,7 +2025,7 @@ async def check_overpowering(self) -> bool: self._saved_preset_mode, ) if self._is_over_climate: - await self.restore_hvac_mode() + await self.restore_hvac_mode(False) await self.restore_preset_mode() self.send_event( EventType.POWER_EVENT, @@ -2127,7 +2127,7 @@ async def check_security(self) -> bool: await self._async_set_preset_mode_internal(PRESET_SECURITY) # Turn off the underlying climate or heater if security default on_percent is 0 if self._is_over_climate or self._security_default_on_percent <= 0.0: - await self.async_set_hvac_mode(HVACMode.OFF) + await self.async_set_hvac_mode(HVACMode.OFF, False) if self._prop_algorithm: self._prop_algorithm.set_security(self._security_default_on_percent) @@ -2161,7 +2161,7 @@ async def check_security(self) -> bool: self._security_state = ret # Restore hvac_mode if previously saved if self._is_over_climate or self._security_default_on_percent <= 0.0: - await self.restore_hvac_mode() + await self.restore_hvac_mode(False) await self.restore_preset_mode() if self._prop_algorithm: self._prop_algorithm.unset_security() @@ -2294,6 +2294,8 @@ def update_custom_attributes(self): self.get_preset_away_name(PRESET_COMFORT) ), "power_temp": self._power_temp, + "target_temp": self.target_temperature, + "current_temp": self._cur_temp, "ext_current_temperature": self._cur_ext_temp, "current_power": self._current_power, "current_power_max": self._current_power_max, diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 5fbe48f..87d4ce6 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -167,6 +167,7 @@ def __init__( self._should_relaunch_control_heating = False self._on_time_sec = 0 self._off_time_sec = 0 + self._hvac_mode = None @property def initial_delay_sec(self): @@ -174,12 +175,18 @@ def initial_delay_sec(self): return self._initial_delay_sec async def set_hvac_mode(self, hvac_mode: HVACMode) -> bool: - """Set the HVACmode. Returns true if we need to redo a control_heating""" + """Set the HVACmode. Returns true if something have change""" + if hvac_mode == HVACMode.OFF: if self.is_device_active: await self.turn_off() await self._cancel_cycle() - return True + + if self._hvac_mode != hvac_mode: + self._hvac_mode = hvac_mode + return True + else: + return False @property def is_device_active(self): @@ -421,10 +428,10 @@ def is_initialized(self) -> bool: """True if the underlying climate was found""" return self._underlying_climate is not None - async def set_hvac_mode(self, hvac_mode: HVACMode): - """Set the HVACmode of the underlying climate""" + async def set_hvac_mode(self, hvac_mode: HVACMode) -> bool: + """Set the HVACmode of the underlying climate. Returns true if something have change""" if not self.is_initialized: - return + return False data = {ATTR_ENTITY_ID: self._entity_id, "hvac_mode": hvac_mode} await self._hass.services.async_call( @@ -433,6 +440,8 @@ async def set_hvac_mode(self, hvac_mode: HVACMode): data, ) + return True + @property def is_device_active(self): """If the toggleable device is currently active."""