Skip to content

Commit

Permalink
Compare serialized values in attr_read/write/read - enable Array read…
Browse files Browse the repository at this point in the history
… in scan_device for zigpy>=0.58.1
  • Loading branch information
mdeweerd committed Oct 24, 2023
1 parent 28e92d4 commit 62decba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions custom_components/zha_toolkit/scan_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ async def discover_attributes_extended(cluster, manufacturer=None, tries=3):
attr_type = foundation.DATA_TYPES.get(attr_rec.datatype)
access_acl = t.uint8_t(attr_rec.acl)

if attr_rec.datatype not in [0x48] and (
access_acl & foundation.AttributeAccessControl.READ != 0
):
# Note: reading back Array type was fixed in zigpy 0.58.1 .
if (
not u.is_zigpy_ge("0.58.1") or attr_rec.datatype not in [0x48]
) and (access_acl & foundation.AttributeAccessControl.READ != 0):
to_read.append(attr_id)

attr_type_hex = f"0x{attr_rec.datatype:02x}"
Expand Down
13 changes: 11 additions & 2 deletions custom_components/zha_toolkit/zcl_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,15 @@ async def attr_write( # noqa: C901
write_is_equal = (
(params[p.READ_BEFORE_WRITE])
and (len(attr_write_list) != 0)
and compare_val is not None
and (
(attr_id in result_read[0]) # type:ignore[index]
and (result_read[0][attr_id] == compare_val) # type:ignore[index]
and (
result_read[0][ # type:ignore[index]
attr_id
].serialize() # type:ignore[union-attr]
== compare_val.serialize()
)
)
)

Expand Down Expand Up @@ -496,7 +502,10 @@ async def attr_write( # noqa: C901
len(result_read[1]) == 0 and len(result_read[0]) == 1
)
if success and compare_val is not None:
if result_read[0][attr_id] != compare_val:
if (
result_read[0][attr_id].serialize()
!= compare_val.serialize()
):
success = False
msg = "Read does not match expected: {!r} <> {!r}".format(
result_read[0][attr_id].serialize(),
Expand Down

0 comments on commit 62decba

Please sign in to comment.