From 7dbdcf0ee43a97b4ad4f4c2585e64d1222680cf9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Sat, 11 Feb 2023 12:38:14 +0100 Subject: [PATCH] Fix security modes corner cases --- custom_components/versatile_thermostat/climate.py | 14 +++++++++----- .../versatile_thermostat/strings.json | 11 +++++++++++ .../versatile_thermostat/translations/en.json | 11 +++++++++++ .../versatile_thermostat/translations/fr.json | 11 +++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 0e67eec..fe8cd66 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -1055,6 +1055,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): if preset_mode == self._attr_preset_mode and not force: # I don't think we need to call async_write_ha_state if we didn't change the state return + old_preset_mode = self._attr_preset_mode if preset_mode == PRESET_NONE: self._attr_preset_mode = PRESET_NONE if self._saved_target_temp: @@ -1070,15 +1071,18 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): self.find_preset_temp(preset_mode) ) - self.reset_last_temperature_time() + self.reset_last_temperature_time(old_preset_mode) self.save_preset_mode() self.recalculate() self.send_event(EventType.PRESET_EVENT, {"preset": self._attr_preset_mode}) - def reset_last_temperature_time(self): + def reset_last_temperature_time(self, old_preset_mode=None): """Reset to now the last temperature time if conditions are satisfied""" - if self._attr_preset_mode not in HIDDEN_PRESETS: + if ( + self._attr_preset_mode not in HIDDEN_PRESETS + and old_preset_mode not in HIDDEN_PRESETS + ): self._last_temperature_mesure = ( self._last_ext_temperature_mesure ) = datetime.now() @@ -1191,7 +1195,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): async def _async_temperature_changed(self, event): """Handle temperature changes.""" new_state = event.data.get("new_state") - _LOGGER.info( + _LOGGER.debug( "%s - Temperature changed. Event.new_state is %s", self, new_state, @@ -1206,7 +1210,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): async def _async_ext_temperature_changed(self, event): """Handle external temperature changes.""" new_state = event.data.get("new_state") - _LOGGER.info( + _LOGGER.debug( "%s - external Temperature changed. Event.new_state is %s", self, new_state, diff --git a/custom_components/versatile_thermostat/strings.json b/custom_components/versatile_thermostat/strings.json index dccfe24..c92c60c 100644 --- a/custom_components/versatile_thermostat/strings.json +++ b/custom_components/versatile_thermostat/strings.json @@ -228,5 +228,16 @@ } } } + }, + "state_attributes": { + "_": { + "preset_mode": { + "state": { + "power": "Shedding", + "security": "Security", + "none": "Manual" + } + } + } } } \ No newline at end of file diff --git a/custom_components/versatile_thermostat/translations/en.json b/custom_components/versatile_thermostat/translations/en.json index 629067d..cb623a2 100644 --- a/custom_components/versatile_thermostat/translations/en.json +++ b/custom_components/versatile_thermostat/translations/en.json @@ -228,5 +228,16 @@ } } } + }, + "state_attributes": { + "_": { + "preset_mode": { + "state": { + "power": "Shedding", + "security": "Security", + "none": "Manual" + } + } + } } } \ No newline at end of file diff --git a/custom_components/versatile_thermostat/translations/fr.json b/custom_components/versatile_thermostat/translations/fr.json index 0603a56..6326256 100644 --- a/custom_components/versatile_thermostat/translations/fr.json +++ b/custom_components/versatile_thermostat/translations/fr.json @@ -228,5 +228,16 @@ } } } + }, + "state_attributes": { + "_": { + "preset_mode": { + "state": { + "power": "Délestage", + "security": "Sécurité", + "none": "Manuel" + } + } + } } } \ No newline at end of file