Skip to content

Commit

Permalink
Issue #619 - manual hvac_off should be prioritized over window and au…
Browse files Browse the repository at this point in the history
…to-start/stop hvac_off (#622)

Co-authored-by: Jean-Marc Collin <[email protected]>
  • Loading branch information
jmcollin78 and Jean-Marc Collin authored Nov 10, 2024
1 parent f9df925 commit ba69319
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 7 deletions.
31 changes: 24 additions & 7 deletions custom_components/versatile_thermostat/base_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,24 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode, need_control_heating=Tr
if hvac_mode is None:
return

def save_state():
self.reset_last_change_time()
self.update_custom_attributes()
self.async_write_ha_state()
self.send_event(EventType.HVAC_MODE_EVENT, {"hvac_mode": self._hvac_mode})

# If we already are in OFF, the manual OFF should just overwrite the reason and saved_hvac_mode
if self._hvac_mode == HVACMode.OFF and hvac_mode == HVACMode.OFF:
_LOGGER.info(
"%s - already in OFF. Change the reason to MANUAL and erase the saved_havc_mode"
)
self._hvac_off_reason = HVAC_OFF_REASON_MANUAL
self._saved_hvac_mode = HVACMode.OFF

save_state()

return

self._hvac_mode = hvac_mode

# Delegate to all underlying
Expand All @@ -1227,14 +1245,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode, need_control_heating=Tr

# Ensure we update the current operation after changing the mode
self.reset_last_temperature_time()
self.reset_last_change_time()

if self._hvac_mode != HVACMode.OFF:
self.set_hvac_off_reason(None)

self.update_custom_attributes()
self.async_write_ha_state()
self.send_event(EventType.HVAC_MODE_EVENT, {"hvac_mode": self._hvac_mode})
save_state()

@overrides
async def async_set_preset_mode(
Expand Down Expand Up @@ -2227,8 +2242,9 @@ def save_all():
save_all()

if new_central_mode == CENTRAL_MODE_STOPPED:
self.set_hvac_off_reason(HVAC_OFF_REASON_MANUAL)
await self.async_set_hvac_mode(HVACMode.OFF)
if self.hvac_mode != HVACMode.OFF:
self.set_hvac_off_reason(HVAC_OFF_REASON_MANUAL)
await self.async_set_hvac_mode(HVACMode.OFF)
return

if new_central_mode == CENTRAL_MODE_COOL_ONLY:
Expand All @@ -2242,7 +2258,8 @@ def save_all():
if new_central_mode == CENTRAL_MODE_HEAT_ONLY:
if HVACMode.HEAT in self.hvac_modes:
await self.async_set_hvac_mode(HVACMode.HEAT)
else:
# if not already off
elif self.hvac_mode != HVACMode.OFF:
self.set_hvac_off_reason(HVAC_OFF_REASON_MANUAL)
await self.async_set_hvac_mode(HVACMode.OFF)
return
Expand Down
1 change: 1 addition & 0 deletions tests/test_central_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ async def test_climate_ac_only_change_central_mode_true(
},
)

# 1. set hvac_mode to COOL and preet ECO
with patch("homeassistant.core.ServiceRegistry.async_call"), patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.find_underlying_climate",
return_value=fake_underlying_climate,
Expand Down
Loading

0 comments on commit ba69319

Please sign in to comment.