mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix ZHA device diagnostics error for unknown unsupported attributes (#101239)
* Modify test to account for scenario of unknown unsupported attributes * Add error checking for finding unsupported attributes * Change comment to clarify zigpy misses an attribute def This should make it more clear that it's about an unknown attribute (where zigpy doesn't have an attribute definition). * Increase test coverage This increases test coverage by doing the following: - adding the `IasZone` to our test device, so we have a cluster which actually has some attribute definitions - adding not just an unknown unsupported attribute by id, but also by name - adding a known unsupported attribute by id and by name * Fix diagnostics logic
This commit is contained in:
parent
d654c4bc1e
commit
5d0c8947a1
@ -139,6 +139,19 @@ def get_endpoint_cluster_attr_data(zha_device: ZHADevice) -> dict:
|
|||||||
|
|
||||||
def get_cluster_attr_data(cluster: Cluster) -> dict:
|
def get_cluster_attr_data(cluster: Cluster) -> dict:
|
||||||
"""Return cluster attribute data."""
|
"""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 {
|
return {
|
||||||
ATTRIBUTES: {
|
ATTRIBUTES: {
|
||||||
f"0x{attr_id:04x}": {
|
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()
|
for attr_id, attr_def in cluster.attributes.items()
|
||||||
if (attr_value := cluster.get(attr_def.name)) is not None
|
if (attr_value := cluster.get(attr_def.name)) is not None
|
||||||
},
|
},
|
||||||
UNSUPPORTED_ATTRIBUTES: {
|
UNSUPPORTED_ATTRIBUTES: 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
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ def zigpy_device(zigpy_device_mock):
|
|||||||
"""Device tracker zigpy device."""
|
"""Device tracker zigpy device."""
|
||||||
endpoints = {
|
endpoints = {
|
||||||
1: {
|
1: {
|
||||||
SIG_EP_INPUT: [security.IasAce.cluster_id],
|
SIG_EP_INPUT: [security.IasAce.cluster_id, security.IasZone.cluster_id],
|
||||||
SIG_EP_OUTPUT: [],
|
SIG_EP_OUTPUT: [],
|
||||||
SIG_EP_TYPE: zha.DeviceType.IAS_ANCILLARY_CONTROL,
|
SIG_EP_TYPE: zha.DeviceType.IAS_ANCILLARY_CONTROL,
|
||||||
SIG_EP_PROFILE: zha.PROFILE_ID,
|
SIG_EP_PROFILE: zha.PROFILE_ID,
|
||||||
@ -93,6 +93,22 @@ async def test_diagnostics_for_device(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test diagnostics for device."""
|
"""Test diagnostics for device."""
|
||||||
zha_device: ZHADevice = await zha_device_joined(zigpy_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)
|
dev_reg = async_get(hass)
|
||||||
device = dev_reg.async_get_device(identifiers={("zha", str(zha_device.ieee))})
|
device = dev_reg.async_get_device(identifiers={("zha", str(zha_device.ieee))})
|
||||||
assert device
|
assert device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user