Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quirk ID test ignoring custom clusters in v2 quirks #264

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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