diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 9570ceb2..c5fb7f9e 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -20,6 +20,7 @@ from zigpy.zcl import Cluster from zigpy.zcl.clusters import general, homeautomation, hvac, measurement, smartenergy from zigpy.zcl.clusters.manufacturer_specific import ManufacturerSpecificCluster +from zigpy.zcl.foundation import ReportingConfig from tests.common import ( SIG_EP_INPUT, @@ -1246,6 +1247,9 @@ def __init__(self, *args, **kwargs) -> None: divisor=1, multiplier=1, unit=UnitOfMass.GRAMS, + reporting_config=ReportingConfig( + min_interval=0, max_interval=60, reportable_change=1 + ), ) .add_to_registry() ) diff --git a/zha/application/const.py b/zha/application/const.py index 93292391..473af4d7 100644 --- a/zha/application/const.py +++ b/zha/application/const.py @@ -94,6 +94,7 @@ ENTITY_METADATA = "entity_metadata" ZCL_INIT_ATTRS = "ZCL_INIT_ATTRS" +REPORT_CONFIG = "REPORT_CONFIG" _ControllerClsType = type[zigpy.application.ControllerApplication] diff --git a/zha/application/discovery.py b/zha/application/discovery.py index 611414e5..67bff2b6 100644 --- a/zha/application/discovery.py +++ b/zha/application/discovery.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections import Counter +from dataclasses import astuple import logging from typing import TYPE_CHECKING, cast @@ -51,6 +52,7 @@ # importing cluster handlers updates registries from zha.zigbee.cluster_handlers import ( # noqa: F401 pylint: disable=unused-import + AttrReportConfig, ClusterHandler, closures, general, @@ -306,6 +308,27 @@ def discover_quirks_v2_entities(self, device: Device) -> None: ) cluster_handler.__dict__[zha_const.ZCL_INIT_ATTRS] = init_attrs + if ( + hasattr(entity_metadata, "attribute_name") + and hasattr(entity_metadata, "reporting_config") + and entity_metadata.reporting_config + ): + reporting_config = tuple( + filter( + lambda cfg: cfg["attr"] != entity_metadata.attribute_name, + cluster_handler.REPORT_CONFIG, + ) + ) + reporting_config += ( + AttrReportConfig( + attr=entity_metadata.attribute_name, + config=astuple(entity_metadata.reporting_config), + ), + ) + + cluster_handler.__dict__[zha_const.REPORT_CONFIG] = reporting_config + + endpoint.claim_cluster_handlers([cluster_handler]) endpoint.async_new_entity( platform=platform, entity_class=entity_class,