ZHA component rewrite part 3 - update helpers (#20463)
* update helpers * address comments * remove ieee * cluster id as hex too
This commit is contained in:
parent
bb1583c453
commit
34090bd021
1 changed files with 23 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue