|
ESPHome 2026.4.3
|
#include <application.h>
Public Member Functions | |
| void | pre_setup (char *name, size_t name_len, char *friendly_name, size_t friendly_name_len) |
| Pre-setup with MAC suffix: overwrites placeholder in mutable static buffers with actual MAC. | |
| void | pre_setup (const char *name, size_t name_len, const char *friendly_name, size_t friendly_name_len) |
| Pre-setup without MAC suffix: StringRef points directly at const string literals in flash. | |
| void | register_device (Device *device) |
| void | register_area (Area *area) |
| void | set_current_component (Component *component) |
| Component * | get_current_component () |
| void | register_binary_sensor (binary_sensor::BinarySensor *binary_sensor) |
| void | register_sensor (sensor::Sensor *sensor) |
| void | register_switch (switch_::Switch *a_switch) |
| void | register_button (button::Button *button) |
| void | register_text_sensor (text_sensor::TextSensor *sensor) |
| void | register_fan (fan::Fan *state) |
| void | register_cover (cover::Cover *cover) |
| void | register_climate (climate::Climate *climate) |
| void | register_light (light::LightState *light) |
| void | register_number (number::Number *number) |
| void | register_date (datetime::DateEntity *date) |
| void | register_time (datetime::TimeEntity *time) |
| void | register_datetime (datetime::DateTimeEntity *datetime) |
| void | register_text (text::Text *text) |
| void | register_select (select::Select *select) |
| void | register_lock (lock::Lock *a_lock) |
| void | register_valve (valve::Valve *valve) |
| void | register_media_player (media_player::MediaPlayer *media_player) |
| void | register_alarm_control_panel (alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) |
| void | register_water_heater (water_heater::WaterHeater *water_heater) |
| void | register_infrared (infrared::Infrared *infrared) |
| void | register_serial_proxy (serial_proxy::SerialProxy *proxy) |
| void | register_event (event::Event *event) |
| void | register_update (update::UpdateEntity *update) |
| void | setup () |
| Reserve space for components to avoid memory fragmentation. | |
| void ESPHOME_ALWAYS_INLINE | loop () |
| Make a loop iteration. Call this in your loop() function. | |
| const StringRef & | get_name () const |
| Get the name of this Application set by pre_setup(). | |
| const StringRef & | get_friendly_name () const |
| Get the friendly name of this Application set by pre_setup(). | |
| const char * | get_area () const |
| Get the area of this Application set by pre_setup(). | |
| void | get_comment_string (std::span< char, ESPHOME_COMMENT_SIZE_MAX > buffer) |
| Copy the comment string into the provided buffer. | |
| std::string | get_comment () |
| Get the comment of this Application as a string. | |
| bool | is_name_add_mac_suffix_enabled () const |
| uint32_t | get_config_hash () |
| Get the config hash as a 32-bit integer. | |
| uint32_t | get_config_version_hash () |
| Get the config hash extended with ESPHome version. | |
| time_t | get_build_time () |
| Get the build time as a Unix timestamp. | |
| void | get_build_time_string (std::span< char, BUILD_TIME_STR_SIZE > buffer) |
| Copy the build time string into the provided buffer Buffer must be BUILD_TIME_STR_SIZE bytes (compile-time enforced) | |
| ESPDEPRECATED ("Use get_build_time_string() instead. Removed in 2026.7.0", "2026.1.0") std | |
| Get the build time as a string (deprecated, use get_build_time_string() instead) | |
| uint32_t IRAM_ATTR HOT | get_loop_component_start_time () const |
| Get the cached time in milliseconds from when the current component started its loop execution. | |
| void | set_loop_interval (uint32_t loop_interval) |
| Set the target interval with which to run the loop() calls. | |
| uint32_t | get_loop_interval () const |
| void | schedule_dump_config () |
| void | feed_wdt () |
| Feed the task watchdog. | |
| void ESPHOME_ALWAYS_INLINE | feed_wdt_with_time (uint32_t time) |
| Feed the task watchdog, hot entry. | |
| void | reboot () |
| void | safe_reboot () |
| void | run_safe_shutdown_hooks () |
| void | run_powerdown_hooks () |
| void | teardown_components (uint32_t timeout_ms) |
| Teardown all components with a timeout. | |
| uint8_t | get_app_state () const |
| Return the public app state status bits (STATUS_LED_* only). | |
| bool | is_setup_complete () const |
| True once Application::setup() has finished walking all components and finalized the initial status flags. | |
| const auto & | get_devices () |
| const auto & | get_areas () |
| auto & | get_binary_sensors () const |
| GET_ENTITY_METHOD (binary_sensor::BinarySensor, binary_sensor, binary_sensors) auto &get_switches() const | |
| GET_ENTITY_METHOD (switch_::Switch, switch, switches) auto &get_buttons() const | |
| GET_ENTITY_METHOD (button::Button, button, buttons) auto &get_sensors() const | |
| GET_ENTITY_METHOD (sensor::Sensor, sensor, sensors) auto &get_text_sensors() const | |
| GET_ENTITY_METHOD (text_sensor::TextSensor, text_sensor, text_sensors) auto &get_fans() const | |
| GET_ENTITY_METHOD (fan::Fan, fan, fans) auto &get_covers() const | |
| GET_ENTITY_METHOD (cover::Cover, cover, covers) auto &get_lights() const | |
| GET_ENTITY_METHOD (light::LightState, light, lights) auto &get_climates() const | |
| GET_ENTITY_METHOD (climate::Climate, climate, climates) auto &get_numbers() const | |
| GET_ENTITY_METHOD (number::Number, number, numbers) auto &get_dates() const | |
| GET_ENTITY_METHOD (datetime::DateEntity, date, dates) auto &get_times() const | |
| GET_ENTITY_METHOD (datetime::TimeEntity, time, times) auto &get_datetimes() const | |
| GET_ENTITY_METHOD (datetime::DateTimeEntity, datetime, datetimes) auto &get_texts() const | |
| GET_ENTITY_METHOD (text::Text, text, texts) auto &get_selects() const | |
| GET_ENTITY_METHOD (select::Select, select, selects) auto &get_locks() const | |
| GET_ENTITY_METHOD (lock::Lock, lock, locks) auto &get_valves() const | |
| GET_ENTITY_METHOD (valve::Valve, valve, valves) auto &get_media_players() const | |
| GET_ENTITY_METHOD (media_player::MediaPlayer, media_player, media_players) auto &get_alarm_control_panels() const | |
| GET_ENTITY_METHOD (alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels) auto &get_water_heaters() const | |
| GET_ENTITY_METHOD (water_heater::WaterHeater, water_heater, water_heaters) auto &get_infrareds() const | |
| GET_ENTITY_METHOD (infrared::Infrared, infrared, infrareds) auto &get_serial_proxies() const | |
| auto & | get_events () const |
| GET_ENTITY_METHOD (event::Event, event, events) auto &get_updates() const | |
| GET_ENTITY_METHOD (update::UpdateEntity, update, updates) Scheduler scheduler | |
| bool | register_socket (struct lwip_sock *sock) |
| Register/unregister a socket to be monitored for read events. | |
| void | unregister_socket (struct lwip_sock *sock) |
| bool | register_socket_fd (int fd) |
| Fallback select() path: monitors file descriptors. | |
| void | unregister_socket_fd (int fd) |
| void | wake_loop_threadsafe () |
| Wake the main event loop from another thread or callback. | |
Static Public Member Functions | |
| static void IRAM_ATTR | wake_loop_isrsafe (BaseType_t *px) |
| Wake from ISR (ESP32 only). | |
| static void IRAM_ATTR | wake_loop_any_context () |
| Wake from any context (ISR, thread, callback). | |
Static Public Attributes | |
| static constexpr size_t | ESPHOME_COMMENT_SIZE_MAX = 256 |
| Maximum size of the comment buffer (including null terminator) | |
| static constexpr size_t | BUILD_TIME_STR_SIZE = 26 |
| Size of buffer required for build time string (including null terminator) | |
| static constexpr uint32_t | WDT_FEED_INTERVAL_MS = 3 |
| Minimum interval between real arch_feed_wdt() calls. | |
Protected Member Functions | |
| friend | void::setup () |
| friend | void::original_setup () |
| bool | is_socket_ready_ (int fd) const |
| bool | any_component_has_status_flag_ (uint8_t flag) const |
| Walk all registered components looking for any whose component_state_ has the given flag set. | |
| template<typename T > | |
| void | register_component_ (T *comp) |
| Register a component, detecting loop() override at compile time. | |
| void | register_component_impl_ (Component *comp, bool has_loop) |
| void | calculate_looping_components_ () |
| void | add_looping_components_by_state_ (bool match_loop_done) |
| void | disable_component_loop_ (Component *component) |
| void | enable_component_loop_ (Component *component) |
| void | enable_pending_loops_ () |
| void | activate_looping_component_ (uint16_t index) |
| uint32_t ESPHOME_ALWAYS_INLINE | before_loop_tasks_ (uint32_t loop_start_time) |
| void ESPHOME_ALWAYS_INLINE | after_loop_tasks_ () |
| void | __attribute__ ((noinline)) process_dump_config_() |
| Process dump_config output one component per loop iteration. | |
| void | feed_wdt_slow_ (uint32_t time) |
| Slow path for feed_wdt(): actually calls arch_feed_wdt(), updates last_wdt_feed_, and re-dispatches the status LED. | |
| void | yield_with_select_ (uint32_t delay_ms) |
| Perform a delay while also monitoring socket file descriptors for readiness. | |
| void ESPHOME_ALWAYS_INLINE | yield_with_select_ (uint32_t delay_ms) |
| void | setup_wake_loop_threadsafe_ () |
| void | drain_wake_notifications_ () |
Definition at line 148 of file application.h.
|
protected |
Process dump_config output one component per loop iteration.
Extracted from loop() to keep cold startup/reconnect logging out of the hot path. Caller must ensure dump_config_at_ < components_.size().
|
protected |
Definition at line 407 of file application.cpp.
|
protected |
Definition at line 369 of file application.cpp.
|
inlineprotected |
Definition at line 645 of file application.h.
|
protected |
Walk all registered components looking for any whose component_state_ has the given flag set.
Used by Component::status_clear_*_slow_path_() (which is a friend) to decide whether to clear the corresponding bit on this->app_state_ (the app-wide "any component has this status" indicator).
Definition at line 233 of file application.cpp.
|
inlineprotected |
Definition at line 848 of file application.h.
|
inlineprotected |
Definition at line 622 of file application.h.
|
protected |
Definition at line 378 of file application.cpp.
|
inlineprotected |
Definition at line 832 of file application.h.
|
protected |
Definition at line 415 of file application.cpp.
|
protected |
Definition at line 432 of file application.cpp.
|
inline |
Get the build time as a string (deprecated, use get_build_time_string() instead)
Definition at line 354 of file application.h.
| void esphome::Application::feed_wdt | ( | ) |
Feed the task watchdog.
Cold entry — callers without a millis() timestamp in hand. Out of line to keep call sites tiny.
Definition at line 212 of file application.cpp.
|
protected |
Slow path for feed_wdt(): actually calls arch_feed_wdt(), updates last_wdt_feed_, and re-dispatches the status LED.
Out of line so the inline wrapper stays tiny.
Definition at line 221 of file application.cpp.
|
inline |
Feed the task watchdog, hot entry.
Callers that already have a millis() timestamp pay only a load + sub + branch on the common (no-op) path. The actual arch feed + status LED update live in feed_wdt_slow_.
Definition at line 401 of file application.h.
|
inline |
Return the public app state status bits (STATUS_LED_* only).
Internal bookkeeping bits like APP_STATE_SETUP_COMPLETE are masked out so external readers (status_led components, etc.) never see them.
Definition at line 424 of file application.h.
|
inline |
Get the area of this Application set by pre_setup().
Definition at line 311 of file application.h.
|
inline |
Definition at line 457 of file application.h.
|
inline |
Definition at line 460 of file application.h.
| time_t esphome::Application::get_build_time | ( | ) |
Get the build time as a Unix timestamp.
Definition at line 701 of file application.cpp.
| void esphome::Application::get_build_time_string | ( | std::span< char, BUILD_TIME_STR_SIZE > | buffer | ) |
Copy the build time string into the provided buffer Buffer must be BUILD_TIME_STR_SIZE bytes (compile-time enforced)
Definition at line 687 of file application.cpp.
|
inline |
Get the comment of this Application as a string.
Definition at line 328 of file application.h.
| void esphome::Application::get_comment_string | ( | std::span< char, ESPHOME_COMMENT_SIZE_MAX > | buffer | ) |
Copy the comment string into the provided buffer.
Definition at line 692 of file application.cpp.
| uint32_t esphome::Application::get_config_hash | ( | ) |
Get the config hash as a 32-bit integer.
Definition at line 697 of file application.cpp.
| uint32_t esphome::Application::get_config_version_hash | ( | ) |
Get the config hash extended with ESPHome version.
Definition at line 699 of file application.cpp.
|
inline |
Definition at line 191 of file application.h.
|
inline |
Definition at line 445 of file application.h.
|
inline |
Definition at line 534 of file application.h.
|
inline |
Definition at line 461 of file application.h.
|
inline |
Definition at line 469 of file application.h.
|
inline |
Definition at line 493 of file application.h.
|
inline |
Definition at line 485 of file application.h.
|
inline |
Definition at line 501 of file application.h.
|
inline |
Definition at line 509 of file application.h.
|
inline |
Definition at line 505 of file application.h.
|
inline |
Definition at line 553 of file application.h.
|
inline |
Definition at line 481 of file application.h.
|
inline |
Definition at line 544 of file application.h.
|
inline |
Definition at line 489 of file application.h.
|
inline |
Definition at line 521 of file application.h.
|
inline |
Definition at line 529 of file application.h.
|
inline |
Definition at line 497 of file application.h.
|
inline |
Definition at line 517 of file application.h.
|
inline |
Definition at line 473 of file application.h.
|
inline |
Definition at line 465 of file application.h.
|
inline |
Definition at line 513 of file application.h.
|
inline |
Definition at line 477 of file application.h.
| esphome::Application::GET_ENTITY_METHOD | ( | update::UpdateEntity | , |
| update | , | ||
| updates | ) |
|
inline |
Definition at line 525 of file application.h.
|
inline |
Definition at line 539 of file application.h.
|
inline |
Definition at line 552 of file application.h.
|
inline |
Get the friendly name of this Application set by pre_setup().
Definition at line 308 of file application.h.
|
inline |
Get the cached time in milliseconds from when the current component started its loop execution.
Definition at line 362 of file application.h.
|
inline |
Definition at line 384 of file application.h.
|
inline |
Get the name of this Application set by pre_setup().
Definition at line 305 of file application.h.
|
inline |
Definition at line 334 of file application.h.
|
inline |
True once Application::setup() has finished walking all components and finalized the initial status flags.
Before this point, the slow-setup busy-wait may be forcing STATUS_LED_WARNING on, and status_clear_* intentionally skips its walk-and-clear step so the forced bit doesn't get wiped. Stored as a free bit on app_state_ (bit 6) to avoid costing additional RAM.
Definition at line 432 of file application.h.
|
inlineprotected |
Definition at line 605 of file application.h.
|
inline |
Make a loop iteration. Call this in your loop() function.
Definition at line 877 of file application.h.
|
inline |
Pre-setup with MAC suffix: overwrites placeholder in mutable static buffers with actual MAC.
Definition at line 153 of file application.h.
|
inline |
Pre-setup without MAC suffix: StringRef points directly at const string literals in flash.
Definition at line 175 of file application.h.
| void esphome::Application::reboot | ( | ) |
Definition at line 246 of file application.cpp.
|
inline |
Definition at line 268 of file application.h.
|
inline |
Definition at line 187 of file application.h.
|
inline |
Definition at line 194 of file application.h.
|
inline |
Definition at line 208 of file application.h.
|
inline |
Definition at line 224 of file application.h.
|
inlineprotected |
Register a component, detecting loop() override at compile time.
Uses HasLoopOverride<T> which handles ambiguous &T::loop from multiple inheritance.
Definition at line 616 of file application.h.
|
protected |
Definition at line 60 of file application.cpp.
|
inline |
Definition at line 220 of file application.h.
|
inline |
Definition at line 236 of file application.h.
|
inline |
Definition at line 244 of file application.h.
|
inline |
Definition at line 184 of file application.h.
|
inline |
Definition at line 289 of file application.h.
|
inline |
Definition at line 216 of file application.h.
|
inline |
Definition at line 278 of file application.h.
|
inline |
Definition at line 228 of file application.h.
|
inline |
Definition at line 256 of file application.h.
|
inline |
Definition at line 264 of file application.h.
|
inline |
Definition at line 232 of file application.h.
|
inline |
Definition at line 252 of file application.h.
|
inline |
Definition at line 200 of file application.h.
|
inline |
Definition at line 282 of file application.h.
| bool esphome::Application::register_socket | ( | struct lwip_sock * | sock | ) |
Register/unregister a socket to be monitored for read events.
WARNING: These functions are NOT thread-safe. They must only be called from the main loop. Fast select path: hooks netconn callback and registers for monitoring.
Definition at line 485 of file application.cpp.
| bool esphome::Application::register_socket_fd | ( | int | fd | ) |
Fallback select() path: monitors file descriptors.
NOTE: File descriptors >= FD_SETSIZE (typically 10 on ESP) will be rejected with an error.
Definition at line 510 of file application.cpp.
|
inline |
Definition at line 204 of file application.h.
|
inline |
Definition at line 248 of file application.h.
|
inline |
Definition at line 212 of file application.h.
|
inline |
Definition at line 240 of file application.h.
|
inline |
Definition at line 293 of file application.h.
|
inline |
Definition at line 260 of file application.h.
|
inline |
Definition at line 274 of file application.h.
| void esphome::Application::run_powerdown_hooks | ( | ) |
Definition at line 270 of file application.cpp.
| void esphome::Application::run_safe_shutdown_hooks | ( | ) |
Definition at line 261 of file application.cpp.
| void esphome::Application::safe_reboot | ( | ) |
Definition at line 253 of file application.cpp.
|
inline |
Definition at line 386 of file application.h.
|
inline |
Definition at line 190 of file application.h.
|
inline |
Set the target interval with which to run the loop() calls.
If the loop() method takes longer than the target interval, ESPHome won't sleep in loop(), but if the time spent in loop() is small than the target, ESPHome will delay at the end of the App.loop() method.
This is done to conserve power: In most use-cases, high-speed loop() calls are not required and degrade power consumption.
Each component can request a high frequency loop execution by using the HighFrequencyLoopRequester helper in helpers.h
Note: This method is not called by ESPHome core code. It is only used by lambda functions in YAML configurations or by external components.
| loop_interval | The interval in milliseconds to run the core loop at. Defaults to 16 milliseconds. |
Definition at line 380 of file application.h.
| void esphome::Application::setup | ( | ) |
Reserve space for components to avoid memory fragmentation.
Set up all the registered components. Call this at the end of your setup() function.
Definition at line 66 of file application.cpp.
|
protected |
Definition at line 631 of file application.cpp.
| void esphome::Application::teardown_components | ( | uint32_t | timeout_ms | ) |
Teardown all components with a timeout.
| timeout_ms | Maximum time to wait for teardown in milliseconds |
Definition at line 276 of file application.cpp.
| void esphome::Application::unregister_socket | ( | struct lwip_sock * | sock | ) |
Definition at line 494 of file application.cpp.
| void esphome::Application::unregister_socket_fd | ( | int | fd | ) |
Definition at line 530 of file application.cpp.
|
protected |
|
protected |
|
inlinestatic |
Wake from any context (ISR, thread, callback).
Definition at line 588 of file application.h.
|
inlinestatic |
Wake from ISR (ESP32 only).
Definition at line 584 of file application.h.
|
inline |
Wake the main event loop from another thread or callback.
Definition at line 580 of file application.h.
|
inlineprotected |
Perform a delay while also monitoring socket file descriptors for readiness.
Definition at line 561 of file application.cpp.
|
inlineprotected |
|
protected |
Definition at line 805 of file application.h.
|
protected |
Definition at line 722 of file application.h.
|
protected |
Definition at line 744 of file application.h.
|
protected |
Definition at line 734 of file application.h.
|
protected |
Definition at line 747 of file application.h.
|
staticconstexpr |
Size of buffer required for build time string (including null terminator)
Definition at line 337 of file application.h.
|
protected |
Definition at line 753 of file application.h.
|
protected |
Definition at line 771 of file application.h.
|
protected |
Definition at line 591 of file application.h.
|
protected |
Definition at line 738 of file application.h.
|
protected |
Definition at line 768 of file application.h.
|
protected |
Definition at line 673 of file application.h.
|
protected |
Definition at line 719 of file application.h.
|
protected |
Definition at line 780 of file application.h.
|
protected |
Definition at line 786 of file application.h.
|
protected |
Definition at line 741 of file application.h.
|
protected |
Definition at line 716 of file application.h.
|
staticconstexpr |
Maximum size of the comment buffer (including null terminator)
Definition at line 322 of file application.h.
|
protected |
Definition at line 756 of file application.h.
|
protected |
Definition at line 765 of file application.h.
|
protected |
Definition at line 704 of file application.h.
|
protected |
Definition at line 725 of file application.h.
|
protected |
Definition at line 724 of file application.h.
|
protected |
Definition at line 811 of file application.h.
|
protected |
Definition at line 707 of file application.h.
|
protected |
Definition at line 709 of file application.h.
|
protected |
Definition at line 774 of file application.h.
|
protected |
Definition at line 795 of file application.h.
|
protected |
Definition at line 708 of file application.h.
|
protected |
Definition at line 717 of file application.h.
|
protected |
Definition at line 692 of file application.h.
|
protected |
Definition at line 718 of file application.h.
|
protected |
Definition at line 712 of file application.h.
|
protected |
Definition at line 801 of file application.h.
|
protected |
Definition at line 694 of file application.h.
|
protected |
Definition at line 703 of file application.h.
|
protected |
Definition at line 723 of file application.h.
|
protected |
Definition at line 777 of file application.h.
|
protected |
Definition at line 733 of file application.h.
|
protected |
Definition at line 789 of file application.h.
|
protected |
Definition at line 759 of file application.h.
|
protected |
Definition at line 814 of file application.h.
|
protected |
Definition at line 696 of file application.h.
|
protected |
Definition at line 728 of file application.h.
|
protected |
Definition at line 750 of file application.h.
|
protected |
Definition at line 762 of file application.h.
|
protected |
Definition at line 792 of file application.h.
|
protected |
Definition at line 783 of file application.h.
|
protected |
Definition at line 817 of file application.h.
|
protected |
Definition at line 798 of file application.h.
|
protected |
Definition at line 699 of file application.h.
|
protected |
Definition at line 808 of file application.h.
|
staticconstexpr |
Minimum interval between real arch_feed_wdt() calls.
Chosen to keep the rate of HAL pokes low while still being small enough that any plausible watchdog timeout (seconds) has orders of magnitude of safety margin.
Definition at line 391 of file application.h.