Skip to content

Preserve discovery progress and group cleanup on membership changes#691

Open
dmulcahey wants to merge 1 commit intodevfrom
pr/fix-discovery-resilience-group-pruning
Open

Preserve discovery progress and group cleanup on membership changes#691
dmulcahey wants to merge 1 commit intodevfrom
pr/fix-discovery-resilience-group-pruning

Conversation

@dmulcahey
Copy link
Contributor

@dmulcahey dmulcahey commented Feb 27, 2026

This pull request introduces robust error handling and lifecycle management improvements for device and group entity discovery in the ZHA integration. The changes ensure that exceptions during endpoint discovery do not halt discovery for other endpoints, and that group entity cleanup properly invokes lifecycle methods, preventing resource leaks and stale entities.

Improved error handling for entity discovery

  • Modified discover_device_entities to catch exceptions during endpoint discovery, log the error, and continue processing remaining endpoints, preventing partial entity loss.
  • Added a test (test_discover_device_entities_continues_after_endpoint_exception) to verify that discovery continues after an endpoint exception.

Group entity lifecycle and cleanup enhancements

  • Updated discover_group_entities to schedule lifecycle cleanup (on_remove) for group entities when group membership drops below quorum, instead of directly clearing entities, ensuring proper cleanup and avoiding leaks.
  • Added logic to prune stale group platform entities when their platform quorum drops below two, invoking cleanup for each affected entity.
  • Added tests to verify group entity cleanup (test_discover_group_entities_member_drop_runs_group_entity_on_remove) and stale platform entity pruning (test_discover_group_entities_platform_quorum_drop_prunes_stale_platform_entity).

Test infrastructure updates

  • Imported new helpers and references in tests/test_discover.py to support the new tests and discovery logic.## Summary
    Makes discovery resilient to per-endpoint exceptions and ensures stale group entities are removed via lifecycle cleanup when membership/platform quorum changes.

Failing tests addressed

  • tests/test_discover.py::test_discover_device_entities_continues_after_endpoint_exception
  • tests/test_discover.py::test_discover_group_entities_member_drop_runs_group_entity_on_remove
  • tests/test_discover.py::test_discover_group_entities_platform_quorum_drop_prunes_stale_platform_entity

Verification

  • pytest (branch-local targeted run): all listed tests pass.

@dmulcahey dmulcahey force-pushed the pr/fix-discovery-resilience-group-pruning branch from 65f9d47 to a243bc2 Compare February 27, 2026 16:04
@dmulcahey dmulcahey changed the base branch from dm/codex-issue-exploration to dev February 27, 2026 16:04
@dmulcahey dmulcahey closed this Feb 27, 2026
@dmulcahey dmulcahey reopened this Feb 27, 2026
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.52%. Comparing base (9d03d63) to head (a243bc2).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #691      +/-   ##
==========================================
+ Coverage   97.51%   97.52%   +0.01%     
==========================================
  Files          62       62              
  Lines       10949    10960      +11     
==========================================
+ Hits        10677    10689      +12     
+ Misses        272      271       -1     

☔ 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