From 6467eff09cf66e035c1003577e1422d8e55808ba Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 8 Feb 2021 12:23:02 -1000 Subject: [PATCH] Fix incorrect current temperature for homekit water heaters (#46076) --- .../components/homekit/type_thermostats.py | 13 +++++++++---- tests/components/homekit/test_type_thermostats.py | 8 ++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/homekit/type_thermostats.py b/homeassistant/components/homekit/type_thermostats.py index 54e2e9f92a8..a1c13432614 100644 --- a/homeassistant/components/homekit/type_thermostats.py +++ b/homeassistant/components/homekit/type_thermostats.py @@ -595,10 +595,15 @@ class WaterHeater(HomeAccessory): def async_update_state(self, new_state): """Update water_heater state after state change.""" # Update current and target temperature - temperature = _get_target_temperature(new_state, self._unit) - if temperature is not None: - if temperature != self.char_current_temp.value: - self.char_target_temp.set_value(temperature) + target_temperature = _get_target_temperature(new_state, self._unit) + if target_temperature is not None: + if target_temperature != self.char_target_temp.value: + self.char_target_temp.set_value(target_temperature) + + current_temperature = _get_current_temperature(new_state, self._unit) + if current_temperature is not None: + if current_temperature != self.char_current_temp.value: + self.char_current_temp.set_value(current_temperature) # Update display units if self._unit and self._unit in UNIT_HASS_TO_HOMEKIT: diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index ce17cf7ea07..79b5ca21097 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -1599,11 +1599,15 @@ async def test_water_heater(hass, hk_driver, events): hass.states.async_set( entity_id, HVAC_MODE_HEAT, - {ATTR_HVAC_MODE: HVAC_MODE_HEAT, ATTR_TEMPERATURE: 56.0}, + { + ATTR_HVAC_MODE: HVAC_MODE_HEAT, + ATTR_TEMPERATURE: 56.0, + ATTR_CURRENT_TEMPERATURE: 35.0, + }, ) await hass.async_block_till_done() assert acc.char_target_temp.value == 56.0 - assert acc.char_current_temp.value == 50.0 + assert acc.char_current_temp.value == 35.0 assert acc.char_target_heat_cool.value == 1 assert acc.char_current_heat_cool.value == 1 assert acc.char_display_units.value == 0