Skip to content

Derive entity registry key from _cluster_match#813

Draft
TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/derive-entity-registry-key
Draft

Derive entity registry key from _cluster_match#813
TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/derive-entity-registry-key

Conversation

@TheJulianJES

Copy link
Copy Markdown
Contributor

DRAFT.

@register_entity(cluster_id) took an explicit cluster ID that was used only as a key into ENTITY_REGISTRY to speed up discovery lookups — the actual matching is done entirely by the class's _cluster_match. The ID was therefore redundant: in every one of the 304 registrations it was one of the match's mandatory clusters (server_clusters/client_clusters), and nothing enforced that it was.

Make register_entity a bare decorator that derives the key from the match. Since every mandatory cluster must be present for a match to succeed, indexing under any single one is a sufficient discovery key, so each class stays in exactly one bucket (no double-evaluation during discovery). The resulting ENTITY_REGISTRY is byte-for-byte identical to before — same buckets, same ordering — so discovery behavior is unchanged.

Also drop the now-unused OnOff as OnOffCluster alias in cover.

`@register_entity(cluster_id)` took an explicit cluster ID that was used
only as a key into `ENTITY_REGISTRY` to speed up discovery lookups — the
actual matching is done entirely by the class's `_cluster_match`. The ID
was therefore redundant: in every one of the 304 registrations it was one
of the match's mandatory clusters (`server_clusters`/`client_clusters`),
and nothing enforced that it was.

Make `register_entity` a bare decorator that derives the key from the
match. Since every mandatory cluster must be present for a match to
succeed, indexing under any single one is a sufficient discovery key, so
each class stays in exactly one bucket (no double-evaluation during
discovery). The resulting `ENTITY_REGISTRY` is byte-for-byte identical to
before — same buckets, same ordering — so discovery behavior is unchanged.

Also drop the now-unused `OnOff as OnOffCluster` alias in cover.
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.36306% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.27%. Comparing base (063f18f) to head (5184bd1).
⚠️ Report is 4 commits behind head on dev.

Files with missing lines Patch % Lines
zha/application/platforms/__init__.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #813      +/-   ##
==========================================
- Coverage   97.29%   97.27%   -0.02%     
==========================================
  Files          55       55              
  Lines       10934    10937       +3     
==========================================
+ Hits        10638    10639       +1     
- Misses        296      298       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

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.

Pull request overview

This PR refactors entity discovery registration by making @register_entity derive its registry bucket key from each entity’s _cluster_match, removing the previously redundant explicit cluster-id argument while keeping discovery behavior the same.

Changes:

  • Convert register_entity from a decorator factory (@register_entity(cluster_id)) into a bare decorator (@register_entity) that computes the registry key from _cluster_match.
  • Update all platform entity registrations to use the new bare decorator form.
  • Remove an unused import alias in the cover platform (OnOff as OnOffCluster).

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
zha/application/platforms/init.py Reworks register_entity to derive the ENTITY_REGISTRY key from _cluster_match and adds validation.
zha/application/platforms/virtual.py Updates all virtual entities to use @register_entity without an explicit cluster id.
zha/application/platforms/update.py Updates OTA update entities to use the bare @register_entity decorator.
zha/application/platforms/switch.py Updates switch entities to use the bare @register_entity decorator.
zha/application/platforms/siren.py Updates siren entities to use the bare @register_entity decorator.
zha/application/platforms/sensor/init.py Updates sensor entities to use the bare @register_entity decorator.
zha/application/platforms/select.py Updates select entities to use the bare @register_entity decorator.
zha/application/platforms/number/init.py Updates number entities to use the bare @register_entity decorator.
zha/application/platforms/lock/init.py Updates lock entity to use the bare @register_entity decorator.
zha/application/platforms/light/init.py Updates light entities to use the bare @register_entity decorator.
zha/application/platforms/fan/init.py Updates fan entities to use the bare @register_entity decorator.
zha/application/platforms/device_tracker.py Updates device tracker entity to use the bare @register_entity decorator.
zha/application/platforms/cover/init.py Updates cover entities to use the bare @register_entity decorator and removes unused OnOffCluster alias import.
zha/application/platforms/climate/init.py Updates climate entities to use the bare @register_entity decorator.
zha/application/platforms/button/init.py Updates button entities to use the bare @register_entity decorator.
zha/application/platforms/binary_sensor/init.py Updates binary sensor entities to use the bare @register_entity decorator.
zha/application/platforms/alarm_control_panel/init.py Updates alarm control panel entity to use the bare @register_entity decorator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants