ZHA Component: Correct AttributeUpdated signal in Thermostat climate entity, ThermostatClusterHandler and ThermostatHVACAction sensor entity (#101725)

* initial

* change other Thermostat climate entities

* remove AttributeUpdateRecord
This commit is contained in:
Caius-Bonus 2023-10-10 20:23:03 +02:00 committed by GitHub
parent 71ddb282d2
commit 5290396731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 38 deletions

View File

@ -367,10 +367,10 @@ class Thermostat(ZhaEntity, ClimateEntity):
self._thrm, SIGNAL_ATTR_UPDATED, self.async_attribute_updated 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.""" """Handle attribute update from device."""
if ( 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 and self.preset_mode == PRESET_AWAY
): ):
# occupancy attribute is an unreportable attribute, but if we get # 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: if await self._thrm.get_occupancy() is True:
self._preset = PRESET_NONE 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() self.async_write_ha_state()
async def async_set_fan_mode(self, fan_mode: str) -> None: 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 only the heat mode, because the device can't be turned off."""
return [HVACMode.HEAT] 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.""" """Handle attribute update from device."""
if record.attr_name == "operation_preset": if attr_name == "operation_preset":
if record.value == 0: if value == 0:
self._preset = PRESET_AWAY self._preset = PRESET_AWAY
if record.value == 1: if value == 1:
self._preset = PRESET_SCHEDULE self._preset = PRESET_SCHEDULE
if record.value == 2: if value == 2:
self._preset = PRESET_NONE self._preset = PRESET_NONE
if record.value == 3: if value == 3:
self._preset = PRESET_COMFORT self._preset = PRESET_COMFORT
if record.value == 4: if value == 4:
self._preset = PRESET_ECO self._preset = PRESET_ECO
if record.value == 5: if value == 5:
self._preset = PRESET_BOOST self._preset = PRESET_BOOST
if record.value == 6: if value == 6:
self._preset = PRESET_COMPLEX 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: async def async_preset_handler(self, preset: str, enable: bool = False) -> None:
"""Set the preset mode.""" """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 only the heat mode, because the device can't be turned off."""
return [HVACMode.HEAT] 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.""" """Handle attribute update from device."""
if record.attr_name == "operation_preset": if attr_name == "operation_preset":
if record.value == 0: if value == 0:
self._preset = PRESET_AWAY self._preset = PRESET_AWAY
if record.value == 1: if value == 1:
self._preset = PRESET_SCHEDULE self._preset = PRESET_SCHEDULE
if record.value == 2: if value == 2:
self._preset = PRESET_NONE self._preset = PRESET_NONE
if record.value == 4: if value == 4:
self._preset = PRESET_ECO self._preset = PRESET_ECO
if record.value == 5: if value == 5:
self._preset = PRESET_BOOST self._preset = PRESET_BOOST
if record.value == 7: if value == 7:
self._preset = PRESET_TEMP_MANUAL 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: async def async_preset_handler(self, preset: str, enable: bool = False) -> None:
"""Set the preset mode.""" """Set the preset mode."""
@ -783,20 +783,20 @@ class ZONNSMARTThermostat(Thermostat):
] ]
self._supported_flags |= ClimateEntityFeature.PRESET_MODE 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.""" """Handle attribute update from device."""
if record.attr_name == "operation_preset": if attr_name == "operation_preset":
if record.value == 0: if value == 0:
self._preset = PRESET_SCHEDULE self._preset = PRESET_SCHEDULE
if record.value == 1: if value == 1:
self._preset = PRESET_NONE self._preset = PRESET_NONE
if record.value == 2: if value == 2:
self._preset = self.PRESET_HOLIDAY self._preset = self.PRESET_HOLIDAY
if record.value == 3: if value == 3:
self._preset = self.PRESET_HOLIDAY self._preset = self.PRESET_HOLIDAY
if record.value == 4: if value == 4:
self._preset = self.PRESET_FROST 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: async def async_preset_handler(self, preset: str, enable: bool = False) -> None:
"""Set the preset mode.""" """Set the preset mode."""

View File

@ -5,7 +5,6 @@ https://home-assistant.io/integrations/zha/
""" """
from __future__ import annotations from __future__ import annotations
from collections import namedtuple
from typing import Any from typing import Any
from zigpy.zcl.clusters import hvac from zigpy.zcl.clusters import hvac
@ -21,7 +20,6 @@ from ..const import (
) )
from . import AttrReportConfig, ClusterHandler 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 = (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_DEMAND = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 5)
REPORT_CONFIG_CLIMATE_DISCRETE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 1) REPORT_CONFIG_CLIMATE_DISCRETE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 1)
@ -235,7 +233,9 @@ class ThermostatClusterHandler(ClusterHandler):
) )
self.async_send_signal( self.async_send_signal(
f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}", 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: async def async_set_operation_mode(self, mode) -> bool:

View File

@ -854,11 +854,6 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"):
return HVACAction.IDLE return HVACAction.IDLE
return HVACAction.OFF 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( @MULTI_MATCH(
cluster_handler_names={CLUSTER_HANDLER_THERMOSTAT}, cluster_handler_names={CLUSTER_HANDLER_THERMOSTAT},