diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index a89bb40b7d..3542a9547c 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -248,6 +248,9 @@ bool Component::cancel_defer(const std::string &name) { // NOLINT void Component::defer(const std::string &name, std::function &&f) { // NOLINT App.scheduler.set_timeout(this, name, 0, std::move(f)); } +void Component::defer(const char *name, std::function &&f) { // NOLINT + App.scheduler.set_timeout(this, name, 0, std::move(f)); +} void Component::set_timeout(uint32_t timeout, std::function &&f) { // NOLINT App.scheduler.set_timeout(this, "", timeout, std::move(f)); } diff --git a/esphome/core/component.h b/esphome/core/component.h index fab28f1576..8b51c14507 100644 --- a/esphome/core/component.h +++ b/esphome/core/component.h @@ -381,6 +381,21 @@ class Component { */ void defer(const std::string &name, std::function &&f); // NOLINT + /** Defer a callback to the next loop() call with a const char* name. + * + * IMPORTANT: The provided name pointer must remain valid for the lifetime of the deferred task. + * This means the name should be: + * - A string literal (e.g., "update") + * - A static const char* variable + * - A pointer with lifetime >= the deferred execution + * + * For dynamic strings, use the std::string overload instead. + * + * @param name The name of the defer function (must have static lifetime) + * @param f The callback + */ + void defer(const char *name, std::function &&f); // NOLINT + /// Defer a callback to the next loop() call. void defer(std::function &&f); // NOLINT diff --git a/requirements.txt b/requirements.txt index c4dae9792d..a6bcebaeea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ click==8.1.7 esphome-dashboard==20250514.0 aioesphomeapi==34.1.0 zeroconf==0.147.0 -puremagic==1.29 +puremagic==1.30 ruamel.yaml==0.18.14 # dashboard_import esphome-glyphsets==0.2.0 pillow==10.4.0