From bf6d75fd5e62fd4d6b90de8199dff4b43fbc7564 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Jan 2026 22:08:57 -1000 Subject: [PATCH] fix --- esphome/core/scheduler.cpp | 12 ++++++------ esphome/core/scheduler.h | 2 +- .../fixtures/scheduler_numeric_id_test.yaml | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 5ef959a36c..6dac2a36d3 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -279,7 +279,7 @@ void retry_handler(const std::shared_ptr &args) { void HOT Scheduler::set_retry_common_(Component *component, NameType name_type, const char *static_name, uint32_t hash_or_id, uint32_t initial_wait_time, uint8_t max_attempts, std::function func, float backoff_increase_factor) { - this->cancel_retry(component, name_type, static_name, hash_or_id); + this->cancel_retry_(component, name_type, static_name, hash_or_id); if (initial_wait_time == SCHEDULER_DONT_RUN) return; @@ -321,13 +321,13 @@ void HOT Scheduler::set_retry(Component *component, const char *name, uint32_t i backoff_increase_factor); } -bool HOT Scheduler::cancel_retry(Component *component, NameType name_type, const char *static_name, - uint32_t hash_or_id) { +bool HOT Scheduler::cancel_retry_(Component *component, NameType name_type, const char *static_name, + uint32_t hash_or_id) { return this->cancel_item_(component, name_type, static_name, hash_or_id, SchedulerItem::TIMEOUT, /* match_retry= */ true); } bool HOT Scheduler::cancel_retry(Component *component, const char *name) { - return this->cancel_retry(component, NameType::STATIC_STRING, name, 0); + return this->cancel_retry_(component, NameType::STATIC_STRING, name, 0); } void HOT Scheduler::set_retry(Component *component, const std::string &name, uint32_t initial_wait_time, @@ -338,7 +338,7 @@ void HOT Scheduler::set_retry(Component *component, const std::string &name, uin } bool HOT Scheduler::cancel_retry(Component *component, const std::string &name) { - return this->cancel_retry(component, NameType::HASHED_STRING, nullptr, fnv1a_hash(name)); + return this->cancel_retry_(component, NameType::HASHED_STRING, nullptr, fnv1a_hash(name)); } void HOT Scheduler::set_retry(Component *component, uint32_t id, uint32_t initial_wait_time, uint8_t max_attempts, @@ -348,7 +348,7 @@ void HOT Scheduler::set_retry(Component *component, uint32_t id, uint32_t initia } bool HOT Scheduler::cancel_retry(Component *component, uint32_t id) { - return this->cancel_retry(component, NameType::NUMERIC_ID, nullptr, id); + return this->cancel_retry_(component, NameType::NUMERIC_ID, nullptr, id); } optional HOT Scheduler::next_schedule_in(uint32_t now) { diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 4333f74f7d..92ff93879a 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -237,7 +237,7 @@ class Scheduler { uint32_t initial_wait_time, uint8_t max_attempts, std::function func, float backoff_increase_factor); // Common implementation for cancel_retry - bool cancel_retry(Component *component, NameType name_type, const char *static_name, uint32_t hash_or_id); + bool cancel_retry_(Component *component, NameType name_type, const char *static_name, uint32_t hash_or_id); uint64_t millis_64_(uint32_t now); // Cleanup logically deleted items from the scheduler diff --git a/tests/integration/fixtures/scheduler_numeric_id_test.yaml b/tests/integration/fixtures/scheduler_numeric_id_test.yaml index 29b547d66d..bf60f2fda9 100644 --- a/tests/integration/fixtures/scheduler_numeric_id_test.yaml +++ b/tests/integration/fixtures/scheduler_numeric_id_test.yaml @@ -88,11 +88,13 @@ script: }); // Test set_interval with uint32_t ID - this->set_interval(5002U, 400, []() { + // Capture 'this' pointer so we can cancel with correct component + auto *self = this; + this->set_interval(5002U, 400, [self]() { ESP_LOGI("test", "Component numeric interval 5002 fired"); id(interval_counter) += 1; - // Cancel after first fire - App.scheduler.cancel_interval(nullptr, 5002U); + // Cancel after first fire - must use same component pointer + App.scheduler.cancel_interval(self, 5002U); }); } };