From 519c49f17512e1fc3af7b065fd5e9a96658ae165 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 30 Jun 2025 13:11:27 -0500 Subject: [PATCH] Revert "fix" This reverts commit c96ffefa42b43cf102f9615ace915f2d0fc532ac. --- esphome/components/ota_base/ota_backend.h | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/esphome/components/ota_base/ota_backend.h b/esphome/components/ota_base/ota_backend.h index b20155a45a..f60019ce5a 100644 --- a/esphome/components/ota_base/ota_backend.h +++ b/esphome/components/ota_base/ota_backend.h @@ -69,29 +69,29 @@ class OTAComponent : public Component { } protected: - /** Thread-safe callback wrapper that automatically defers to main loop. + /** Thread-safe callback manager that automatically defers to main loop. * * This ensures all OTA callbacks are executed in the main loop task, * making them safe to call from any context (including web_server's OTA task). * Existing code doesn't need changes - callbacks are automatically deferred. */ - class StateCallbackManager { + class DeferredCallbackManager : public CallbackManager { public: - StateCallbackManager(OTAComponent *component) : component_(component) {} - - void add(std::function &&callback) { callbacks_.add(std::move(callback)); } + DeferredCallbackManager(OTAComponent *component) : component_(component) {} + /// Override call to automatically defer to main loop void call(OTAState state, float progress, uint8_t error) { // Always defer to main loop for thread safety - component_->defer([this, state, progress, error]() { this->callbacks_.call(state, progress, error); }); + component_->defer([this, state, progress, error]() { + CallbackManager::call(state, progress, error); + }); } private: OTAComponent *component_; - CallbackManager callbacks_; }; - StateCallbackManager state_callback_{this}; + DeferredCallbackManager state_callback_{this}; #endif }; @@ -114,10 +114,10 @@ class OTAGlobalCallback { OTAGlobalCallback *get_global_ota_callback(); void register_ota_platform(OTAComponent *ota_caller); -// Thread-safe callback execution is automatically provided by StateCallbackManager -// which uses Component::defer() to ensure all OTA callbacks run in the main loop task. -// This makes OTA callbacks safe to call from any context including web_server's -// separate OTA task. No code changes needed. +// Thread-safe callback execution is automatically provided by DeferredCallbackManager +// which overrides call() to use Component::defer(). This ensures all OTA callbacks +// run in the main loop task, making them safe to call from any context including +// web_server's separate OTA task. No code changes needed. #endif } // namespace ota_base