ESPHome 2025.12.5
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <limits>
5#include <string>
6#include <vector>
9#include "esphome/core/hal.h"
14
15#ifdef USE_DEVICES
16#include "esphome/core/device.h"
17#endif
18#ifdef USE_AREAS
19#include "esphome/core/area.h"
20#endif
21
22#ifdef USE_SOCKET_SELECT_SUPPORT
23#include <sys/select.h>
24#ifdef USE_WAKE_LOOP_THREADSAFE
25#include <lwip/sockets.h>
26#endif
27#endif // USE_SOCKET_SELECT_SUPPORT
28
29#ifdef USE_BINARY_SENSOR
31#endif
32#ifdef USE_SENSOR
34#endif
35#ifdef USE_SWITCH
37#endif
38#ifdef USE_BUTTON
40#endif
41#ifdef USE_TEXT_SENSOR
43#endif
44#ifdef USE_FAN
46#endif
47#ifdef USE_CLIMATE
49#endif
50#ifdef USE_LIGHT
52#endif
53#ifdef USE_COVER
55#endif
56#ifdef USE_NUMBER
58#endif
59#ifdef USE_DATETIME_DATE
61#endif
62#ifdef USE_DATETIME_TIME
64#endif
65#ifdef USE_DATETIME_DATETIME
67#endif
68#ifdef USE_TEXT
70#endif
71#ifdef USE_SELECT
73#endif
74#ifdef USE_LOCK
76#endif
77#ifdef USE_VALVE
79#endif
80#ifdef USE_MEDIA_PLAYER
82#endif
83#ifdef USE_ALARM_CONTROL_PANEL
85#endif
86#ifdef USE_EVENT
88#endif
89#ifdef USE_UPDATE
91#endif
92
93namespace esphome {
94
95// Teardown timeout constant (in milliseconds)
96// For reboots, it's more important to shut down quickly than disconnect cleanly
97// since we're not entering deep sleep. The only consequence of not shutting down
98// cleanly is a warning in the log.
99static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
100
102 public:
103 void pre_setup(const std::string &name, const std::string &friendly_name, const char *comment,
104 const char *compilation_time, bool name_add_mac_suffix) {
105 arch_init();
106 this->name_add_mac_suffix_ = name_add_mac_suffix;
107 if (name_add_mac_suffix) {
108 // MAC address length: 12 hex chars + null terminator
109 constexpr size_t mac_address_len = 13;
110 // MAC address suffix length (last 6 characters of 12-char MAC address string)
111 constexpr size_t mac_address_suffix_len = 6;
112 char mac_addr[mac_address_len];
114 const char *mac_suffix_ptr = mac_addr + mac_address_suffix_len;
115 this->name_ = make_name_with_suffix(name, '-', mac_suffix_ptr, mac_address_suffix_len);
116 if (!friendly_name.empty()) {
117 this->friendly_name_ = make_name_with_suffix(friendly_name, ' ', mac_suffix_ptr, mac_address_suffix_len);
118 }
119 } else {
120 this->name_ = name;
121 this->friendly_name_ = friendly_name;
122 }
123 this->comment_ = comment;
124 this->compilation_time_ = compilation_time;
125 }
126
127#ifdef USE_DEVICES
128 void register_device(Device *device) { this->devices_.push_back(device); }
129#endif
130#ifdef USE_AREAS
131 void register_area(Area *area) { this->areas_.push_back(area); }
132#endif
133
136
137#ifdef USE_BINARY_SENSOR
139 this->binary_sensors_.push_back(binary_sensor);
140 }
141#endif
142
143#ifdef USE_SENSOR
144 void register_sensor(sensor::Sensor *sensor) { this->sensors_.push_back(sensor); }
145#endif
146
147#ifdef USE_SWITCH
148 void register_switch(switch_::Switch *a_switch) { this->switches_.push_back(a_switch); }
149#endif
150
151#ifdef USE_BUTTON
152 void register_button(button::Button *button) { this->buttons_.push_back(button); }
153#endif
154
155#ifdef USE_TEXT_SENSOR
156 void register_text_sensor(text_sensor::TextSensor *sensor) { this->text_sensors_.push_back(sensor); }
157#endif
158
159#ifdef USE_FAN
160 void register_fan(fan::Fan *state) { this->fans_.push_back(state); }
161#endif
162
163#ifdef USE_COVER
164 void register_cover(cover::Cover *cover) { this->covers_.push_back(cover); }
165#endif
166
167#ifdef USE_CLIMATE
168 void register_climate(climate::Climate *climate) { this->climates_.push_back(climate); }
169#endif
170
171#ifdef USE_LIGHT
172 void register_light(light::LightState *light) { this->lights_.push_back(light); }
173#endif
174
175#ifdef USE_NUMBER
176 void register_number(number::Number *number) { this->numbers_.push_back(number); }
177#endif
178
179#ifdef USE_DATETIME_DATE
180 void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
181#endif
182
183#ifdef USE_DATETIME_TIME
184 void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
185#endif
186
187#ifdef USE_DATETIME_DATETIME
188 void register_datetime(datetime::DateTimeEntity *datetime) { this->datetimes_.push_back(datetime); }
189#endif
190
191#ifdef USE_TEXT
192 void register_text(text::Text *text) { this->texts_.push_back(text); }
193#endif
194
195#ifdef USE_SELECT
196 void register_select(select::Select *select) { this->selects_.push_back(select); }
197#endif
198
199#ifdef USE_LOCK
200 void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
201#endif
202
203#ifdef USE_VALVE
204 void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
205#endif
206
207#ifdef USE_MEDIA_PLAYER
208 void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
209#endif
210
211#ifdef USE_ALARM_CONTROL_PANEL
213 this->alarm_control_panels_.push_back(a_alarm_control_panel);
214 }
215#endif
216
217#ifdef USE_EVENT
218 void register_event(event::Event *event) { this->events_.push_back(event); }
219#endif
220
221#ifdef USE_UPDATE
222 void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
223#endif
224
226
228 template<class C> C *register_component(C *c) {
229 static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
230 this->register_component_((Component *) c);
231 return c;
232 }
233
235 void setup();
236
238 void loop();
239
241 const std::string &get_name() const { return this->name_; }
242
244 const std::string &get_friendly_name() const { return this->friendly_name_; }
245
247 const char *get_area() const {
248#ifdef USE_AREAS
249 // If we have areas registered, return the name of the first one (which is the top-level area)
250 if (!this->areas_.empty() && this->areas_[0] != nullptr) {
251 return this->areas_[0]->get_name();
252 }
253#endif
254 return "";
255 }
256
258 std::string get_comment() const { return this->comment_; }
260 StringRef get_comment_ref() const { return StringRef(this->comment_); }
261
263
264 std::string get_compilation_time() const { return this->compilation_time_; }
267
269 inline uint32_t IRAM_ATTR HOT get_loop_component_start_time() const { return this->loop_component_start_time_; }
270
287 void set_loop_interval(uint32_t loop_interval) {
288 this->loop_interval_ = std::min(loop_interval, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()));
289 }
290
291 uint32_t get_loop_interval() const { return static_cast<uint32_t>(this->loop_interval_); }
292
294
295 void feed_wdt(uint32_t time = 0);
296
297 void reboot();
298
299 void safe_reboot();
300
302
303 void run_powerdown_hooks();
304
309 void teardown_components(uint32_t timeout_ms);
310
311 uint8_t get_app_state() const { return this->app_state_; }
312
313// Helper macro for entity getter method declarations
314#ifdef USE_DEVICES
315#define GET_ENTITY_METHOD(entity_type, entity_name, entities_member) \
316 entity_type *get_##entity_name##_by_key(uint32_t key, uint32_t device_id, bool include_internal = false) { \
317 for (auto *obj : this->entities_member##_) { \
318 if (obj->get_object_id_hash() == key && obj->get_device_id() == device_id && \
319 (include_internal || !obj->is_internal())) \
320 return obj; \
321 } \
322 return nullptr; \
323 }
324 const auto &get_devices() { return this->devices_; }
325#else
326#define GET_ENTITY_METHOD(entity_type, entity_name, entities_member) \
327 entity_type *get_##entity_name##_by_key(uint32_t key, bool include_internal = false) { \
328 for (auto *obj : this->entities_member##_) { \
329 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal())) \
330 return obj; \
331 } \
332 return nullptr; \
333 }
334#endif // USE_DEVICES
335#ifdef USE_AREAS
336 const auto &get_areas() { return this->areas_; }
337#endif
338#ifdef USE_BINARY_SENSOR
339 auto &get_binary_sensors() const { return this->binary_sensors_; }
340 GET_ENTITY_METHOD(binary_sensor::BinarySensor, binary_sensor, binary_sensors)
341#endif
342#ifdef USE_SWITCH
343 auto &get_switches() const { return this->switches_; }
345#endif
346#ifdef USE_BUTTON
347 auto &get_buttons() const { return this->buttons_; }
349#endif
350#ifdef USE_SENSOR
351 auto &get_sensors() const { return this->sensors_; }
353#endif
354#ifdef USE_TEXT_SENSOR
355 auto &get_text_sensors() const { return this->text_sensors_; }
356 GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors)
357#endif
358#ifdef USE_FAN
359 auto &get_fans() const { return this->fans_; }
361#endif
362#ifdef USE_COVER
363 auto &get_covers() const { return this->covers_; }
365#endif
366#ifdef USE_LIGHT
367 auto &get_lights() const { return this->lights_; }
369#endif
370#ifdef USE_CLIMATE
371 auto &get_climates() const { return this->climates_; }
373#endif
374#ifdef USE_NUMBER
375 auto &get_numbers() const { return this->numbers_; }
377#endif
378#ifdef USE_DATETIME_DATE
379 auto &get_dates() const { return this->dates_; }
381#endif
382#ifdef USE_DATETIME_TIME
383 auto &get_times() const { return this->times_; }
385#endif
386#ifdef USE_DATETIME_DATETIME
387 auto &get_datetimes() const { return this->datetimes_; }
389#endif
390#ifdef USE_TEXT
391 auto &get_texts() const { return this->texts_; }
393#endif
394#ifdef USE_SELECT
395 auto &get_selects() const { return this->selects_; }
397#endif
398#ifdef USE_LOCK
399 auto &get_locks() const { return this->locks_; }
401#endif
402#ifdef USE_VALVE
403 auto &get_valves() const { return this->valves_; }
405#endif
406#ifdef USE_MEDIA_PLAYER
407 auto &get_media_players() const { return this->media_players_; }
408 GET_ENTITY_METHOD(media_player::MediaPlayer, media_player, media_players)
409#endif
410
411#ifdef USE_ALARM_CONTROL_PANEL
412 auto &get_alarm_control_panels() const { return this->alarm_control_panels_; }
413 GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels)
414#endif
415
416#ifdef USE_EVENT
417 auto &get_events() const { return this->events_; }
419#endif
420
421#ifdef USE_UPDATE
422 auto &get_updates() const { return this->updates_; }
424#endif
425
426 Scheduler scheduler;
427
429#ifdef USE_SOCKET_SELECT_SUPPORT
434 bool register_socket_fd(int fd);
435 void unregister_socket_fd(int fd);
438 bool is_socket_ready(int fd) const;
439
440#ifdef USE_WAKE_LOOP_THREADSAFE
445#endif
446#endif
447
448 protected:
449 friend Component;
450
451 void register_component_(Component *comp);
452
454 void add_looping_components_by_state_(bool match_loop_done);
455
456 // These methods are called by Component::disable_loop() and Component::enable_loop()
457 // Components should not call these directly - use this->disable_loop() or this->enable_loop()
458 // to ensure component state is properly updated along with the loop partition
462 void activate_looping_component_(uint16_t index);
463 void before_loop_tasks_(uint32_t loop_start_time);
464 void after_loop_tasks_();
465
467
469 void yield_with_select_(uint32_t delay_ms);
470
471#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
472 void setup_wake_loop_threadsafe_(); // Create wake notification socket
473 inline void drain_wake_notifications_(); // Read pending wake notifications in main loop (hot path - inlined)
474#endif
475
476 // === Member variables ordered by size to minimize padding ===
477
478 // Pointer-sized members first
480 const char *comment_{nullptr};
481 const char *compilation_time_{nullptr};
482
483 // std::vector (3 pointers each: begin, end, capacity)
484 // Partitioned vector design for looping components
485 // =================================================
486 // Components are partitioned into [active | inactive] sections:
487 //
488 // looping_components_: [A, B, C, D | E, F]
489 // ^
490 // looping_components_active_end_ (4)
491 //
492 // - Components A,B,C,D are active and will be called in loop()
493 // - Components E,F are inactive (disabled/failed) and won't be called
494 // - No flag checking needed during iteration - just loop 0 to active_end_
495 // - When a component is disabled, it's swapped with the last active component
496 // and active_end_ is decremented
497 // - When a component is enabled, it's swapped with the first inactive component
498 // and active_end_ is incremented
499 // - This eliminates branch mispredictions from flag checking in the hot loop
501#ifdef USE_SOCKET_SELECT_SUPPORT
502 std::vector<int> socket_fds_; // Vector of all monitored socket file descriptors
503#ifdef USE_WAKE_LOOP_THREADSAFE
504 int wake_socket_fd_{-1}; // Shared wake notification socket for waking main loop from tasks
505#endif
506#endif
507
508 // std::string members (typically 24-32 bytes each)
509 std::string name_;
510 std::string friendly_name_;
511
512 // size_t members
513 size_t dump_config_at_{SIZE_MAX};
514
515 // 4-byte members
516 uint32_t last_loop_{0};
518
519#ifdef USE_SOCKET_SELECT_SUPPORT
520 int max_fd_{-1}; // Highest file descriptor number for select()
521#endif
522
523 // 2-byte members (grouped together for alignment)
524 uint16_t loop_interval_{16}; // Loop interval in ms (max 65535ms = 65.5 seconds)
525 uint16_t looping_components_active_end_{0}; // Index marking end of active components in looping_components_
526 uint16_t current_loop_index_{0}; // For safe reentrant modifications during iteration
527
528 // 1-byte members (grouped together to minimize padding)
529 uint8_t app_state_{0};
531 bool in_loop_{false};
533
534#ifdef USE_SOCKET_SELECT_SUPPORT
535 bool socket_fds_changed_{false}; // Flag to rebuild base_read_fds_ when socket_fds_ changes
536#endif
537
538#ifdef USE_SOCKET_SELECT_SUPPORT
539 // Variable-sized members
540 fd_set base_read_fds_{}; // Cached fd_set rebuilt only when socket_fds_ changes
541 fd_set read_fds_{}; // Working fd_set for select(), copied from base_read_fds_
542#endif
543
544 // StaticVectors (largest members - contain actual array data inline)
546
547#ifdef USE_DEVICES
549#endif
550#ifdef USE_AREAS
552#endif
553#ifdef USE_BINARY_SENSOR
555#endif
556#ifdef USE_SWITCH
558#endif
559#ifdef USE_BUTTON
561#endif
562#ifdef USE_EVENT
564#endif
565#ifdef USE_SENSOR
567#endif
568#ifdef USE_TEXT_SENSOR
570#endif
571#ifdef USE_FAN
573#endif
574#ifdef USE_COVER
576#endif
577#ifdef USE_CLIMATE
579#endif
580#ifdef USE_LIGHT
582#endif
583#ifdef USE_NUMBER
585#endif
586#ifdef USE_DATETIME_DATE
588#endif
589#ifdef USE_DATETIME_TIME
591#endif
592#ifdef USE_DATETIME_DATETIME
594#endif
595#ifdef USE_SELECT
597#endif
598#ifdef USE_TEXT
600#endif
601#ifdef USE_LOCK
603#endif
604#ifdef USE_VALVE
606#endif
607#ifdef USE_MEDIA_PLAYER
609#endif
610#ifdef USE_ALARM_CONTROL_PANEL
613#endif
614#ifdef USE_UPDATE
616#endif
617};
618
620extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
621
622#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
623// Inline implementations for hot-path functions
624// drain_wake_notifications_() is called on every loop iteration
625
626// Small buffer for draining wake notification bytes (1 byte sent per wake)
627// Size allows draining multiple notifications per recvfrom() without wasting stack
628static constexpr size_t WAKE_NOTIFY_DRAIN_BUFFER_SIZE = 16;
629
631 // Called from main loop to drain any pending wake notifications
632 // Must check is_socket_ready() to avoid blocking on empty socket
633 if (this->wake_socket_fd_ >= 0 && this->is_socket_ready(this->wake_socket_fd_)) {
634 char buffer[WAKE_NOTIFY_DRAIN_BUFFER_SIZE];
635 // Drain all pending notifications with non-blocking reads
636 // Multiple wake events may have triggered multiple writes, so drain until EWOULDBLOCK
637 // We control both ends of this loopback socket (always write 1 byte per wake),
638 // so no error checking needed - any errors indicate catastrophic system failure
639 while (lwip_recvfrom(this->wake_socket_fd_, buffer, sizeof(buffer), 0, nullptr, nullptr) > 0) {
640 // Just draining, no action needed - wake has already occurred
641 }
642 }
643}
644#endif // defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
645
646} // 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_
std::string get_comment() const
Get the comment of this Application set by pre_setup().
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)
void pre_setup(const std::string &name, const std::string &friendly_name, const char *comment, const char *compilation_time, bool name_add_mac_suffix)
uint16_t looping_components_active_end_
void set_current_component(Component *component)
Component * get_current_component()
StaticVector< binary_sensor::BinarySensor *, ESPHOME_ENTITY_BINARY_SENSOR_COUNT > binary_sensors_
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
void register_update(update::UpdateEntity *update)
StaticVector< Area *, ESPHOME_AREA_COUNT > areas_
void register_media_player(media_player::MediaPlayer *media_player)
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_
void register_climate(climate::Climate *climate)
StaticVector< datetime::DateEntity *, ESPHOME_ENTITY_DATE_COUNT > dates_
void register_cover(cover::Cover *cover)
StaticVector< media_player::MediaPlayer *, ESPHOME_ENTITY_MEDIA_PLAYER_COUNT > media_players_
GET_ENTITY_METHOD(text::Text, text, texts) auto &get_selects() const
std::string get_compilation_time() const
StaticVector< update::UpdateEntity *, ESPHOME_ENTITY_UPDATE_COUNT > updates_
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_()
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_
GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors) auto &get_fans() const
void disable_component_loop_(Component *component)
const char * comment_
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)
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_
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_
const char * compilation_time_
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)
uint16_t current_loop_index_
StaticVector< button::Button *, ESPHOME_ENTITY_BUTTON_COUNT > buttons_
StringRef get_comment_ref() const
Get the comment as StringRef (avoids allocation)
GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels) auto &get_events() const
StringRef get_compilation_time_ref() const
Get the compilation time as StringRef (for API usage)
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
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
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:184
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:132
StringRef is a reference to a string owned by something else.
Definition string_ref.h:22
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:177
Base class for all cover devices.
Definition cover.h:112
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:30
Base-class for all sensors.
Definition sensor.h:43
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
void arch_init()
Definition core.cpp:42
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:663
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:241