Map pre-heating and defrosting hvac actions in homekit (#123907)

closes #123864
This commit is contained in:
J. Nick Koston 2024-08-14 08:36:49 -05:00 committed by GitHub
parent f7e017aa73
commit 17f0d9ce45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

View File

@ -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

View File

@ -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,