Skip to content

Entity recomputation and add/remove at runtime #517

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

puddly
Copy link
Contributor

@puddly puddly commented Aug 14, 2025

This PR introduces two new events to the ZHA device object:

  • DeviceEntityAddedEvent(unique_id: str)
  • DeviceEntityRemovedEvent(unique_id: str)

And a new method:

  • recompute_entities()

recompute_entities() will emit the above events when entities are added/removed at runtime. I've added it to the main device discovery unit test to make sure that it's idempotent.

Future TODOs:

  • Re-interview devices after OTA.
  • Call recompute_entities on device rejoin to deal with devices that change modes.
  • Call recompute_entities after device reconfiguration button is clicked.
  • This is too expensive to call on every attribute update but it would be nice to figure out how to do this dynamically, to supersede the above manual calls?

@puddly puddly force-pushed the puddly/dynamic-entities branch from 8af5782 to 983586a Compare August 14, 2025 19:16
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 93.75000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.88%. Comparing base (c66f3c1) to head (d4118a6).

Files with missing lines Patch % Lines
zha/zigbee/device.py 93.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #517      +/-   ##
==========================================
- Coverage   96.89%   96.88%   -0.01%     
==========================================
  Files          63       63              
  Lines       10494    10536      +42     
==========================================
+ Hits        10168    10208      +40     
- Misses        326      328       +2     

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant