Skip to content

Commit

Permalink
YAML decoder: Use default value if we don't have more info
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Dec 5, 2023
1 parent b9ff894 commit f08e388
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f08e388

Please sign in to comment.