Skip to content

Adapt to zigpy OTA event refactor#717

Merged
TheJulianJES merged 5 commits intozigpy:devfrom
TheJulianJES:tjj/zigpy_ota_changes
Mar 24, 2026
Merged

Adapt to zigpy OTA event refactor#717
TheJulianJES merged 5 commits intozigpy:devfrom
TheJulianJES:tjj/zigpy_ota_changes

Conversation

@TheJulianJES
Copy link
Copy Markdown
Contributor

@TheJulianJES TheJulianJES commented Mar 24, 2026

Tested and working with linked zigpy PR.

AI summary

Adapt to zigpy OTA refactor (OtaImageAvailableEvent, post-OTA image_notify)

  • Replace device.add_listener / device_ota_image_query_result with on_event listener for OtaImageAvailableEvent on the OTA cluster
  • Remove device listener registration from both FirmwareUpdateEntity and FirmwareUpdateServerEntity
  • Update tests to handle post-OTA image_notifyNO_IMAGE_AVAILABLE exchange

PR:

HA Core change:

@TheJulianJES TheJulianJES changed the title Adjust for zigpy OTA changes Adapt to zigpy OTA event refactor Mar 24, 2026
@TheJulianJES TheJulianJES marked this pull request as ready for review March 24, 2026 06:04
Copilot AI review requested due to automatic review settings March 24, 2026 06:04
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (28f1515) to head (0067dfd).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #717   +/-   ##
=======================================
  Coverage   97.62%   97.62%           
=======================================
  Files          62       62           
  Lines       10954    10957    +3     
=======================================
+ Hits        10694    10697    +3     
  Misses        260      260           

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates ZHA’s update (firmware OTA) platform integration to align with zigpy’s OTA event refactor, switching from device-level listeners to cluster event subscriptions and updating tests to reflect the new post-OTA behavior.

Changes:

  • Replace the legacy device_ota_image_query_result device-listener flow with an OTA-cluster on_event listener for OtaImageAvailableEvent.
  • Remove device.add_listener / remove_listener usage from firmware update entities and add a startup cached-OTA check via check_cluster_for_ota.
  • Update and extend tests to handle the post-OTA image_notifyNO_IMAGE_AVAILABLE exchange and to validate cached OTA state pickup on startup.

Reviewed changes

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

File Description
zha/application/platforms/update.py Rewires OTA availability handling to zigpy’s OtaImageAvailableEvent and adds startup cached-OTA checks.
tests/test_update.py Adjusts OTA success/failure test flows for post-OTA behavior and adds coverage for cached OTA state on restart.

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

Comment on lines 313 to 334
def on_add(self) -> None:
"""Call when entity is added."""
super().on_add()

self.device.device.add_listener(self)
ota_cluster = self._ota_cluster_handler.cluster
self._on_remove_callbacks.append(
self._ota_cluster_handler.on_event(
CLUSTER_HANDLER_ATTRIBUTE_UPDATED,
self.handle_cluster_handler_attribute_updated,
)
)
self._on_remove_callbacks.append(
lambda: self.device.device.remove_listener(self)
ota_cluster.on_event(
OtaImageAvailableEvent.event_type,
self._handle_ota_image_available,
)
)

# Check for cached OTA image availability from zigpy
ota_cluster.create_catching_task(
self.device.device.application.ota.check_cluster_for_ota(ota_cluster)
)
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_add() in this entity duplicates the exact same OTA listener registration + cached-OTA check logic as FirmwareUpdateServerEntity.on_add(). Consider factoring this into a shared helper on BaseFirmwareUpdateEntity (e.g., _register_ota_listeners()) to avoid divergence when future zigpy/ZHA event wiring changes again.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

@TheJulianJES TheJulianJES Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think we want this in the base class? There's already some duplication between server and client, so I think this is fine. They are technically different cluster handlers (and clusters, somewhat).

Comment thread zha/application/platforms/update.py
@TheJulianJES
Copy link
Copy Markdown
Contributor Author

As mentioned in #718, this is required to get CI passing again because of the zigpy OTA changes linked in the PR description (image notify on pairing).

@TheJulianJES TheJulianJES merged commit e890251 into zigpy:dev Mar 24, 2026
13 checks passed
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