Skip to content

Commit

Permalink
Fix quirk ID test ignoring custom clusters in v2 quirks (#264)
Browse files Browse the repository at this point in the history
* Also loop over custom clusters from v2 quirks

* Rename `all_quirk_ids` to `cluster_quirk_id_map`

* Add typing to `cluster_quirk_id_map` dict
  • Loading branch information
TheJulianJES authored Oct 26, 2024
1 parent 922f266 commit 593d33c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions tests/test_cluster_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# pylint:disable=redefined-outer-name,too-many-lines

from __future__ import annotations

import logging
import math
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -563,9 +565,21 @@ def test_cluster_handler_registry() -> None:
"""Test ZIGBEE cluster handler Registry."""

# get all quirk ID from zigpy quirks registry
all_quirk_ids = {}
cluster_quirk_id_map: dict[int, set[str | None]] = {}
for cluster_id in CLUSTERS_BY_ID:
all_quirk_ids[cluster_id] = {None}
cluster_quirk_id_map[cluster_id] = {None}

# loop over custom clusters in v2 quirks registry
for quirks in _DEVICE_REGISTRY._registry_v2.values():
for quirk_reg_entry in quirks:
# get standalone adds_metadata and adds_metadata from replaces_metadata
all_metadata = set(quirk_reg_entry.adds_metadata) | {
rm.add for rm in quirk_reg_entry.replaces_metadata
}
for metadata in all_metadata:
cluster_quirk_id_map[metadata.cluster.cluster_id] = {None}

# loop over custom clusters in v1 quirks registry
for manufacturer in _DEVICE_REGISTRY.registry.values():
for model_quirk_list in manufacturer.values():
for quirk in model_quirk_list:
Expand All @@ -583,22 +597,22 @@ def test_cluster_handler_registry() -> None:
for cluster_id in cluster_ids:
if not isinstance(cluster_id, int):
cluster_id = cluster_id.cluster_id
if cluster_id not in all_quirk_ids:
all_quirk_ids[cluster_id] = {None}
all_quirk_ids[cluster_id].add(quirk_id)
if cluster_id not in cluster_quirk_id_map:
cluster_quirk_id_map[cluster_id] = {None}
cluster_quirk_id_map[cluster_id].add(quirk_id)

for (
cluster_id,
cluster_handler_classes,
) in CLUSTER_HANDLER_REGISTRY.items():
assert isinstance(cluster_id, int)
assert 0 <= cluster_id <= 0xFFFF
assert cluster_id in all_quirk_ids
assert cluster_id in cluster_quirk_id_map
assert isinstance(cluster_handler_classes, dict)
for quirk_id, cluster_handler in cluster_handler_classes.items():
assert quirk_id is None or isinstance(quirk_id, str)
assert issubclass(cluster_handler, ClusterHandler)
assert quirk_id in all_quirk_ids[cluster_id]
assert quirk_id in cluster_quirk_id_map[cluster_id]


def test_epch_unclaimed_cluster_handlers(cluster_handler) -> None:
Expand Down

0 comments on commit 593d33c

Please sign in to comment.