Skip to content

Commit

Permalink
ZHA component rewrite part 3 - update helpers (#20463)
Browse files Browse the repository at this point in the history
* update helpers

* address comments

* remove ieee

* cluster id as hex too
  • Loading branch information
dmulcahey authored and balloob committed Jan 29, 2019
1 parent bb1583c commit 34090bd
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions homeassistant/components/zha/core/helpers.py
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 34090bd

Please sign in to comment.