ESPHome 2026.1.0
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <ctime>
5#include <limits>
6#include <span>
7#include <string>
8#include <vector>
12#include "esphome/core/hal.h"
19
20#ifdef USE_DEVICES
21#include "esphome/core/device.h"
22#endif
23#ifdef USE_AREAS
24#include "esphome/core/area.h"
25#endif
26
27#ifdef USE_SOCKET_SELECT_SUPPORT
28#include <sys/select.h>
29#ifdef USE_WAKE_LOOP_THREADSAFE
30#include <lwip/sockets.h>
31#endif
32#endif // USE_SOCKET_SELECT_SUPPORT
33
34#ifdef USE_BINARY_SENSOR
36#endif
37#ifdef USE_SENSOR
39#endif
40#ifdef USE_SWITCH
42#endif
43#ifdef USE_BUTTON
45#endif
46#ifdef USE_TEXT_SENSOR
48#endif
49#ifdef USE_FAN
51#endif
52#ifdef USE_CLIMATE
54#endif
55#ifdef USE_LIGHT
57#endif
58#ifdef USE_COVER
60#endif
61#ifdef USE_NUMBER
63#endif
64#ifdef USE_DATETIME_DATE
66#endif
67#ifdef USE_DATETIME_TIME
69#endif
70#ifdef USE_DATETIME_DATETIME
72#endif
73#ifdef USE_TEXT
75#endif
76#ifdef USE_SELECT
78#endif
79#ifdef USE_LOCK
81#endif
82#ifdef USE_VALVE
84#endif
85#ifdef USE_MEDIA_PLAYER
87#endif
88#ifdef USE_ALARM_CONTROL_PANEL
90#endif
91#ifdef USE_WATER_HEATER
93#endif
94#ifdef USE_INFRARED
96#endif
97#ifdef USE_EVENT
99#endif
100#ifdef USE_UPDATE
102#endif
103
104namespace esphome {
105
106// Teardown timeout constant (in milliseconds)
107// For reboots, it's more important to shut down quickly than disconnect cleanly
108// since we're not entering deep sleep. The only consequence of not shutting down
109// cleanly is a warning in the log.
110static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
111
113 public:
114 void pre_setup(const std::string &name, const std::string &friendly_name, bool name_add_mac_suffix) {
115 arch_init();
116 this->name_add_mac_suffix_ = name_add_mac_suffix;
117 if (name_add_mac_suffix) {
118 // MAC address length: 12 hex chars + null terminator
119 constexpr size_t mac_address_len = 13;
120 // MAC address suffix length (last 6 characters of 12-char MAC address string)
121 constexpr size_t mac_address_suffix_len = 6;
122 char mac_addr[mac_address_len];
124 const char *mac_suffix_ptr = mac_addr + mac_address_suffix_len;
125 this->name_ = make_name_with_suffix(name, '-', mac_suffix_ptr, mac_address_suffix_len);
126 if (!friendly_name.empty()) {
127 this->friendly_name_ = make_name_with_suffix(friendly_name, ' ', mac_suffix_ptr, mac_address_suffix_len);
128 }
129 } else {
130 this->name_ = name;
131 this->friendly_name_ = friendly_name;
132 }
133 }
134
135#ifdef USE_DEVICES
136 void register_device(Device *device) { this->devices_.push_back(device); }
137#endif
138#ifdef USE_AREAS
139 void register_area(Area *area) { this->areas_.push_back(area); }
140#endif
141
144
145#ifdef USE_BINARY_SENSOR
147 this->binary_sensors_.push_back(binary_sensor);
148 }
149#endif
150
151#ifdef USE_SENSOR
152 void register_sensor(sensor::Sensor *sensor) { this->sensors_.push_back(sensor); }
153#endif
154
155#ifdef USE_SWITCH
156 void register_switch(switch_::Switch *a_switch) { this->switches_.push_back(a_switch); }
157#endif
158
159#ifdef USE_BUTTON
160 void register_button(button::Button *button) { this->buttons_.push_back(button); }
161#endif
162
163#ifdef USE_TEXT_SENSOR
164 void register_text_sensor(text_sensor::TextSensor *sensor) { this->text_sensors_.push_back(sensor); }
165#endif
166
167#ifdef USE_FAN
168 void register_fan(fan::Fan *state) { this->fans_.push_back(state); }
169#endif
170
171#ifdef USE_COVER
172 void register_cover(cover::Cover *cover) { this->covers_.push_back(cover); }
173#endif
174
175#ifdef USE_CLIMATE
176 void register_climate(climate::Climate *climate) { this->climates_.push_back(climate); }
177#endif
178
179#ifdef USE_LIGHT
180 void register_light(light::LightState *light) { this->lights_.push_back(light); }
181#endif
182
183#ifdef USE_NUMBER
184 void register_number(number::Number *number) { this->numbers_.push_back(number); }
185#endif
186
187#ifdef USE_DATETIME_DATE
188 void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
189#endif
190
191#ifdef USE_DATETIME_TIME
192 void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
193#endif
194
195#ifdef USE_DATETIME_DATETIME
196 void register_datetime(datetime::DateTimeEntity *datetime) { this->datetimes_.push_back(datetime); }
197#endif
198
199#ifdef USE_TEXT
200 void register_text(text::Text *text) { this->texts_.push_back(text); }
201#endif
202
203#ifdef USE_SELECT
204 void register_select(select::Select *select) { this->selects_.push_back(select); }
205#endif
206
207#ifdef USE_LOCK
208 void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
209#endif
210
211#ifdef USE_VALVE
212 void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
213#endif
214
215#ifdef USE_MEDIA_PLAYER
216 void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
217#endif
218
219#ifdef USE_ALARM_CONTROL_PANEL
221 this->alarm_control_panels_.push_back(a_alarm_control_panel);
222 }
223#endif
224
225#ifdef USE_WATER_HEATER
226 void register_water_heater(water_heater::WaterHeater *water_heater) { this->water_heaters_.push_back(water_heater); }
227#endif
228
229#ifdef USE_INFRARED
230 void register_infrared(infrared::Infrared *infrared) { this->infrareds_.push_back(infrared); }
231#endif
232
233#ifdef USE_EVENT
234 void register_event(event::Event *event) { this->events_.push_back(event); }
235#endif
236
237#ifdef USE_UPDATE
238 void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
239#endif
240
242
244 template<class C> C *register_component(C *c) {
245 static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
246 this->register_component_((Component *) c);
247 return c;
248 }
249
251 void setup();
252
254 void loop();
255
257 const std::string &get_name() const { return this->name_; }
258
260 const std::string &get_friendly_name() const { return this->friendly_name_; }
261
263 const char *get_area() const {
264#ifdef USE_AREAS
265 // If we have areas registered, return the name of the first one (which is the top-level area)
266 if (!this->areas_.empty() && this->areas_[0] != nullptr) {
267 return this->areas_[0]->get_name();
268 }
269#endif
270 return "";
271 }
272
275 void get_comment_string(std::span<char, ESPHOME_COMMENT_SIZE> buffer) {
276 ESPHOME_strncpy_P(buffer.data(), ESPHOME_COMMENT_STR, buffer.size());
277 buffer[buffer.size() - 1] = '\0';
278 }
279
281 std::string get_comment() {
282 char buffer[ESPHOME_COMMENT_SIZE];
283 this->get_comment_string(buffer);
284 return std::string(buffer);
285 }
286
288
290 static constexpr size_t BUILD_TIME_STR_SIZE = 26;
291
293 constexpr uint32_t get_config_hash() { return ESPHOME_CONFIG_HASH; }
294
296 constexpr uint32_t get_config_version_hash() { return fnv1a_hash_extend(ESPHOME_CONFIG_HASH, ESPHOME_VERSION); }
297
299 constexpr time_t get_build_time() { return ESPHOME_BUILD_TIME; }
300
303 void get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> buffer);
304
306 // Remove before 2026.7.0
307 ESPDEPRECATED("Use get_build_time_string() instead. Removed in 2026.7.0", "2026.1.0")
308 std::string get_compilation_time() {
309 char buf[BUILD_TIME_STR_SIZE];
310 this->get_build_time_string(buf);
311 return std::string(buf);
312 }
313
315 inline uint32_t IRAM_ATTR HOT get_loop_component_start_time() const { return this->loop_component_start_time_; }
316
333 void set_loop_interval(uint32_t loop_interval) {
334 this->loop_interval_ = std::min(loop_interval, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()));
335 }
336
337 uint32_t get_loop_interval() const { return static_cast<uint32_t>(this->loop_interval_); }
338
340
341 void feed_wdt(uint32_t time = 0);
342
343 void reboot();
344
345 void safe_reboot();
346
348
349 void run_powerdown_hooks();
350
355 void teardown_components(uint32_t timeout_ms);
356
357 uint8_t get_app_state() const { return this->app_state_; }
358
359// Helper macro for entity getter method declarations
360#ifdef USE_DEVICES
361#define GET_ENTITY_METHOD(entity_type, entity_name, entities_member) \
362 entity_type *get_##entity_name##_by_key(uint32_t key, uint32_t device_id, bool include_internal = false) { \
363 for (auto *obj : this->entities_member##_) { \
364 if (obj->get_object_id_hash() == key && obj->get_device_id() == device_id && \
365 (include_internal || !obj->is_internal())) \
366 return obj; \
367 } \
368 return nullptr; \
369 }
370 const auto &get_devices() { return this->devices_; }
371#else
372#define GET_ENTITY_METHOD(entity_type, entity_name, entities_member) \
373 entity_type *get_##entity_name##_by_key(uint32_t key, bool include_internal = false) { \
374 for (auto *obj : this->entities_member##_) { \
375 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal())) \
376 return obj; \
377 } \
378 return nullptr; \
379 }
380#endif // USE_DEVICES
381#ifdef USE_AREAS
382 const auto &get_areas() { return this->areas_; }
383#endif
384#ifdef USE_BINARY_SENSOR
385 auto &get_binary_sensors() const { return this->binary_sensors_; }
386 GET_ENTITY_METHOD(binary_sensor::BinarySensor, binary_sensor, binary_sensors)
387#endif
388#ifdef USE_SWITCH
389 auto &get_switches() const { return this->switches_; }
391#endif
392#ifdef USE_BUTTON
393 auto &get_buttons() const { return this->buttons_; }
395#endif
396#ifdef USE_SENSOR
397 auto &get_sensors() const { return this->sensors_; }
399#endif
400#ifdef USE_TEXT_SENSOR
401 auto &get_text_sensors() const { return this->text_sensors_; }
402 GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors)
403#endif
404#ifdef USE_FAN
405 auto &get_fans() const { return this->fans_; }
407#endif
408#ifdef USE_COVER
409 auto &get_covers() const { return this->covers_; }
411#endif
412#ifdef USE_LIGHT
413 auto &get_lights() const { return this->lights_; }
415#endif
416#ifdef USE_CLIMATE
417 auto &get_climates() const { return this->climates_; }
419#endif
420#ifdef USE_NUMBER
421 auto &get_numbers() const { return this->numbers_; }
423#endif
424#ifdef USE_DATETIME_DATE
425 auto &get_dates() const { return this->dates_; }
427#endif
428#ifdef USE_DATETIME_TIME
429 auto &get_times() const { return this->times_; }
431#endif
432#ifdef USE_DATETIME_DATETIME
433 auto &get_datetimes() const { return this->datetimes_; }
435#endif
436#ifdef USE_TEXT
437 auto &get_texts() const { return this->texts_; }
439#endif
440#ifdef USE_SELECT
441 auto &get_selects() const { return this->selects_; }
443#endif
444#ifdef USE_LOCK
445 auto &get_locks() const { return this->locks_; }
447#endif
448#ifdef USE_VALVE
449 auto &get_valves() const { return this->valves_; }
451#endif
452#ifdef USE_MEDIA_PLAYER
453 auto &get_media_players() const { return this->media_players_; }
454 GET_ENTITY_METHOD(media_player::MediaPlayer, media_player, media_players)
455#endif
456
457#ifdef USE_ALARM_CONTROL_PANEL
458 auto &get_alarm_control_panels() const { return this->alarm_control_panels_; }
459 GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels)
460#endif
461
462#ifdef USE_WATER_HEATER
463 auto &get_water_heaters() const { return this->water_heaters_; }
464 GET_ENTITY_METHOD(water_heater::WaterHeater, water_heater, water_heaters)
465#endif
466
467#ifdef USE_INFRARED
468 auto &get_infrareds() const { return this->infrareds_; }
470#endif
471
472#ifdef USE_EVENT
473 auto &get_events() const { return this->events_; }
475#endif
476
477#ifdef USE_UPDATE
478 auto &get_updates() const { return this->updates_; }
480#endif
481
482 Scheduler scheduler;
483
485#ifdef USE_SOCKET_SELECT_SUPPORT
490 bool register_socket_fd(int fd);
491 void unregister_socket_fd(int fd);
494 bool is_socket_ready(int fd) const;
495
496#ifdef USE_WAKE_LOOP_THREADSAFE
501#endif
502#endif
503
504 protected:
505 friend Component;
506
507 void register_component_(Component *comp);
508
510 void add_looping_components_by_state_(bool match_loop_done);
511
512 // These methods are called by Component::disable_loop() and Component::enable_loop()
513 // Components should not call these directly - use this->disable_loop() or this->enable_loop()
514 // to ensure component state is properly updated along with the loop partition
518 void activate_looping_component_(uint16_t index);
519 void before_loop_tasks_(uint32_t loop_start_time);
520 void after_loop_tasks_();
521
523
525 void yield_with_select_(uint32_t delay_ms);
526
527#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
528 void setup_wake_loop_threadsafe_(); // Create wake notification socket
529 inline void drain_wake_notifications_(); // Read pending wake notifications in main loop (hot path - inlined)
530#endif
531
532 // === Member variables ordered by size to minimize padding ===
533
534 // Pointer-sized members first
536
537 // std::vector (3 pointers each: begin, end, capacity)
538 // Partitioned vector design for looping components
539 // =================================================
540 // Components are partitioned into [active | inactive] sections:
541 //
542 // looping_components_: [A, B, C, D | E, F]
543 // ^
544 // looping_components_active_end_ (4)
545 //
546 // - Components A,B,C,D are active and will be called in loop()
547 // - Components E,F are inactive (disabled/failed) and won't be called
548 // - No flag checking needed during iteration - just loop 0 to active_end_
549 // - When a component is disabled, it's swapped with the last active component
550 // and active_end_ is decremented
551 // - When a component is enabled, it's swapped with the first inactive component
552 // and active_end_ is incremented
553 // - This eliminates branch mispredictions from flag checking in the hot loop
555#ifdef USE_SOCKET_SELECT_SUPPORT
556 std::vector<int> socket_fds_; // Vector of all monitored socket file descriptors
557#ifdef USE_WAKE_LOOP_THREADSAFE
558 int wake_socket_fd_{-1}; // Shared wake notification socket for waking main loop from tasks
559#endif
560#endif
561
562 // std::string members (typically 24-32 bytes each)
563 std::string name_;
564 std::string friendly_name_;
565
566 // size_t members
567 size_t dump_config_at_{SIZE_MAX};
568
569 // 4-byte members
570 uint32_t last_loop_{0};
572
573#ifdef USE_SOCKET_SELECT_SUPPORT
574 int max_fd_{-1}; // Highest file descriptor number for select()
575#endif
576
577 // 2-byte members (grouped together for alignment)
578 uint16_t loop_interval_{16}; // Loop interval in ms (max 65535ms = 65.5 seconds)
579 uint16_t looping_components_active_end_{0}; // Index marking end of active components in looping_components_
580 uint16_t current_loop_index_{0}; // For safe reentrant modifications during iteration
581
582 // 1-byte members (grouped together to minimize padding)
583 uint8_t app_state_{0};
585 bool in_loop_{false};
587
588#ifdef USE_SOCKET_SELECT_SUPPORT
589 bool socket_fds_changed_{false}; // Flag to rebuild base_read_fds_ when socket_fds_ changes
590#endif
591
592#ifdef USE_SOCKET_SELECT_SUPPORT
593 // Variable-sized members
594 fd_set base_read_fds_{}; // Cached fd_set rebuilt only when socket_fds_ changes
595 fd_set read_fds_{}; // Working fd_set for select(), copied from base_read_fds_
596#endif
597
598 // StaticVectors (largest members - contain actual array data inline)
600
601#ifdef USE_DEVICES
603#endif
604#ifdef USE_AREAS
606#endif
607#ifdef USE_BINARY_SENSOR
609#endif
610#ifdef USE_SWITCH
612#endif
613#ifdef USE_BUTTON
615#endif
616#ifdef USE_EVENT
618#endif
619#ifdef USE_SENSOR
621#endif
622#ifdef USE_TEXT_SENSOR
624#endif
625#ifdef USE_FAN
627#endif
628#ifdef USE_COVER
630#endif
631#ifdef USE_CLIMATE
633#endif
634#ifdef USE_LIGHT
636#endif
637#ifdef USE_NUMBER
639#endif
640#ifdef USE_DATETIME_DATE
642#endif
643#ifdef USE_DATETIME_TIME
645#endif
646#ifdef USE_DATETIME_DATETIME
648#endif
649#ifdef USE_SELECT
651#endif
652#ifdef USE_TEXT
654#endif
655#ifdef USE_LOCK
657#endif
658#ifdef USE_VALVE
660#endif
661#ifdef USE_MEDIA_PLAYER
663#endif
664#ifdef USE_ALARM_CONTROL_PANEL
667#endif
668#ifdef USE_WATER_HEATER
670#endif
671#ifdef USE_INFRARED
673#endif
674#ifdef USE_UPDATE
676#endif
677};
678
680extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
681
682#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
683// Inline implementations for hot-path functions
684// drain_wake_notifications_() is called on every loop iteration
685
686// Small buffer for draining wake notification bytes (1 byte sent per wake)
687// Size allows draining multiple notifications per recvfrom() without wasting stack
688static constexpr size_t WAKE_NOTIFY_DRAIN_BUFFER_SIZE = 16;
689
691 // Called from main loop to drain any pending wake notifications
692 // Must check is_socket_ready() to avoid blocking on empty socket
693 if (this->wake_socket_fd_ >= 0 && this->is_socket_ready(this->wake_socket_fd_)) {
694 char buffer[WAKE_NOTIFY_DRAIN_BUFFER_SIZE];
695 // Drain all pending notifications with non-blocking reads
696 // Multiple wake events may have triggered multiple writes, so drain until EWOULDBLOCK
697 // We control both ends of this loopback socket (always write 1 byte per wake),
698 // so no error checking needed - any errors indicate catastrophic system failure
699 while (lwip_recvfrom(this->wake_socket_fd_, buffer, sizeof(buffer), 0, nullptr, nullptr) > 0) {
700 // Just draining, no action needed - wake has already occurred
701 }
702 }
703}
704#endif // defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
705
706} // namespace esphome
StaticVector< switch_::Switch *, ESPHOME_ENTITY_SWITCH_COUNT > switches_
StaticVector< light::LightState *, ESPHOME_ENTITY_LIGHT_COUNT > lights_
void setup()
Set up all the registered components. Call this at the end of your setup() function.
uint32_t get_loop_interval() const
StaticVector< valve::Valve *, ESPHOME_ENTITY_VALVE_COUNT > valves_
void register_fan(fan::Fan *state)
void wake_loop_threadsafe()
Wake the main event loop from a FreeRTOS task Thread-safe, can be called from task context to immedia...
void register_button(button::Button *button)
GET_ENTITY_METHOD(select::Select, select, selects) auto &get_locks() const
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
StaticVector< datetime::TimeEntity *, ESPHOME_ENTITY_TIME_COUNT > times_
GET_ENTITY_METHOD(fan::Fan, fan, fans) auto &get_covers() const
void register_light(light::LightState *light)
const auto & get_areas()
void register_binary_sensor(binary_sensor::BinarySensor *binary_sensor)
uint16_t looping_components_active_end_
GET_ENTITY_METHOD(infrared::Infrared, infrared, infrareds) auto &get_events() const
void set_current_component(Component *component)
Component * get_current_component()
StaticVector< binary_sensor::BinarySensor *, ESPHOME_ENTITY_BINARY_SENSOR_COUNT > binary_sensors_
void register_infrared(infrared::Infrared *infrared)
bool is_socket_ready(int fd) const
Check if there's data available on a socket without blocking This function is thread-safe for reading...
void register_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel)
GET_ENTITY_METHOD(datetime::TimeEntity, time, times) auto &get_datetimes() const
StaticVector< select::Select *, ESPHOME_ENTITY_SELECT_COUNT > selects_
GET_ENTITY_METHOD(climate::Climate, climate, climates) auto &get_numbers() const
static constexpr size_t BUILD_TIME_STR_SIZE
Size of buffer required for build time string (including null terminator)
void register_update(update::UpdateEntity *update)
StaticVector< Area *, ESPHOME_AREA_COUNT > areas_
void register_media_player(media_player::MediaPlayer *media_player)
std::string get_comment()
Get the comment of this Application as a string.
GET_ENTITY_METHOD(valve::Valve, valve, valves) auto &get_media_players() const
StaticVector< fan::Fan *, ESPHOME_ENTITY_FAN_COUNT > fans_
std::vector< int > socket_fds_
void register_number(number::Number *number)
GET_ENTITY_METHOD(update::UpdateEntity, update, updates) Scheduler scheduler
void set_loop_interval(uint32_t loop_interval)
Set the target interval with which to run the loop() calls.
StaticVector< Component *, ESPHOME_COMPONENT_COUNT > components_
GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels) auto &get_water_heaters() const
void register_climate(climate::Climate *climate)
void pre_setup(const std::string &name, const std::string &friendly_name, bool name_add_mac_suffix)
StaticVector< datetime::DateEntity *, ESPHOME_ENTITY_DATE_COUNT > dates_
void register_cover(cover::Cover *cover)
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...
StaticVector< media_player::MediaPlayer *, ESPHOME_ENTITY_MEDIA_PLAYER_COUNT > media_players_
GET_ENTITY_METHOD(text::Text, text, texts) auto &get_selects() const
GET_ENTITY_METHOD(water_heater::WaterHeater, water_heater, water_heaters) auto &get_infrareds() const
StaticVector< update::UpdateEntity *, ESPHOME_ENTITY_UPDATE_COUNT > updates_
void register_water_heater(water_heater::WaterHeater *water_heater)
void register_area(Area *area)
Component * current_component_
GET_ENTITY_METHOD(datetime::DateEntity, date, dates) auto &get_times() const
void register_datetime(datetime::DateTimeEntity *datetime)
GET_ENTITY_METHOD(light::LightState, light, lights) auto &get_climates() const
void drain_wake_notifications_()
StaticVector< infrared::Infrared *, ESPHOME_ENTITY_INFRARED_COUNT > infrareds_
void register_time(datetime::TimeEntity *time)
void enable_component_loop_(Component *component)
uint32_t loop_component_start_time_
GET_ENTITY_METHOD(media_player::MediaPlayer, media_player, media_players) auto &get_alarm_control_panels() const
StaticVector< climate::Climate *, ESPHOME_ENTITY_CLIMATE_COUNT > climates_
constexpr uint32_t get_config_hash()
Get the config hash as a 32-bit integer.
GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors) auto &get_fans() const
void disable_component_loop_(Component *component)
const char * get_area() const
Get the area of this Application set by pre_setup().
bool is_name_add_mac_suffix_enabled() const
void activate_looping_component_(uint16_t index)
const auto & get_devices()
StaticVector< cover::Cover *, ESPHOME_ENTITY_COVER_COUNT > covers_
StaticVector< lock::Lock *, ESPHOME_ENTITY_LOCK_COUNT > locks_
std::string friendly_name_
void register_switch(switch_::Switch *a_switch)
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)
const std::string & get_name() const
Get the name of this Application set by pre_setup().
void register_lock(lock::Lock *a_lock)
StaticVector< event::Event *, ESPHOME_ENTITY_EVENT_COUNT > events_
void teardown_components(uint32_t timeout_ms)
Teardown all components with a timeout.
void register_event(event::Event *event)
void register_valve(valve::Valve *valve)
FixedVector< Component * > looping_components_
void add_looping_components_by_state_(bool match_loop_done)
void register_sensor(sensor::Sensor *sensor)
StaticVector< alarm_control_panel::AlarmControlPanel *, ESPHOME_ENTITY_ALARM_CONTROL_PANEL_COUNT > alarm_control_panels_
void get_comment_string(std::span< char, ESPHOME_COMMENT_SIZE > buffer)
Copy the comment string into the provided buffer Buffer must be ESPHOME_COMMENT_SIZE bytes (compile-t...
volatile bool has_pending_enable_loop_requests_
GET_ENTITY_METHOD(datetime::DateTimeEntity, datetime, datetimes) auto &get_texts() const
GET_ENTITY_METHOD(sensor::Sensor, sensor, sensors) auto &get_text_sensors() const
StaticVector< text_sensor::TextSensor *, ESPHOME_ENTITY_TEXT_SENSOR_COUNT > text_sensors_
StaticVector< datetime::DateTimeEntity *, ESPHOME_ENTITY_DATETIME_COUNT > datetimes_
GET_ENTITY_METHOD(switch_::Switch, switch, switches) auto &get_buttons() const
GET_ENTITY_METHOD(binary_sensor::BinarySensor, binary_sensor, binary_sensors) auto &get_switches() const
void register_text_sensor(text_sensor::TextSensor *sensor)
constexpr uint32_t get_config_version_hash()
Get the config hash extended with ESPHome version.
uint16_t current_loop_index_
StaticVector< button::Button *, ESPHOME_ENTITY_BUTTON_COUNT > buttons_
StaticVector< text::Text *, ESPHOME_ENTITY_TEXT_COUNT > texts_
void register_select(select::Select *select)
void feed_wdt(uint32_t time=0)
C * register_component(C *c)
Reserve space for components to avoid memory fragmentation.
void before_loop_tasks_(uint32_t loop_start_time)
void loop()
Make a loop iteration. Call this in your loop() function.
void register_text(text::Text *text)
void register_device(Device *device)
void unregister_socket_fd(int fd)
GET_ENTITY_METHOD(event::Event, event, events) auto &get_updates() const
StaticVector< water_heater::WaterHeater *, ESPHOME_ENTITY_WATER_HEATER_COUNT > water_heaters_
GET_ENTITY_METHOD(cover::Cover, cover, covers) auto &get_lights() const
bool register_socket_fd(int fd)
Register/unregister a socket file descriptor to be monitored for read events.
StaticVector< Device *, ESPHOME_DEVICE_COUNT > devices_
StaticVector< number::Number *, ESPHOME_ENTITY_NUMBER_COUNT > numbers_
void calculate_looping_components_()
auto & get_binary_sensors() const
constexpr time_t get_build_time()
Get the build time as a Unix timestamp.
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 yield_with_select_(uint32_t delay_ms)
Perform a delay while also monitoring socket file descriptors for readiness.
uint8_t get_app_state() const
GET_ENTITY_METHOD(number::Number, number, numbers) auto &get_dates() const
GET_ENTITY_METHOD(lock::Lock, lock, locks) auto &get_valves() const
StaticVector< sensor::Sensor *, ESPHOME_ENTITY_SENSOR_COUNT > sensors_
GET_ENTITY_METHOD(button::Button, button, buttons) auto &get_sensors() const
void register_component_(Component *comp)
void register_date(datetime::DateEntity *date)
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:188
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:132
Base class for all binary_sensor-type classes.
Base class for all buttons.
Definition button.h:25
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:182
Base class for all cover devices.
Definition cover.h:112
Infrared - Base class for infrared remote control implementations.
Definition infrared.h:85
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:91
Base class for all locks.
Definition lock.h:111
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:31
Base-class for all sensors.
Definition sensor.h:42
Base class for all switches.
Definition switch.h:39
Base-class for all text inputs.
Definition text.h:24
Base class for all valve devices.
Definition valve.h:106
const Component * component
Definition component.cpp:37
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr uint32_t fnv1a_hash_extend(uint32_t hash, const char *str)
Extend a FNV-1a hash with additional string data.
Definition helpers.h:424
void arch_init()
Definition core.cpp:37
void get_mac_address_into_buffer(std::span< char, MAC_ADDRESS_BUFFER_SIZE > buf)
Get the device MAC address into the given buffer, in lowercase hex notation.
Definition helpers.cpp:731
Application App
Global storage of Application pointer - only one Application can exist.
std::string make_name_with_suffix(const char *name, size_t name_len, char sep, const char *suffix_ptr, size_t suffix_len)
Optimized string concatenation: name + separator + suffix (const char* overload) Uses a fixed stack b...
Definition helpers.cpp:262