Skip to content

Commit

Permalink
Fix security modes corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Feb 11, 2023
1 parent ade1ee4 commit 7dbdcf0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
14 changes: 9 additions & 5 deletions custom_components/versatile_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ async def _async_set_preset_mode_internal(self, preset_mode, force=False):
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:
Expand All @@ -1070,15 +1071,18 @@ async def _async_set_preset_mode_internal(self, preset_mode, force=False):
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()
Expand Down Expand Up @@ -1191,7 +1195,7 @@ async def entry_update_listener(
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,
Expand All @@ -1206,7 +1210,7 @@ async def _async_temperature_changed(self, event):
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,
Expand Down
11 changes: 11 additions & 0 deletions custom_components/versatile_thermostat/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,16 @@
}
}
}
},
"state_attributes": {
"_": {
"preset_mode": {
"state": {
"power": "Shedding",
"security": "Security",
"none": "Manual"
}
}
}
}
}
11 changes: 11 additions & 0 deletions custom_components/versatile_thermostat/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,16 @@
}
}
}
},
"state_attributes": {
"_": {
"preset_mode": {
"state": {
"power": "Shedding",
"security": "Security",
"none": "Manual"
}
}
}
}
}
11 changes: 11 additions & 0 deletions custom_components/versatile_thermostat/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,16 @@
}
}
}
},
"state_attributes": {
"_": {
"preset_mode": {
"state": {
"power": "Délestage",
"security": "Sécurité",
"none": "Manuel"
}
}
}
}
}

0 comments on commit 7dbdcf0

Please sign in to comment.