From 117c12d135039797e5c00e9f1c87ece7f4be13e0 Mon Sep 17 00:00:00 2001 From: Jc2k Date: Mon, 10 Oct 2022 19:58:20 +0100 Subject: [PATCH] Fix Eve Thermo always showing as heating in homekit_controller even when off (#80019) --- .../components/homekit_controller/climate.py | 8 +++++++ .../homekit_controller/test_climate.py | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/homeassistant/components/homekit_controller/climate.py b/homeassistant/components/homekit_controller/climate.py index 2c4d2e3871d..41788eb4cb2 100644 --- a/homeassistant/components/homekit_controller/climate.py +++ b/homeassistant/components/homekit_controller/climate.py @@ -565,6 +565,14 @@ class HomeKitClimateEntity(HomeKitBaseClimateEntity): # This characteristic describes the current mode of a device, # e.g. a thermostat is "heating" a room to 75 degrees Fahrenheit. # Can be 0 - 2 (Off, Heat, Cool) + + # If the HVAC is switched off, it must be idle + # This works around a bug in some devices (like Eve radiator valves) that + # return they are heating when they are not. + target = self.service.value(CharacteristicsTypes.HEATING_COOLING_TARGET) + if target == HeatingCoolingTargetValues.OFF: + return HVACAction.IDLE + value = self.service.value(CharacteristicsTypes.HEATING_COOLING_CURRENT) return CURRENT_MODE_HOMEKIT_TO_HASS.get(value) diff --git a/tests/components/homekit_controller/test_climate.py b/tests/components/homekit_controller/test_climate.py index c5cad7015d8..0f669c9c51f 100644 --- a/tests/components/homekit_controller/test_climate.py +++ b/tests/components/homekit_controller/test_climate.py @@ -619,6 +619,27 @@ async def test_hvac_mode_vs_hvac_action(hass, utcnow): assert state.attributes["hvac_action"] == "heating" +async def test_hvac_mode_vs_hvac_action_current_mode_wrong(hass, utcnow): + """Check that we cope with buggy HEATING_COOLING_CURRENT.""" + helper = await setup_test_component(hass, create_thermostat_service) + + await helper.async_update( + ServicesTypes.THERMOSTAT, + { + CharacteristicsTypes.TEMPERATURE_CURRENT: 22, + CharacteristicsTypes.TEMPERATURE_TARGET: 21, + CharacteristicsTypes.HEATING_COOLING_CURRENT: 1, + CharacteristicsTypes.HEATING_COOLING_TARGET: 0, + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: 50, + CharacteristicsTypes.RELATIVE_HUMIDITY_TARGET: 45, + }, + ) + + state = await helper.poll_and_get_state() + assert state.state == "off" + assert state.attributes["hvac_action"] == "idle" + + def create_heater_cooler_service(accessory): """Define thermostat characteristics.""" service = accessory.add_service(ServicesTypes.HEATER_COOLER)