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

ZHA component rewrite part 3 - update helpers #20463

Merged
merged 4 commits into from
Jan 29, 2019
Merged
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
30 changes: 23 additions & 7 deletions homeassistant/components/zha/core/helpers.py
Original file line number Diff line number Diff line change
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)