Skip to content

refactor: unify forced and non-forced OTA execution paths#690

Merged
BrentIO merged 1 commit into
mainfrom
fix/689
Jun 21, 2026
Merged

refactor: unify forced and non-forced OTA execution paths#690
BrentIO merged 1 commit into
mainfrom
fix/689

Conversation

@BrentIO

@BrentIO BrentIO commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Collapses the two separate code paths in otaFirmware_checkPending() into one, gated by a single isForced bool (_otaPendingDoc.size() > 0)
  • Removes the duplicate onProgress / onPartitionComplete / onComplete callback registrations that were copy-pasted into the forced path — the callbacks registered once in setup_OtaFirmware() now serve both paths
  • Adds _otaLastPublishedPercentage = -1 inside onProgress when a new partition is detected, so each partition starts with a fresh publish gate
  • Removes the premature {"in_progress": true} publish from the MQTT update/set handler — checkPending() now issues the proper retained message with full version info on the next loop tick

Fixes (#689)

  • Immediately shows 100%: the MQTT handler was publishing an incomplete state message with no update_percentage, installed_version, or latest_version; removed in favour of the unified publish in checkPending()
  • "Updating app" / "Updating ui" titles not published on MQTT-triggered OTA: _otaLastPublishedPercentage was never reset before calling execOTA() on the non-forced path; the pct != _otaLastPublishedPercentage guard then suppressed publishes when a small partition completed at the same percentage as the previous run
  • Progress bar doesn't restart when flashing UI: same guard issue at partition boundaries; now reset to -1 whenever onProgress detects a new partition

Test plan

  • Trigger OTA via MQTT (update/set ON) with an update available — confirm HA shows installed_version, latest_version, and in_progress: true immediately, starting from 0%
  • Confirm "Updating app" title appears in HA during app flash
  • Confirm progress bar resets to 0% and "Updating ui" title appears when UI flash begins
  • Trigger forced OTA via HTTP API — confirm behaviour is unchanged (version shows x.x.x (Forced), same progress/title behaviour)

🤖 Generated with Claude Code

Both paths now share the single set of callbacks registered in
setup_OtaFirmware(). otaFirmware_checkPending() uses an isForced bool to
gate the forced-only setup (application name, HTTPS client, version label),
then both paths share the _otaLastPublishedPercentage reset, the retained
in_progress MQTT publish with full version info, and the failure cleanup.

Fixes three symptoms on MQTT-triggered OTA:
- immediately shows 100% (premature incomplete MQTT publish removed from
  the update/set handler; checkPending now issues the proper message)
- Updating app/ui titles not published (missing percentage reset before
  execOTA and on partition boundary now both handled)
- progress bar not restarting between app and ui partitions (_otaLastPublishedPercentage
  reset added inside onProgress when a new partition is detected)

Closes #689

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@BrentIO BrentIO merged commit b2bc49e into main Jun 21, 2026
2 checks passed
@BrentIO BrentIO deleted the fix/689 branch June 21, 2026 21:43
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