22namespace setup_priority {
25inline constexpr float BUS = 1000.0f;
27inline constexpr float IO = 900.0f;
31inline constexpr float DATA = 600.0f;
36inline constexpr float WIFI = 250.0f;
45inline constexpr float LATE = -100.0f;
60class PollingComponent;
65#define LOG_UPDATE_INTERVAL(this) log_update_interval(TAG, this)
123#ifdef USE_LOOP_PRIORITY
176 ESPDEPRECATED(
"Use mark_failed(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary "
177 "strings. Will stop working in 2026.6.0",
180#pragma GCC diagnostic push
181#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
183#pragma GCC diagnostic pop
248 ESPDEPRECATED(
"Use status_set_error(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary "
249 "strings. Will stop working in 2026.6.0",
333 ESPDEPRECATED(
"Use const char* or uint32_t overload instead. Removed in 2026.7.0",
"2026.1.0")
334 void
set_interval(const std::
string &name, uint32_t interval, std::function<
void()> &&
f);
350 void set_interval(const
char *name, uint32_t interval, std::function<
void()> &&
f);
358 void set_interval(uint32_t
id, uint32_t interval, std::function<
void()> &&
f);
370 ESPDEPRECATED("Use const
char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0")
402 ESPDEPRECATED("cancel_retry is deprecated and will be removed in 2026.8.0.", "2026.2.0")
403 bool cancel_retry(const std::
string &name);
405 ESPDEPRECATED("cancel_retry is deprecated and will be removed in 2026.8.0.", "2026.2.0")
406 bool cancel_retry(const
char *name);
408 ESPDEPRECATED("cancel_retry is deprecated and will be removed in 2026.8.0.", "2026.2.0")
409 bool cancel_retry(uint32_t
id);
426 ESPDEPRECATED("Use const
char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0")
427 void set_timeout(const std::
string &name, uint32_t timeout, std::function<
void()> &&
f);
443 void set_timeout(const
char *name, uint32_t timeout, std::function<
void()> &&
f);
451 void set_timeout(uint32_t
id, uint32_t timeout, std::function<
void()> &&
f);
463 ESPDEPRECATED("Use const
char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0")
477 ESPDEPRECATED("Use const
char* overload instead. Removed in 2026.7.0", "2026.1.0")
478 void defer(const std::
string &name, std::function<
void()> &&
f);
493 void defer(const
char *name, std::function<
void()> &&
f);
499 void defer(uint32_t
id, std::function<
void()> &&
f);
503 ESPDEPRECATED("Use const
char* overload instead. Removed in 2026.7.0", "2026.1.0")
void mark_failed()
Mark this component as failed.
void status_momentary_error(const char *name, uint32_t length=5000)
Set error status flag and automatically clear it after a timeout.
ESPDEPRECATED("Use status_set_error(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary " "strings. Will stop working in 2026.6.0", "2025.12.0") void status_set_error(const char *message)
virtual float get_setup_priority() const
priority of setup().
virtual void setup()
Where the component's initialization should happen.
float get_actual_setup_priority() const
bool has_overridden_loop() const
void mark_failed(const LogString *message)
const LogString * get_component_log_str() const
Get the integration where this component was declared as a LogString for logging.
void set_component_source(const LogString *source)
Set where this component was loaded from for some debug messages.
virtual void on_powerdown()
Called after teardown is complete to power down hardware.
ESPDEPRECATED("Use const char* overload instead. Removed in 2026.7.0", "2026.1.0") void defer(const std voi defer)(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call.
const LogString * component_source_
bool set_status_flag_(uint8_t flag)
Helper to set a status LED flag on both this component and the app.
uint8_t get_component_state() const
void status_set_warning(const char *message=nullptr)
bool should_warn_of_blocking(uint32_t blocking_time)
volatile bool pending_enable_loop_
ISR-safe flag for enable_loop_soon_any_context.
virtual bool can_proceed()
virtual void on_safe_shutdown()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual float get_loop_priority() const
priority of loop().
void status_clear_error()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(const std voi set_interval)(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
bool is_in_loop_state() const
Check if this component has completed setup and is in the loop state.
virtual bool teardown()
Called during teardown to allow component to gracefully finish operations.
ESPDEPRECATED("Use const char* overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_defer(const std boo cancel_defer)(const char *name)
Cancel a defer callback using the specified name, name must not be empty.
uint16_t warn_if_blocking_over_
Warn if blocked for this many ms (max 65.5s)
uint8_t component_state_
State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION,...
void status_momentary_warning(const char *name, uint32_t length=5000)
Set warning status flag and automatically clear it after a timeout.
virtual void dump_config()
void enable_loop()
Enable this component's loop.
void set_component_state_(uint8_t state)
Helper to set component state (clears state bits and sets new state)
bool status_has_warning() const
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> float backoff_increase_factor
bool status_has_error() const
void disable_loop()
Disable this component's loop.
virtual void on_shutdown()
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t initial_wait_time
virtual void loop()
This method will be called repeatedly.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t max_attempts
void reset_to_construction_state()
Reset this component back to the construction state to allow setup to run again.
void set_setup_priority(float priority)
ESPDEPRECATED("Use mark_failed(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary " "strings. Will stop working in 2026.6.0", "2025.12.0") void mark_failed(const char *message)
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_interval(const std boo cancel_interval)(const char *name)
Cancel an interval function.
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> && f
void status_clear_warning()
virtual void call_setup()
bool is_idle() const
Check if this component is idle.
This class simplifies creating components that periodically check a state.
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
void call_setup() override
virtual void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
uint32_t update_interval_
~WarnIfComponentBlockingGuard()=default
WarnIfComponentBlockingGuard(Component *component, uint32_t start_time)
const Component * component
constexpr float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
constexpr float AFTER_BLUETOOTH
constexpr float AFTER_WIFI
For components that should be initialized after WiFi is connected.
constexpr float LATE
For components that should be initialized at the very end of the setup process.
constexpr float DATA
For components that import data from directly connected sensors like DHT.
constexpr float PROCESSOR
For components that use data from sensors like displays.
constexpr float BLUETOOTH
constexpr float BUS
For communication buses like i2c/spi.
constexpr float IO
For components that represent GPIO pins like PCF8573.
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Providing packet encoding functions for exchanging data with a remote host.
constexpr uint8_t COMPONENT_STATE_FAILED
constexpr uint8_t COMPONENT_HAS_LOOP
InternalSchedulerID
Type-safe scheduler IDs for core base classes.
constexpr uint8_t STATUS_LED_MASK
constexpr uint8_t COMPONENT_STATE_LOOP
constexpr uint8_t STATUS_LED_WARNING
constexpr uint8_t COMPONENT_STATE_MASK
void log_update_interval(const char *tag, PollingComponent *component)
void clear_setup_priority_overrides()
static void uint32_t blocking_time
constexpr uint16_t WARN_IF_BLOCKING_OVER_MS
constexpr uint8_t COMPONENT_STATE_LOOP_DONE
constexpr uint8_t COMPONENT_STATE_SETUP
constexpr uint8_t COMPONENT_STATE_CONSTRUCTION
constexpr uint8_t STATUS_LED_OK
constexpr uint8_t STATUS_LED_ERROR
constexpr uint32_t SCHEDULER_DONT_RUN