Skip to content

Codex updated: Harden device entity lifecycle and command forwarding#834

Draft
dmulcahey wants to merge 1 commit into
devfrom
codex-updated-pr-689
Draft

Codex updated: Harden device entity lifecycle and command forwarding#834
dmulcahey wants to merge 1 commit into
devfrom
codex-updated-pr-689

Conversation

@dmulcahey

Copy link
Copy Markdown
Contributor

This pull request was created with Codex and is an updated version of the pull request it supersedes.

Original pull request: #689

This pull request introduces important improvements to entity and device lifecycle management in the Zigbee integration, focusing on robust cleanup, initialization, and manufacturer-specific command handling. The main goals are to prevent stale state accumulation, ensure proper error handling during entity and endpoint removal, and guarantee that manufacturer codes are correctly forwarded in cluster commands.

Entity and Device Lifecycle Improvements:

  • Added exception handling for on_remove callbacks in platform entities, preventing a single callback failure from aborting entity cleanup and ensuring all tracked tasks are cancelled and removed properly (zha/application/platforms/__init__.py). [1] [2]
  • Modified device initialization to drain and clean up stale pending entities before starting a new discovery cycle, logging any failures instead of aborting initialization (zha/zigbee/device.py).
  • Ensured that repeated async_initialize passes do not accumulate pending entities by clearing the pending list after each initialization, and keeping entity instances stable across re-initialization (zha/zigbee/device.py).
  • Prevented false-positive device status transitions by tracking endpoint initialization failures and only setting status to INITIALIZED if all endpoints initialize successfully (zha/zigbee/device.py). [1] [2]

Cluster Command Handling:

  • Updated issue_cluster_command to correctly forward manufacturer codes in both args and params invocation paths, ensuring manufacturer-specific commands are properly framed for compatibility and reliability (zha/zigbee/device.py).

Testing Enhancements:

  • Added comprehensive tests to validate correct manufacturer forwarding, proper stale entity cleanup, prevention of pending entity growth, and robust error handling in initialization and removal flows (tests/test_device.py). [1] [2]

These changes collectively strengthen the reliability and maintainability of device and entity management in the Zigbee integration, reducing lifecycle errors and improving support for manufacturer-specific device interactions.## Summary
Hardens device/entity lifecycle initialization and cluster command forwarding.

Failing tests addressed

  • tests/test_device.py::test_issue_cluster_command
  • tests/test_device.py::test_platform_entity_on_remove_callback_failure_does_not_abort_cleanup
  • tests/test_device.py::test_async_initialize_does_not_grow_pending_entities_between_passes
  • tests/test_device.py::test_async_initialize_does_not_mark_initialized_if_endpoint_init_fails
  • tests/test_sensor.py::test_device_counter_sensors
  • tests/test_sensor.py::test_device_unavailable_or_disabled_skips_entity_polling
  • tests/test_light.py::test_light_refresh

Verification

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

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.30%. Comparing base (c38e03e) to head (80b8570).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #834      +/-   ##
==========================================
+ Coverage   97.27%   97.30%   +0.03%     
==========================================
  Files          55       55              
  Lines       10930    10946      +16     
==========================================
+ Hits        10632    10651      +19     
+ Misses        298      295       -3     

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

1 participant