diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 7a0d33ee1b..e8e21cd38d 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -89,6 +89,7 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type if (delay == 0 && type == SchedulerItem::TIMEOUT) { // Put in defer queue for guaranteed FIFO execution LockGuard guard{this->lock_}; + this->cancel_deferred_item_locked_(component, is_static_string, name_ptr, type); this->defer_queue_.push_back(std::move(item)); return; } @@ -434,7 +435,7 @@ size_t HOT Scheduler::cancel_deferred_item_locked_(Component *component, const c SchedulerItem::Type type) { size_t cancelled_count = 0; for (auto &item : this->defer_queue_) { - if (item->component != component || item->type != type || item->remove) { + if (item->component != component || item->remove) { continue; } const char *item_name = item->get_name(); diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 844dfc600f..06a0543881 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -157,9 +157,11 @@ class Scheduler { // Cancel heap items (items_ and to_add_) bool cancel_heap_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type); +#if !defined(USE_ESP8266) && !defined(USE_RP2040) // Cancel deferred items (defer_queue_) bool cancel_deferred_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type); +#endif private: // Helper to execute a scheduler item