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.
This commit is contained in:
Guy Martin 2023-07-19 22:11:05 +02:00 committed by GitHub
parent 0f4c71f993
commit deafdc3005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -244,7 +244,10 @@ class MatchRule:
if callable(self.quirk_classes): if callable(self.quirk_classes):
matches.append(self.quirk_classes(quirk_class)) matches.append(self.quirk_classes(quirk_class))
else: 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 return matches

View File

@ -18,7 +18,8 @@ if typing.TYPE_CHECKING:
MANUFACTURER = "mock manufacturer" MANUFACTURER = "mock manufacturer"
MODEL = "mock model" MODEL = "mock model"
QUIRK_CLASS = "mock.class" QUIRK_CLASS = "mock.test.quirk.class"
QUIRK_CLASS_SHORT = "quirk.class"
@pytest.fixture @pytest.fixture
@ -209,6 +210,12 @@ def cluster_handlers(cluster_handler):
), ),
False, False,
), ),
(
registries.MatchRule(
cluster_handler_names="on_off", quirk_classes=QUIRK_CLASS_SHORT
),
True,
),
], ],
) )
def test_registry_matching(rule, matched, cluster_handlers) -> None: def test_registry_matching(rule, matched, cluster_handlers) -> None: