From 34090bd021cd66cd5c637c3a386461096e76f910 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Mon, 28 Jan 2019 19:40:00 -0500 Subject: [PATCH] ZHA component rewrite part 3 - update helpers (#20463) * update helpers * address comments * remove ieee * cluster id as hex too --- homeassistant/components/zha/core/helpers.py | 30 +++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index a182479d221..6957edc4f3f 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -55,7 +55,7 @@ async def bind_cluster(entity_id, cluster): ) -async def configure_reporting(entity_id, cluster, attr, skip_bind=False, +async def configure_reporting(entity_id, cluster, attr, min_report=REPORT_CONFIG_MIN_INT, max_report=REPORT_CONFIG_MAX_INT, reportable_change=REPORT_CONFIG_RPT_CHANGE, @@ -68,12 +68,13 @@ async def configure_reporting(entity_id, cluster, attr, skip_bind=False, from zigpy.exceptions import DeliveryError attr_name = cluster.attributes.get(attr, [attr])[0] + attr_id = get_attr_id_by_name(cluster, attr_name) cluster_name = cluster.ep_attribute kwargs = {} if manufacturer: kwargs['manufacturer'] = manufacturer try: - res = await cluster.configure_reporting(attr, min_report, + res = await cluster.configure_reporting(attr_id, min_report, max_report, reportable_change, **kwargs) _LOGGER.debug( @@ -101,11 +102,11 @@ async def bind_configure_reporting(entity_id, cluster, attr, skip_bind=False, if not skip_bind: await bind_cluster(entity_id, cluster) - await configure_reporting(entity_id, cluster, attr, skip_bind=False, - min_report=REPORT_CONFIG_MIN_INT, - max_report=REPORT_CONFIG_MAX_INT, - reportable_change=REPORT_CONFIG_RPT_CHANGE, - manufacturer=None) + await configure_reporting(entity_id, cluster, attr, + min_report=min_report, + max_report=max_report, + reportable_change=reportable_change, + manufacturer=manufacturer) async def check_zigpy_connection(usb_path, radio_type, database_path): @@ -136,3 +137,18 @@ def convert_ieee(ieee_str): """Convert given ieee string to EUI64.""" from zigpy.types import EUI64, uint8_t return EUI64([uint8_t(p, base=16) for p in ieee_str.split(':')]) + + +def construct_unique_id(cluster): + """Construct a unique id from a cluster.""" + return "0x{:04x}:{}:0x{:04x}".format( + cluster.endpoint.device.nwk, + cluster.endpoint.endpoint_id, + cluster.cluster_id + ) + + +def get_attr_id_by_name(cluster, attr_name): + """Get the attribute id for a cluster attribute by its name.""" + return next((attrid for attrid, (attrname, datatype) in + cluster.attributes.items() if attr_name == attrname), None)