Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,32 @@ async def test_join_binding_reporting(zha_gateway: Gateway) -> None:
]


async def test_quirks_v2_prevent_entity_also_prevents_binding(
zha_gateway: Gateway,
) -> None:
"""A quirk-prevented entity must not drive cluster binding."""
zigpy_dev = await zigpy_device_from_json(
zha_gateway.application_controller,
"tests/data/devices/innr-sp-240.json",
)
Comment on lines +1204 to +1208
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the docstring would describe a bit better what the quirk does here, since you have to guess a bit, or know that it prevents default entity creation for all entities on the LevelControl cluster.


level = zigpy_dev.endpoints[1].level
on_off = zigpy_dev.endpoints[1].on_off

with (
patch.object(level, "bind", wraps=level.bind) as mock_level_bind,
patch.object(on_off, "bind", wraps=on_off.bind) as mock_on_off_bind,
):
zha_device = await join_zigpy_device(zha_gateway, zigpy_dev)
Comment on lines +1205 to +1217
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my docstring comment below is related to this. I do kind of agree that it's not perfect to have ZHA rely on zha-quirks for its tests (that do not test the quirk but some ZHA feature). Realistically, the quirk for this device should never change, so I think updating the docstring a bit is probably enough.


assert zha_device.quirk_applied

# The prevented LevelControl entity no longer binds its cluster, while the
# sibling OnOff entity (not prevented) still does.
assert mock_level_bind.mock_calls == []
assert mock_on_off_bind.mock_calls == [call()]


async def test_endpoint_none_profile(
zha_gateway: Gateway,
caplog: pytest.LogCaptureFixture,
Expand Down
6 changes: 5 additions & 1 deletion zha/zigbee/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,14 @@ def _discover_new_entities(self) -> None:

# Discover all applicable entities
for entity in new_entities:
self._discovered_entities.append(entity)
# A quirk-prevented entity must not drive cluster binding or
# reporting either, so it's kept out of `_discovered_entities`
# (the source for `aggregate_cluster_configs`) entirely.
if self._is_entity_removed_by_quirk(entity):
continue

self._discovered_entities.append(entity)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring on this list at device.py:403-406 is now stale — it states _discovered_entities includes "ones removed by a quirk" so binding/reporting matches the legacy claim-during-discovery flow, which is precisely what this PR reverses. Please update it to reflect that quirk-prevented entities are now excluded.


Comment on lines +1161 to +1168
# Apply any metadata changes from quirks v2
self._apply_entity_metadata_changes(entity)

Expand Down
Loading