From e320f98ae4f643efef5679d0b3fb91c9ad8dd5c5 Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 6 Nov 2023 10:22:21 +0100 Subject: [PATCH] Use 'unicode_escape' encoding to convert bytes to string (#213) --- custom_components/zha_toolkit/utils.py | 2 +- custom_components/zha_toolkit/zcl_attr.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/zha_toolkit/utils.py b/custom_components/zha_toolkit/utils.py index cde3c10..ae2b654 100644 --- a/custom_components/zha_toolkit/utils.py +++ b/custom_components/zha_toolkit/utils.py @@ -473,7 +473,7 @@ def dict_to_jsonable(src_dict): value = value.serialize() if isinstance(value, bytes): # "bytes" is not compatible with json, get a "string" - value = str(value, encoding="ascii") + value = str(value, encoding="unicode_escape") else: # Anything else: get a textual representation value = repr(value) diff --git a/custom_components/zha_toolkit/zcl_attr.py b/custom_components/zha_toolkit/zcl_attr.py index c90af58..62e1c96 100644 --- a/custom_components/zha_toolkit/zcl_attr.py +++ b/custom_components/zha_toolkit/zcl_attr.py @@ -78,7 +78,7 @@ async def my_read_reporting_configuration_multiple( record.direction = direction # LOGGER.warning(f"Record {record.direction} {record.attrid}") cfg.append(record) - LOGGER.warning("Read reporting with %s %r", cfg, kwargs) + LOGGER.debug("Read reporting with %s %r", cfg, kwargs) param = t.List[f.ReadReportingConfigRecord](cfg) LOGGER.debug("Resolves to %s", param) @@ -88,9 +88,9 @@ async def my_read_reporting_configuration_multiple( ) try: - LOGGER.warning("Read reporting with %s result %s", cfg, res) + LOGGER.debug("Read reporting with %s result %s", cfg, res) except Exception as e: - LOGGER.debug("Error when reporting result of Read Report %r", e) + LOGGER.warning("Error when reporting result of Read Report %r", e) # Parse configure reporting result for unsupported attributes records = res[0]