From deafdc3005ca8150a5f777776d37beaf836046ce Mon Sep 17 00:00:00 2001 From: Guy Martin Date: Wed, 19 Jul 2023 22:11:05 +0200 Subject: [PATCH] Allow match quirk_class of custom quirks to ZHA (#93268) * Allow matching custom quirks when self.quirk_classes might not contain the full class path but only the module and the class. * Add test for matching custom quirk classes. --- homeassistant/components/zha/core/registries.py | 5 ++++- tests/components/zha/test_registries.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 0c7369f15e7..03fdc7e37c1 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -244,7 +244,10 @@ class MatchRule: if callable(self.quirk_classes): matches.append(self.quirk_classes(quirk_class)) else: - matches.append(quirk_class in self.quirk_classes) + matches.append( + quirk_class.split(".")[-2:] + in [x.split(".")[-2:] for x in self.quirk_classes] + ) return matches diff --git a/tests/components/zha/test_registries.py b/tests/components/zha/test_registries.py index 057921f80a9..6f36ee624e9 100644 --- a/tests/components/zha/test_registries.py +++ b/tests/components/zha/test_registries.py @@ -18,7 +18,8 @@ if typing.TYPE_CHECKING: MANUFACTURER = "mock manufacturer" MODEL = "mock model" -QUIRK_CLASS = "mock.class" +QUIRK_CLASS = "mock.test.quirk.class" +QUIRK_CLASS_SHORT = "quirk.class" @pytest.fixture @@ -209,6 +210,12 @@ def cluster_handlers(cluster_handler): ), False, ), + ( + registries.MatchRule( + cluster_handler_names="on_off", quirk_classes=QUIRK_CLASS_SHORT + ), + True, + ), ], ) def test_registry_matching(rule, matched, cluster_handlers) -> None: