Adapt to zigpy OTA event refactor#717
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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_resultdevice-listener flow with an OTA-clusteron_eventlistener forOtaImageAvailableEvent. - Remove
device.add_listener/remove_listenerusage from firmware update entities and add a startup cached-OTA check viacheck_cluster_for_ota. - Update and extend tests to handle the post-OTA
image_notify→NO_IMAGE_AVAILABLEexchange 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.
| 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) | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
|
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). |
Tested and working with linked zigpy PR.
AI summary
Adapt to zigpy OTA refactor (
OtaImageAvailableEvent, post-OTAimage_notify)device.add_listener/device_ota_image_query_resultwithon_eventlistener forOtaImageAvailableEventon the OTA clusterFirmwareUpdateEntityandFirmwareUpdateServerEntityimage_notify→NO_IMAGE_AVAILABLEexchangePR:
OtaImageAvailableEventzigpy#1799HA Core change: