From 5290396731b3d6c227f34b0e0dca1408db90d7e9 Mon Sep 17 00:00:00 2001 From: Caius-Bonus <123886836+Caius-Bonus@users.noreply.github.com> Date: Tue, 10 Oct 2023 20:23:03 +0200 Subject: [PATCH] ZHA Component: Correct AttributeUpdated signal in Thermostat climate entity, ThermostatClusterHandler and ThermostatHVACAction sensor entity (#101725) * initial * change other Thermostat climate entities * remove AttributeUpdateRecord --- homeassistant/components/zha/climate.py | 60 +++++++++---------- .../zha/core/cluster_handlers/hvac.py | 6 +- homeassistant/components/zha/sensor.py | 5 -- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index 5cbe2684ab4..1151d2fe59d 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -367,10 +367,10 @@ class Thermostat(ZhaEntity, ClimateEntity): self._thrm, SIGNAL_ATTR_UPDATED, self.async_attribute_updated ) - async def async_attribute_updated(self, record): + async def async_attribute_updated(self, attr_id, attr_name, value): """Handle attribute update from device.""" if ( - record.attr_name in (ATTR_OCCP_COOL_SETPT, ATTR_OCCP_HEAT_SETPT) + attr_name in (ATTR_OCCP_COOL_SETPT, ATTR_OCCP_HEAT_SETPT) and self.preset_mode == PRESET_AWAY ): # occupancy attribute is an unreportable attribute, but if we get @@ -379,7 +379,7 @@ class Thermostat(ZhaEntity, ClimateEntity): if await self._thrm.get_occupancy() is True: self._preset = PRESET_NONE - self.debug("Attribute '%s' = %s update", record.attr_name, record.value) + self.debug("Attribute '%s' = %s update", attr_name, value) self.async_write_ha_state() async def async_set_fan_mode(self, fan_mode: str) -> None: @@ -609,24 +609,24 @@ class MoesThermostat(Thermostat): """Return only the heat mode, because the device can't be turned off.""" return [HVACMode.HEAT] - async def async_attribute_updated(self, record): + async def async_attribute_updated(self, attr_id, attr_name, value): """Handle attribute update from device.""" - if record.attr_name == "operation_preset": - if record.value == 0: + if attr_name == "operation_preset": + if value == 0: self._preset = PRESET_AWAY - if record.value == 1: + if value == 1: self._preset = PRESET_SCHEDULE - if record.value == 2: + if value == 2: self._preset = PRESET_NONE - if record.value == 3: + if value == 3: self._preset = PRESET_COMFORT - if record.value == 4: + if value == 4: self._preset = PRESET_ECO - if record.value == 5: + if value == 5: self._preset = PRESET_BOOST - if record.value == 6: + if value == 6: self._preset = PRESET_COMPLEX - await super().async_attribute_updated(record) + await super().async_attribute_updated(attr_id, attr_name, value) async def async_preset_handler(self, preset: str, enable: bool = False) -> None: """Set the preset mode.""" @@ -688,22 +688,22 @@ class BecaThermostat(Thermostat): """Return only the heat mode, because the device can't be turned off.""" return [HVACMode.HEAT] - async def async_attribute_updated(self, record): + async def async_attribute_updated(self, attr_id, attr_name, value): """Handle attribute update from device.""" - if record.attr_name == "operation_preset": - if record.value == 0: + if attr_name == "operation_preset": + if value == 0: self._preset = PRESET_AWAY - if record.value == 1: + if value == 1: self._preset = PRESET_SCHEDULE - if record.value == 2: + if value == 2: self._preset = PRESET_NONE - if record.value == 4: + if value == 4: self._preset = PRESET_ECO - if record.value == 5: + if value == 5: self._preset = PRESET_BOOST - if record.value == 7: + if value == 7: self._preset = PRESET_TEMP_MANUAL - await super().async_attribute_updated(record) + await super().async_attribute_updated(attr_id, attr_name, value) async def async_preset_handler(self, preset: str, enable: bool = False) -> None: """Set the preset mode.""" @@ -783,20 +783,20 @@ class ZONNSMARTThermostat(Thermostat): ] self._supported_flags |= ClimateEntityFeature.PRESET_MODE - async def async_attribute_updated(self, record): + async def async_attribute_updated(self, attr_id, attr_name, value): """Handle attribute update from device.""" - if record.attr_name == "operation_preset": - if record.value == 0: + if attr_name == "operation_preset": + if value == 0: self._preset = PRESET_SCHEDULE - if record.value == 1: + if value == 1: self._preset = PRESET_NONE - if record.value == 2: + if value == 2: self._preset = self.PRESET_HOLIDAY - if record.value == 3: + if value == 3: self._preset = self.PRESET_HOLIDAY - if record.value == 4: + if value == 4: self._preset = self.PRESET_FROST - await super().async_attribute_updated(record) + await super().async_attribute_updated(attr_id, attr_name, value) async def async_preset_handler(self, preset: str, enable: bool = False) -> None: """Set the preset mode.""" diff --git a/homeassistant/components/zha/core/cluster_handlers/hvac.py b/homeassistant/components/zha/core/cluster_handlers/hvac.py index 15050ce67b1..dad3ee5eb4d 100644 --- a/homeassistant/components/zha/core/cluster_handlers/hvac.py +++ b/homeassistant/components/zha/core/cluster_handlers/hvac.py @@ -5,7 +5,6 @@ https://home-assistant.io/integrations/zha/ """ from __future__ import annotations -from collections import namedtuple from typing import Any from zigpy.zcl.clusters import hvac @@ -21,7 +20,6 @@ from ..const import ( ) from . import AttrReportConfig, ClusterHandler -AttributeUpdateRecord = namedtuple("AttributeUpdateRecord", "attr_id, attr_name, value") REPORT_CONFIG_CLIMATE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 25) REPORT_CONFIG_CLIMATE_DEMAND = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 5) REPORT_CONFIG_CLIMATE_DISCRETE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 1) @@ -235,7 +233,9 @@ class ThermostatClusterHandler(ClusterHandler): ) self.async_send_signal( f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}", - AttributeUpdateRecord(attrid, attr_name, value), + attrid, + attr_name, + value, ) async def async_set_operation_mode(self, mode) -> bool: diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 1e166675b5b..b733e5cc3cf 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -854,11 +854,6 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"): return HVACAction.IDLE return HVACAction.OFF - @callback - def async_set_state(self, *args, **kwargs) -> None: - """Handle state update from cluster handler.""" - self.async_write_ha_state() - @MULTI_MATCH( cluster_handler_names={CLUSTER_HANDLER_THERMOSTAT},