From 981177da2355557e9981293a8e7f8f49000abcbf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 30 Jun 2025 12:09:07 -0500 Subject: [PATCH] todo --- esphome/components/ota/ota.h | 30 ++++++++++++++++++- esphome/components/ota_base/ota_backend.h | 8 +++++ .../web_server_base/web_server_base.h | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/esphome/components/ota/ota.h b/esphome/components/ota/ota.h index 17d2d24d00..42a6cdbe85 100644 --- a/esphome/components/ota/ota.h +++ b/esphome/components/ota/ota.h @@ -13,13 +13,41 @@ using ota_base::OTAResponseTypes; using ota_base::OTAState; // Re-export specific enum values for backward compatibility -// (in case external components use ota::OTA_STARTED, etc.) +// OTAState values static constexpr auto OTA_COMPLETED = ota_base::OTA_COMPLETED; static constexpr auto OTA_STARTED = ota_base::OTA_STARTED; static constexpr auto OTA_IN_PROGRESS = ota_base::OTA_IN_PROGRESS; static constexpr auto OTA_ABORT = ota_base::OTA_ABORT; static constexpr auto OTA_ERROR = ota_base::OTA_ERROR; +// OTAResponseTypes values +static constexpr auto OTA_RESPONSE_OK = ota_base::OTA_RESPONSE_OK; +static constexpr auto OTA_RESPONSE_REQUEST_AUTH = ota_base::OTA_RESPONSE_REQUEST_AUTH; +static constexpr auto OTA_RESPONSE_HEADER_OK = ota_base::OTA_RESPONSE_HEADER_OK; +static constexpr auto OTA_RESPONSE_AUTH_OK = ota_base::OTA_RESPONSE_AUTH_OK; +static constexpr auto OTA_RESPONSE_UPDATE_PREPARE_OK = ota_base::OTA_RESPONSE_UPDATE_PREPARE_OK; +static constexpr auto OTA_RESPONSE_BIN_MD5_OK = ota_base::OTA_RESPONSE_BIN_MD5_OK; +static constexpr auto OTA_RESPONSE_RECEIVE_OK = ota_base::OTA_RESPONSE_RECEIVE_OK; +static constexpr auto OTA_RESPONSE_UPDATE_END_OK = ota_base::OTA_RESPONSE_UPDATE_END_OK; +static constexpr auto OTA_RESPONSE_SUPPORTS_COMPRESSION = ota_base::OTA_RESPONSE_SUPPORTS_COMPRESSION; +static constexpr auto OTA_RESPONSE_CHUNK_OK = ota_base::OTA_RESPONSE_CHUNK_OK; +static constexpr auto OTA_RESPONSE_ERROR_MAGIC = ota_base::OTA_RESPONSE_ERROR_MAGIC; +static constexpr auto OTA_RESPONSE_ERROR_UPDATE_PREPARE = ota_base::OTA_RESPONSE_ERROR_UPDATE_PREPARE; +static constexpr auto OTA_RESPONSE_ERROR_AUTH_INVALID = ota_base::OTA_RESPONSE_ERROR_AUTH_INVALID; +static constexpr auto OTA_RESPONSE_ERROR_WRITING_FLASH = ota_base::OTA_RESPONSE_ERROR_WRITING_FLASH; +static constexpr auto OTA_RESPONSE_ERROR_UPDATE_END = ota_base::OTA_RESPONSE_ERROR_UPDATE_END; +static constexpr auto OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING = ota_base::OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING; +static constexpr auto OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = + ota_base::OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG; +static constexpr auto OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = ota_base::OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG; +static constexpr auto OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = + ota_base::OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE; +static constexpr auto OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = ota_base::OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE; +static constexpr auto OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = ota_base::OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION; +static constexpr auto OTA_RESPONSE_ERROR_MD5_MISMATCH = ota_base::OTA_RESPONSE_ERROR_MD5_MISMATCH; +static constexpr auto OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE = ota_base::OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE; +static constexpr auto OTA_RESPONSE_ERROR_UNKNOWN = ota_base::OTA_RESPONSE_ERROR_UNKNOWN; + #ifdef USE_OTA_STATE_CALLBACK using ota_base::OTAGlobalCallback; diff --git a/esphome/components/ota_base/ota_backend.h b/esphome/components/ota_base/ota_backend.h index 8e2831a063..7f4c89a540 100644 --- a/esphome/components/ota_base/ota_backend.h +++ b/esphome/components/ota_base/ota_backend.h @@ -91,6 +91,14 @@ class OTAGlobalCallback { OTAGlobalCallback *get_global_ota_callback(); void register_ota_platform(OTAComponent *ota_caller); + +// TODO: When web_server is updated to use ota_base, we need to add thread-safe +// callback execution. The web_server OTA runs in a separate task, so callbacks +// need to be deferred to the main loop task to avoid race conditions. +// This could be implemented using: +// - A queue of callback events that the main loop processes +// - Or using App.schedule() to defer callback execution to the main loop +// Example: App.schedule([=]() { state_callback_.call(state, progress, error); }); #endif } // namespace ota_base diff --git a/esphome/components/web_server_base/web_server_base.h b/esphome/components/web_server_base/web_server_base.h index 641006cb99..a1e3added0 100644 --- a/esphome/components/web_server_base/web_server_base.h +++ b/esphome/components/web_server_base/web_server_base.h @@ -110,6 +110,8 @@ class WebServerBase : public Component { void add_handler(AsyncWebHandler *handler); + // TODO: In future PR, update this to use ota_base instead of duplicating OTA code + // Important: OTA callbacks must be thread-safe as web server OTA runs in a separate task void add_ota_handler(); void set_port(uint16_t port) { port_ = port; }