Set climate state to off if is_on is False

This commit is contained in:
jbouwh 2025-01-01 13:17:57 +00:00
parent a117a3cba9
commit 4ad5ce6d52
2 changed files with 9 additions and 0 deletions

View File

@ -354,6 +354,8 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
hvac_mode = self.hvac_mode
if hvac_mode is None:
return None
if hasattr(self, "_attr_is_on") and self._attr_is_on is False:
return HVACMode.OFF.value
# Support hvac_mode as string for custom integration backwards compatibility
if not isinstance(hvac_mode, HVACMode):
return HVACMode(hvac_mode).value # type: ignore[unreachable]

View File

@ -490,6 +490,13 @@ async def test_turn_on_off_toggle(hass: HomeAssistant) -> None:
climate._attr_hvac_mode = None
assert climate.is_on is None
# If _attr_is_on is set to False the state should be always off
climate._attr_hvac_action = HVACAction.IDLE
climate._attr_hvac_mode = HVACMode.AUTO
climate._attr_is_on = False
assert climate.is_on is False
assert climate.state == HVACMode.OFF
async def test_sync_toggle(hass: HomeAssistant) -> None:
"""Test if async toggle calls sync toggle."""