From c26d1803253fc1f7b3ce720a0769d1d8e4773c37 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 13 Apr 2026 13:07:50 -1000 Subject: [PATCH] Emit OTA_ABORT state when tearing down a stale session on retry Addresses Copilot review suggestion on #15720: when the handler aborts a previously interrupted OTA session because a new upload arrived, also fire the OTA_ABORT state notification so user-facing on_abort: automations and other OTA state listeners observe the teardown. Without this, the abort would be silent to listeners (distinct from OTA_ERROR, which signals a failed session rather than a superseded one). --- esphome/components/web_server/ota/ota_web_server.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/components/web_server/ota/ota_web_server.cpp b/esphome/components/web_server/ota/ota_web_server.cpp index 4edab37603e..9812714ec03 100644 --- a/esphome/components/web_server/ota/ota_web_server.cpp +++ b/esphome/components/web_server/ota/ota_web_server.cpp @@ -126,6 +126,10 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Platf if (this->ota_backend_) { ESP_LOGW(TAG, "New OTA upload received while previous session was still open; aborting previous session"); this->ota_backend_->abort(); +#ifdef USE_OTA_STATE_LISTENER + // Notify listeners that the previous session was aborted before the new one starts. + this->parent_->notify_state_deferred_(ota::OTA_ABORT, 0.0f, 0); +#endif this->ota_backend_.reset(); }