Skip to content

Properly tear down group entities on membership changes and group removal - #849

Draft
TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/fix-group-entity-lifecycle
Draft

Properly tear down group entities on membership changes and group removal#849
TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/fix-group-entity-lifecycle

Conversation

@TheJulianJES

Copy link
Copy Markdown
Contributor

DRAFT. Description to be updated later. Just opening now, so I don't forget about this again.
I think this was related to the HA Core PR that creates "devices/services" for Zigbee groups:


Group entity teardown was previously skipped in three places, leaking member entity subscriptions (member entities kept references to dead group entities and kept invoking their debounced updates):

  • discover_group_entities cleared group_entities with a bare .clear() when a group dropped below 2 members, without calling on_remove() or unregister_group_entity(), and never removed a platform's group entity when that platform alone dropped below 2 eligible members (the stale entity remained registered and functional with a single backing member)
  • Gateway.group_removed popped the group without calling Group.on_remove(), unlike shutdown() and device_removed()
  • Group.on_remove() only removed the group entities themselves, leaving the member entity subscriptions in _entity_unsubs dangling

unregister_group_entity() now also verifies the exact entity instance is registered, so a delayed removal task cannot unregister a recreated group entity with the same unique id.

…oval

Group entity teardown was previously skipped in three places, leaking
member entity subscriptions (member entities kept references to dead
group entities and kept invoking their debounced updates):

- discover_group_entities cleared group_entities with a bare .clear()
  when a group dropped below 2 members, without calling on_remove() or
  unregister_group_entity(), and never removed a platform's group
  entity when that platform alone dropped below 2 eligible members
  (the stale entity remained registered and functional with a single
  backing member)
- Gateway.group_removed popped the group without calling
  Group.on_remove(), unlike shutdown() and device_removed()
- Group.on_remove() only removed the group entities themselves,
  leaving the member entity subscriptions in _entity_unsubs dangling

unregister_group_entity() now also verifies the exact entity instance
is registered, so a delayed removal task cannot unregister a recreated
group entity with the same unique id.
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.28%. Comparing base (c38e03e) to head (361987c).
⚠️ Report is 6 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #849      +/-   ##
==========================================
+ Coverage   97.27%   97.28%   +0.01%     
==========================================
  Files          55       55              
  Lines       10930    10954      +24     
==========================================
+ Hits        10632    10657      +25     
+ Misses        298      297       -1     

☔ 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.

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.

2 participants