From f08e388be3173213326bcdb05e34923650349f30 Mon Sep 17 00:00:00 2001 From: cecille Date: Tue, 5 Dec 2023 12:18:02 -0500 Subject: [PATCH] YAML decoder: Use default value if we don't have more info --- .../matter_chip_tool_adapter/decoder.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py index a7dd32b7d43a85..90270b9cf92408 100644 --- a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py +++ b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py @@ -79,6 +79,8 @@ def __translate_names(self, payloads): if key == _CLUSTER_ID: key = _CLUSTER value = specs.get_cluster_name(value) + if value is None: + value = "Unknown cluster" elif key == _ENDPOINT_ID: key = _ENDPOINT elif key == _RESPONSE_ID: @@ -89,9 +91,13 @@ def __translate_names(self, payloads): key = _ATTRIBUTE value = specs.get_attribute_name( payload[_CLUSTER_ID], value) + if value is None: + value = "Unknown attribute" elif key == _EVENT_ID: key = _EVENT value = specs.get_event_name(payload[_CLUSTER_ID], value) + if value is None: + value = "Unknown event" elif key == _VALUE or key == _ERROR or key == _CLUSTER_ERROR or key == _DATA_VERSION or key == _EVENT_NUMBER: pass else: @@ -187,7 +193,7 @@ def __convert_command(self, rv): response = specs.get_response_by_name(cluster_name, response_name) if not response: - raise KeyError(f'Error: response "{response_name}" not found.') + return value typename = response.name array = False @@ -201,7 +207,8 @@ def __convert_attribute(self, rv): attribute = specs.get_attribute_by_name(cluster_name, attribute_name) if not attribute: - raise KeyError(f'Error: attribute "{attribute_name}" not found.') + # Let's just return the value directly and hope for the test + return value typename = attribute.definition.data_type.name array = attribute.definition.is_list @@ -215,7 +222,7 @@ def __convert_event(self, rv): event = specs.get_event_by_name(cluster_name, event_name) if not event: - raise KeyError(f'Error: event "{event_name}" not found.') + return event typename = event.name array = False