From f53da62026cc508d86703f45788418dfd8225597 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Sat, 10 Aug 2024 19:25:21 +0200 Subject: [PATCH] Extend ZHA attribute diagnostic information (#123199) * Include full attribute representation in in data * Extend attribute diagnostics for zha --- homeassistant/components/zha/diagnostics.py | 22 ++------ .../zha/snapshots/test_diagnostics.ambr | 50 ++++++++++++++----- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/zha/diagnostics.py b/homeassistant/components/zha/diagnostics.py index bc4738d032a..3e598c4d5f8 100644 --- a/homeassistant/components/zha/diagnostics.py +++ b/homeassistant/components/zha/diagnostics.py @@ -7,7 +7,7 @@ from importlib.metadata import version from typing import Any from zha.application.const import ( - ATTR_ATTRIBUTE_NAME, + ATTR_ATTRIBUTE, ATTR_DEVICE_TYPE, ATTR_IEEE, ATTR_IN_CLUSTERS, @@ -158,27 +158,13 @@ def get_endpoint_cluster_attr_data(zha_device: Device) -> dict: def get_cluster_attr_data(cluster: Cluster) -> dict: """Return cluster attribute data.""" - unsupported_attributes = {} - for u_attr in cluster.unsupported_attributes: - try: - u_attr_def = cluster.find_attribute(u_attr) - unsupported_attributes[f"0x{u_attr_def.id:04x}"] = { - ATTR_ATTRIBUTE_NAME: u_attr_def.name - } - except KeyError: - if isinstance(u_attr, int): - unsupported_attributes[f"0x{u_attr:04x}"] = {} - else: - unsupported_attributes[u_attr] = {} - return { ATTRIBUTES: { f"0x{attr_id:04x}": { - ATTR_ATTRIBUTE_NAME: attr_def.name, - ATTR_VALUE: attr_value, + ATTR_ATTRIBUTE: repr(attr_def), + ATTR_VALUE: cluster.get(attr_def.name), } for attr_id, attr_def in cluster.attributes.items() - if (attr_value := cluster.get(attr_def.name)) is not None }, - UNSUPPORTED_ATTRIBUTES: unsupported_attributes, + UNSUPPORTED_ATTRIBUTES: cluster.unsupported_attributes, } diff --git a/tests/components/zha/snapshots/test_diagnostics.ambr b/tests/components/zha/snapshots/test_diagnostics.ambr index 8899712b99d..67655aebc8c 100644 --- a/tests/components/zha/snapshots/test_diagnostics.ambr +++ b/tests/components/zha/snapshots/test_diagnostics.ambr @@ -161,8 +161,20 @@ 'in_clusters': dict({ '0x0500': dict({ 'attributes': dict({ + '0x0000': dict({ + 'attribute': "ZCLAttributeDef(id=0x0000, name='zone_state', type=, access=, mandatory=True, is_manufacturer_specific=False)", + 'value': None, + }), + '0x0001': dict({ + 'attribute': "ZCLAttributeDef(id=0x0001, name='zone_type', type=, access=, mandatory=True, is_manufacturer_specific=False)", + 'value': None, + }), + '0x0002': dict({ + 'attribute': "ZCLAttributeDef(id=0x0002, name='zone_status', type=, access=, mandatory=True, is_manufacturer_specific=False)", + 'value': None, + }), '0x0010': dict({ - 'attribute_name': 'cie_addr', + 'attribute': "ZCLAttributeDef(id=0x0010, name='cie_addr', type=, access=, mandatory=True, is_manufacturer_specific=False)", 'value': list([ 50, 79, @@ -174,27 +186,41 @@ 0, ]), }), - }), - 'endpoint_attribute': 'ias_zone', - 'unsupported_attributes': dict({ + '0x0011': dict({ + 'attribute': "ZCLAttributeDef(id=0x0011, name='zone_id', type=, access=, mandatory=True, is_manufacturer_specific=False)", + 'value': None, + }), '0x0012': dict({ - 'attribute_name': 'num_zone_sensitivity_levels_supported', + 'attribute': "ZCLAttributeDef(id=0x0012, name='num_zone_sensitivity_levels_supported', type=, access=, mandatory=False, is_manufacturer_specific=False)", + 'value': None, }), '0x0013': dict({ - 'attribute_name': 'current_zone_sensitivity_level', + 'attribute': "ZCLAttributeDef(id=0x0013, name='current_zone_sensitivity_level', type=, access=, mandatory=False, is_manufacturer_specific=False)", + 'value': None, }), }), + 'endpoint_attribute': 'ias_zone', + 'unsupported_attributes': list([ + 18, + 'current_zone_sensitivity_level', + ]), }), '0x0501': dict({ 'attributes': dict({ + '0xfffd': dict({ + 'attribute': "ZCLAttributeDef(id=0xFFFD, name='cluster_revision', type=, access=, mandatory=True, is_manufacturer_specific=False)", + 'value': None, + }), + '0xfffe': dict({ + 'attribute': "ZCLAttributeDef(id=0xFFFE, name='reporting_status', type=, access=, mandatory=False, is_manufacturer_specific=False)", + 'value': None, + }), }), 'endpoint_attribute': 'ias_ace', - 'unsupported_attributes': dict({ - '0x1000': dict({ - }), - 'unknown_attribute_name': dict({ - }), - }), + 'unsupported_attributes': list([ + 4096, + 'unknown_attribute_name', + ]), }), }), 'out_clusters': dict({