From 17f0d9ce45c9eb7b65fec9f2da4991d02b1c352b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 14 Aug 2024 08:36:49 -0500 Subject: [PATCH] Map pre-heating and defrosting hvac actions in homekit (#123907) closes #123864 --- .../components/homekit/type_thermostats.py | 8 +++-- .../homekit/test_type_thermostats.py | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/homekit/type_thermostats.py b/homeassistant/components/homekit/type_thermostats.py index 5dc520e8568..a97f26b7abb 100644 --- a/homeassistant/components/homekit/type_thermostats.py +++ b/homeassistant/components/homekit/type_thermostats.py @@ -150,6 +150,8 @@ HC_HASS_TO_HOMEKIT_ACTION = { HVACAction.COOLING: HC_HEAT_COOL_COOL, HVACAction.DRYING: HC_HEAT_COOL_COOL, HVACAction.FAN: HC_HEAT_COOL_COOL, + HVACAction.PREHEATING: HC_HEAT_COOL_HEAT, + HVACAction.DEFROSTING: HC_HEAT_COOL_HEAT, } FAN_STATE_INACTIVE = 0 @@ -623,8 +625,10 @@ class Thermostat(HomeAccessory): ) # Set current operation mode for supported thermostats - if hvac_action := attributes.get(ATTR_HVAC_ACTION): - homekit_hvac_action = HC_HASS_TO_HOMEKIT_ACTION[hvac_action] + if (hvac_action := attributes.get(ATTR_HVAC_ACTION)) and ( + homekit_hvac_action := HC_HASS_TO_HOMEKIT_ACTION.get(hvac_action), + HC_HEAT_COOL_OFF, + ): self.char_current_heat_cool.set_value(homekit_hvac_action) # Update current temperature diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index 3a32e94e491..8454610566b 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -161,6 +161,40 @@ async def test_thermostat(hass: HomeAssistant, hk_driver, events: list[Event]) - assert acc.char_current_temp.value == 23.0 assert acc.char_display_units.value == 0 + hass.states.async_set( + entity_id, + HVACMode.HEAT, + { + **base_attrs, + ATTR_TEMPERATURE: 22.2, + ATTR_CURRENT_TEMPERATURE: 17.8, + ATTR_HVAC_ACTION: HVACAction.PREHEATING, + }, + ) + await hass.async_block_till_done() + assert acc.char_target_temp.value == 22.2 + assert acc.char_current_heat_cool.value == 1 + assert acc.char_target_heat_cool.value == 1 + assert acc.char_current_temp.value == 17.8 + assert acc.char_display_units.value == 0 + + hass.states.async_set( + entity_id, + HVACMode.HEAT, + { + **base_attrs, + ATTR_TEMPERATURE: 22.2, + ATTR_CURRENT_TEMPERATURE: 17.8, + ATTR_HVAC_ACTION: HVACAction.DEFROSTING, + }, + ) + await hass.async_block_till_done() + assert acc.char_target_temp.value == 22.2 + assert acc.char_current_heat_cool.value == 1 + assert acc.char_target_heat_cool.value == 1 + assert acc.char_current_temp.value == 17.8 + assert acc.char_display_units.value == 0 + hass.states.async_set( entity_id, HVACMode.FAN_ONLY,