Reset update percentage after install#818
Draft
TheJulianJES wants to merge 3 commits into
Draft
Conversation
The update entity set `in_progress` back to `False` when an install completed, failed, or raised, but never cleared `update_percentage`. This left the entity reporting a stale percentage (typically 100%) with `in_progress == False`, an inconsistent state at the library boundary. Collapse the three duplicated reset blocks into a single `finally` that also clears `update_percentage`, so the progress state is always cleared regardless of the update's outcome.
Cover the regression where the update entity kept reporting a stale progress percentage after an install finished: verify it is reset to `None` on both successful and failed installs.
A CancelledError is a BaseException, so it bypasses the except handler and propagates untouched, while the finally block still clears in_progress and update_percentage. Guard both against regression.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #818 +/- ##
==========================================
- Coverage 97.29% 97.29% -0.01%
==========================================
Files 55 55
Lines 10933 10930 -3
==========================================
- Hits 10637 10634 -3
Misses 296 296 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DRAFT.
Reset
update_percentagewhen a firmware update finishesThe firmware update entity set
in_progressback toFalsewhen an install completed, failed, or raised, but never clearedupdate_percentage. This left the entity reporting a stale percentage (typically100) alongsidein_progress == False— an internally inconsistent state at the library boundary.Home Assistant's
updateplatform happens to mask the percentage (update_percentage if in_progress else None), so an HA frontend user usually doesn't notice. But the ZHA library's ownstatedict and websocket contract emit the stale value directly, and relying on a downstream consumer to sanitize our output is fragile — the library should report correct state itself.Fix
The three exit paths (exception, non-
SUCCESSstatus, success) each duplicatedself._attr_in_progress = False+maybe_emit_state_changed_event(). These are collapsed into a singlefinallyblock that also clearsself._attr_update_percentage, so the progress state is always cleared regardless of the update's outcome.This also fixes a latent bug on cancellation.
asyncio.CancelledErroris aBaseException, so it was never caught byexcept Exception, and without afinallythe old code skipped cleanup entirely — leaving the entity stuck atin_progress: true/100%indefinitely. The install call chain is unshielded end to end (HAasync_install_with_progress→ HA ZHAasync_install→ this entity →zigpyupdate_firmware), so a cancelled install task propagatesCancelledErrorstraight into this code. This is reachable in practice whenever the install task is cancelled while ZHA keeps running — e.g. an automation withmode: restartre-triggering,automation.reload/script.reload, or atimeout:wrappingupdate.install. Thefinallynow clears the state and lets theCancelledErrorpropagate untouched.Tests
test_firmware_update_success— assertupdate_percentageis reset toNoneafter a successful install (the primary regression; fails against the old code withassert 100.0 is None).test_firmware_update_raises— assert the progress state is cleared after a failed install.test_firmware_update_cancelled— new test: aCancelledErrorfromupdate_firmwarepropagates untouched (not wrapped inZHAException) and bothin_progressandupdate_percentageare still cleared.