diff --git a/custom_components/zha_toolkit/scan_device.py b/custom_components/zha_toolkit/scan_device.py index db1e70d..d973c26 100644 --- a/custom_components/zha_toolkit/scan_device.py +++ b/custom_components/zha_toolkit/scan_device.py @@ -2,7 +2,6 @@ import asyncio import logging -import re from zigpy import types as t from zigpy.exceptions import ControllerException, DeliveryError @@ -14,6 +13,9 @@ LOGGER = logging.getLogger(__name__) +ACCESS_CONTROL_MAP = {0x01: "READ", 0x02: "WRITE", 0x04: "REPORT"} + + @u.retryable( ( DeliveryError, @@ -232,13 +234,16 @@ async def discover_attributes_extended(cluster, manufacturer=None, tries=3): ] else: attr_type = attr_type_hex - try: - access = re.sub( - "^.*\\.", - "", - str(foundation.AttributeAccessControl(access_acl)), + + if access_acl != 0: + access = "|".join( + [ + s + for x, s in ACCESS_CONTROL_MAP.items() + if x & access_acl != 0 + ] ) - except ValueError: + else: access = "undefined" result[attr_id] = { diff --git a/custom_components/zha_toolkit/zcl_attr.py b/custom_components/zha_toolkit/zcl_attr.py index bac3fd1..a51724a 100644 --- a/custom_components/zha_toolkit/zcl_attr.py +++ b/custom_components/zha_toolkit/zcl_attr.py @@ -346,11 +346,7 @@ async def attr_write( # noqa: C901 attr_type = params[p.ATTR_TYPE] result_read = None - if ( - params[p.READ_BEFORE_WRITE] - or (len(attr_write_list) == 0) - or (cmd != S.ATTR_WRITE) - ): + if params[p.READ_BEFORE_WRITE] or (attr_read_list and cmd == S.ATTR_READ): if use_cache > 0: # Try to get value from cache if attr_id in cluster._attr_cache: