24#ifdef USE_RUNTIME_STATS
25namespace runtime_stats {
26class RuntimeStatsCollector;
34namespace setup_priority {
37inline constexpr float POWER = 1200.0f;
39inline constexpr float BUS = 1000.0f;
41inline constexpr float IO = 900.0f;
45inline constexpr float DATA = 600.0f;
50inline constexpr float WIFI = 250.0f;
59inline constexpr float LATE = -100.0f;
73class PollingComponent;
78#define LOG_UPDATE_INTERVAL(this) log_update_interval(TAG, this)
106#ifdef USE_RUNTIME_STATS
152 virtual void setup();
333 friend void ::setup();
334 friend void ::original_setup();
471 void defer(
const char *name, std::function<
void()> &&f);
474 void defer(std::function<
void()> &&f);
497#ifdef USE_RUNTIME_STATS
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.
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)
virtual void on_powerdown()
Called after teardown is complete to power down hardware.
bool set_status_flag_(uint8_t flag)
Helper to set a status LED flag on both this component and the app.
ComponentRuntimeStats runtime_stats_
void status_set_warning()
uint8_t get_component_state() const
void enable_loop_slow_path_()
volatile bool pending_enable_loop_
ISR-safe flag for enable_loop_soon_any_context.
virtual bool can_proceed()
virtual void on_safe_shutdown()
bool cancel_interval(const char *name)
Cancel an interval function.
void status_clear_error()
void set_component_source_(uint8_t index)
Set where this component was loaded from for some debug messages.
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.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
uint8_t component_state_
State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION,...
bool should_warn_of_blocking(uint32_t blocking_time, uint32_t &threshold_ms_out)
bool cancel_timeout(const char *name)
Cancel a timeout function.
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.
const LogString * get_component_log_str() const ESPHOME_ALWAYS_INLINE
Get the integration where this component was declared as a LogString for logging.
uint8_t component_source_index_
Index into component source PROGMEM lookup table (0 = not set)
void status_clear_warning_slow_path_()
void set_component_state_(uint8_t state)
Helper to set component state (clears state bits and sets new state)
bool status_has_warning() const
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
bool status_has_error() const
void status_clear_error_slow_path_()
void disable_loop()
Disable this component's loop.
virtual void on_shutdown()
void set_interval(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a const char* name.
virtual void loop()
This method will be called repeatedly.
void reset_to_construction_state()
Reset this component back to the construction state to allow setup to run again.
uint8_t warn_if_blocking_over_
Warn threshold in centiseconds (max 2550ms)
void set_setup_priority(float priority)
bool cancel_defer(const char *name)
Cancel a defer callback using the specified name, name must not be empty.
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
void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
uint32_t update_interval_
const Component * component
const LogString * message
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 POWER
For power supply components that must be on before buses like i2c can work.
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.
constexpr uint8_t COMPONENT_STATE_FAILED
constexpr uint8_t WARN_IF_BLOCKING_OVER_CS
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 APP_STATE_SETUP_COMPLETE
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()
const LogString * component_source_lookup(uint8_t index)
Lookup component source name by index (1-based).
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
Inline runtime statistics — eliminates std::map lookup on every loop iteration.
static uint64_t global_recorded_us
void record_time(uint32_t duration_us)
uint32_t total_max_time_us
uint32_t period_max_time_us