diff --git a/homeassistant/components/zha/diagnostics.py b/homeassistant/components/zha/diagnostics.py index 0fa1de5ff0e..ae68e6d5cca 100644 --- a/homeassistant/components/zha/diagnostics.py +++ b/homeassistant/components/zha/diagnostics.py @@ -139,6 +139,19 @@ def get_endpoint_cluster_attr_data(zha_device: ZHADevice) -> 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}": { @@ -148,10 +161,5 @@ def get_cluster_attr_data(cluster: Cluster) -> dict: for attr_id, attr_def in cluster.attributes.items() if (attr_value := cluster.get(attr_def.name)) is not None }, - UNSUPPORTED_ATTRIBUTES: { - f"0x{cluster.find_attribute(u_attr).id:04x}": { - ATTR_ATTRIBUTE_NAME: cluster.find_attribute(u_attr).name - } - for u_attr in cluster.unsupported_attributes - }, + UNSUPPORTED_ATTRIBUTES: unsupported_attributes, } diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index c13bb36c1c0..1f6a731d0fb 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -44,7 +44,7 @@ def zigpy_device(zigpy_device_mock): """Device tracker zigpy device.""" endpoints = { 1: { - SIG_EP_INPUT: [security.IasAce.cluster_id], + SIG_EP_INPUT: [security.IasAce.cluster_id, security.IasZone.cluster_id], SIG_EP_OUTPUT: [], SIG_EP_TYPE: zha.DeviceType.IAS_ANCILLARY_CONTROL, SIG_EP_PROFILE: zha.PROFILE_ID, @@ -93,6 +93,22 @@ async def test_diagnostics_for_device( ) -> None: """Test diagnostics for device.""" zha_device: ZHADevice = await zha_device_joined(zigpy_device) + + # add unknown unsupported attribute with id and name + zha_device.device.endpoints[1].in_clusters[ + security.IasAce.cluster_id + ].unsupported_attributes.update({0x1000, "unknown_attribute_name"}) + + # add known unsupported attributes with id and name + zha_device.device.endpoints[1].in_clusters[ + security.IasZone.cluster_id + ].unsupported_attributes.update( + { + security.IasZone.AttributeDefs.num_zone_sensitivity_levels_supported.id, + security.IasZone.AttributeDefs.current_zone_sensitivity_level.name, + } + ) + dev_reg = async_get(hass) device = dev_reg.async_get_device(identifiers={("zha", str(zha_device.ieee))}) assert device