From 994a91f910df6dda3e204beb0d74ae22673827a8 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Wed, 18 Oct 2023 12:00:13 +0200 Subject: [PATCH] Add debug info regarding false read_after_write --- custom_components/zha_toolkit/zcl_attr.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/custom_components/zha_toolkit/zcl_attr.py b/custom_components/zha_toolkit/zcl_attr.py index 4f218e1..3aada55 100644 --- a/custom_components/zha_toolkit/zcl_attr.py +++ b/custom_components/zha_toolkit/zcl_attr.py @@ -491,11 +491,20 @@ async def attr_write( # noqa: C901 f"Reading attr result (attrs, status): {result_read!r}" ) # read_is_equal = (result_read[0][attr_id] == compare_val) - success = ( - success - and (len(result_read[1]) == 0 and len(result_read[0]) == 1) - and (result_read[0][attr_id] == compare_val) + success = success and ( + 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: + success = False + msg = "Read does not match expected: {!r} <> {!r}".format( + result_read[0][attr_id].serialize(), + compare_val.serialize(), + ) + LOGGER.warning(msg) + if "warnings" not in event_data: + event_data["warnings"] = [] + event_data["warnings"].append(msg) if result_read is not None: event_data["result_read"] = result_read