-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port Inovelli VZM entities from ZHA to quirks v2 #5122
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """Tests for Inovelli quirks (VZM series).""" | ||
|
|
||
| import pytest | ||
| from zha.quirks import DEVICE_REGISTRY | ||
|
|
||
| import zhaquirks | ||
| from zhaquirks.builder.device import QuirkV2Factory | ||
| from zhaquirks.inovelli.builder import INOVELLI_CLUSTER_ID | ||
|
|
||
| zhaquirks.setup() | ||
|
|
||
|
|
||
| def _inovelli_v2_definitions(): | ||
| """Yield (model, QuirkDefinition) for every Inovelli VZM v2 quirk.""" | ||
| seen = set() | ||
| for entry in DEVICE_REGISTRY: | ||
| factory = entry.zha_device_factory | ||
| if not isinstance(factory, QuirkV2Factory): | ||
| continue | ||
| if "inovelli" not in str(entry.source.file).lower(): | ||
| continue | ||
| model = str(entry.source.file).split("/")[-1] | ||
|
Comment on lines
+22
to
+24
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll clean up this entire test file next. It's good enough to release an initial version with the ported quirks for HA beta and so we can port #5014.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zigpy-review-bot Create a "Task" issue, assign + tag me there, and mention what should be improved for the Inovelli quirks/tests. Also look through (comments in) the other two recently merged Inovelli PRs. List everything, possibly use /details blocks.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #5218 (type: Task, assigned to you). It collects the deferred items from this PR, #5014 and #4944: the |
||
| if model in seen: | ||
| continue | ||
| seen.add(model) | ||
| yield model, factory.quirk_definition | ||
|
|
||
|
|
||
| # Number of Inovelli ``0xFC31`` entities each device file is expected to expose. | ||
| # Locks the per-model set derived from the ZHA library's registration rules. | ||
| EXPECTED_ENTITY_COUNTS = { | ||
| "VZM30SN.py": 38, | ||
| "VZM31SN.py": 40, | ||
| "VZM32SN.py": 37, | ||
| "VZM35SN.py": 38, | ||
| "VZM36.py": 32, # 17 on endpoint 1 + 15 on endpoint 2 | ||
| } | ||
|
|
||
|
|
||
| def test_inovelli_quirks_present(): | ||
| """All five Inovelli VZM device files register a v2 quirk.""" | ||
| models = {model for model, _ in _inovelli_v2_definitions()} | ||
| assert models == set(EXPECTED_ENTITY_COUNTS) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("model", "definition"), | ||
| [(m, d) for m, d in _inovelli_v2_definitions()], | ||
| ) | ||
| def test_inovelli_entity_unique_id_suffix(model, definition): | ||
| """Every Inovelli cluster entity keeps the ZHA-native unique_id. | ||
|
|
||
| ZHA-native entities include the cluster id in their unique_id, but quirks v2 | ||
| entities do not. To avoid orphaning existing Home Assistant entities, every | ||
| ported entity must carry a ``64561[-<attribute>]`` suffix (``64561 == 0xFC31``). | ||
| """ | ||
| inovelli_entities = [ | ||
| em for em in definition.entity_metadata if em.cluster_id == INOVELLI_CLUSTER_ID | ||
| ] | ||
| assert len(inovelli_entities) == EXPECTED_ENTITY_COUNTS[model] | ||
|
TheJulianJES marked this conversation as resolved.
|
||
|
|
||
| for em in inovelli_entities: | ||
| suffix = em.unique_id_suffix | ||
| assert suffix is not None | ||
| # bare cluster id (internal temperature sensor) or ``64561-<attribute>`` | ||
| assert suffix == str(INOVELLI_CLUSTER_ID) or suffix.startswith( | ||
| f"{INOVELLI_CLUSTER_ID}-" | ||
| ), f"{model}: unexpected unique_id suffix {suffix!r}" | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean this up later. For now, it's good enough that we can merge the quirks and builder 😅