Clean up ZHA channel reporting configuration (#33497)

This commit is contained in:
Alexei Chetroi 2020-04-01 11:35:48 -04:00 committed by GitHub
parent 4dbbf93af9
commit eff9b2a1a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,9 +20,6 @@ from ..const import (
ATTR_UNIQUE_ID, ATTR_UNIQUE_ID,
ATTR_VALUE, ATTR_VALUE,
CHANNEL_ZDO, CHANNEL_ZDO,
REPORT_CONFIG_MAX_INT,
REPORT_CONFIG_MIN_INT,
REPORT_CONFIG_RPT_CHANGE,
SIGNAL_ATTR_UPDATED, SIGNAL_ATTR_UPDATED,
) )
from ..helpers import LogMixin, safe_read from ..helpers import LogMixin, safe_read
@ -149,57 +146,47 @@ class ZigbeeChannel(LogMixin):
"Failed to bind '%s' cluster: %s", self.cluster.ep_attribute, str(ex) "Failed to bind '%s' cluster: %s", self.cluster.ep_attribute, str(ex)
) )
async def configure_reporting( async def configure_reporting(self) -> None:
self,
attr,
report_config=(
REPORT_CONFIG_MIN_INT,
REPORT_CONFIG_MAX_INT,
REPORT_CONFIG_RPT_CHANGE,
),
):
"""Configure attribute reporting for a cluster. """Configure attribute reporting for a cluster.
This also swallows DeliveryError exceptions that are thrown when This also swallows DeliveryError exceptions that are thrown when
devices are unreachable. devices are unreachable.
""" """
attr_name = self.cluster.attributes.get(attr, [attr])[0]
kwargs = {} kwargs = {}
if self.cluster.cluster_id >= 0xFC00 and self._ch_pool.manufacturer_code: if self.cluster.cluster_id >= 0xFC00 and self._ch_pool.manufacturer_code:
kwargs["manufacturer"] = self._ch_pool.manufacturer_code kwargs["manufacturer"] = self._ch_pool.manufacturer_code
min_report_int, max_report_int, reportable_change = report_config for report in self._report_config:
try: attr = report["attr"]
res = await self.cluster.configure_reporting( attr_name = self.cluster.attributes.get(attr, [attr])[0]
attr, min_report_int, max_report_int, reportable_change, **kwargs min_report_int, max_report_int, reportable_change = report["config"]
) try:
self.debug( res = await self.cluster.configure_reporting(
"reporting '%s' attr on '%s' cluster: %d/%d/%d: Result: '%s'", attr, min_report_int, max_report_int, reportable_change, **kwargs
attr_name, )
self.cluster.ep_attribute, self.debug(
min_report_int, "reporting '%s' attr on '%s' cluster: %d/%d/%d: Result: '%s'",
max_report_int, attr_name,
reportable_change, self.cluster.ep_attribute,
res, min_report_int,
) max_report_int,
except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex: reportable_change,
self.debug( res,
"failed to set reporting for '%s' attr on '%s' cluster: %s", )
attr_name, except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex:
self.cluster.ep_attribute, self.debug(
str(ex), "failed to set reporting for '%s' attr on '%s' cluster: %s",
) attr_name,
self.cluster.ep_attribute,
str(ex),
)
async def async_configure(self): async def async_configure(self):
"""Set cluster binding and attribute reporting.""" """Set cluster binding and attribute reporting."""
if not self._ch_pool.skip_configuration: if not self._ch_pool.skip_configuration:
await self.bind() await self.bind()
if self.cluster.is_server: if self.cluster.is_server:
for report_config in self._report_config: await self.configure_reporting()
await self.configure_reporting(
report_config["attr"], report_config["config"]
)
self.debug("finished channel configuration") self.debug("finished channel configuration")
else: else:
self.debug("skipping channel configuration") self.debug("skipping channel configuration")