Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuration of entity reporting for V2 quirks #254

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
)
Expand Down
1 change: 1 addition & 0 deletions zha/application/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
ENTITY_METADATA = "entity_metadata"

ZCL_INIT_ATTRS = "ZCL_INIT_ATTRS"
REPORT_CONFIG = "REPORT_CONFIG"

_ControllerClsType = type[zigpy.application.ControllerApplication]

Expand Down
23 changes: 23 additions & 0 deletions zha/application/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from collections import Counter
from dataclasses import astuple
import logging
from typing import TYPE_CHECKING, cast

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading