ESPHome 2025.7.1
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"
13
14#ifdef USE_DEVICES
15#include "esphome/core/device.h"
16#endif
17#ifdef USE_AREAS
18#include "esphome/core/area.h"
19#endif
20
21#ifdef USE_SOCKET_SELECT_SUPPORT
22#include <sys/select.h>
23#endif
24
25#ifdef USE_BINARY_SENSOR
27#endif
28#ifdef USE_SENSOR
30#endif
31#ifdef USE_SWITCH
33#endif
34#ifdef USE_BUTTON
36#endif
37#ifdef USE_TEXT_SENSOR
39#endif
40#ifdef USE_FAN
42#endif
43#ifdef USE_CLIMATE
45#endif
46#ifdef USE_LIGHT
48#endif
49#ifdef USE_COVER
51#endif
52#ifdef USE_NUMBER
54#endif
55#ifdef USE_DATETIME_DATE
57#endif
58#ifdef USE_DATETIME_TIME
60#endif
61#ifdef USE_DATETIME_DATETIME
63#endif
64#ifdef USE_TEXT
66#endif
67#ifdef USE_SELECT
69#endif
70#ifdef USE_LOCK
72#endif
73#ifdef USE_VALVE
75#endif
76#ifdef USE_MEDIA_PLAYER
78#endif
79#ifdef USE_ALARM_CONTROL_PANEL
81#endif
82#ifdef USE_EVENT
84#endif
85#ifdef USE_UPDATE
87#endif
88
89namespace esphome {
90
91// Teardown timeout constant (in milliseconds)
92// For reboots, it's more important to shut down quickly than disconnect cleanly
93// since we're not entering deep sleep. The only consequence of not shutting down
94// cleanly is a warning in the log.
95static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
96
98 public:
99 void pre_setup(const std::string &name, const std::string &friendly_name, const char *comment,
100 const char *compilation_time, bool name_add_mac_suffix) {
101 arch_init();
102 this->name_add_mac_suffix_ = name_add_mac_suffix;
103 if (name_add_mac_suffix) {
104 this->name_ = name + "-" + get_mac_address().substr(6);
105 if (friendly_name.empty()) {
106 this->friendly_name_ = "";
107 } else {
108 this->friendly_name_ = friendly_name + " " + get_mac_address().substr(6);
109 }
110 } else {
111 this->name_ = name;
112 this->friendly_name_ = friendly_name;
113 }
114 this->comment_ = comment;
115 this->compilation_time_ = compilation_time;
116 }
117
118#ifdef USE_DEVICES
119 void register_device(Device *device) { this->devices_.push_back(device); }
120#endif
121#ifdef USE_AREAS
122 void register_area(Area *area) { this->areas_.push_back(area); }
123#endif
124
125 void set_current_component(Component *component) { this->current_component_ = component; }
127
128#ifdef USE_BINARY_SENSOR
130 this->binary_sensors_.push_back(binary_sensor);
131 }
132#endif
133
134#ifdef USE_SENSOR
135 void register_sensor(sensor::Sensor *sensor) { this->sensors_.push_back(sensor); }
136#endif
137
138#ifdef USE_SWITCH
139 void register_switch(switch_::Switch *a_switch) { this->switches_.push_back(a_switch); }
140#endif
141
142#ifdef USE_BUTTON
143 void register_button(button::Button *button) { this->buttons_.push_back(button); }
144#endif
145
146#ifdef USE_TEXT_SENSOR
147 void register_text_sensor(text_sensor::TextSensor *sensor) { this->text_sensors_.push_back(sensor); }
148#endif
149
150#ifdef USE_FAN
151 void register_fan(fan::Fan *state) { this->fans_.push_back(state); }
152#endif
153
154#ifdef USE_COVER
155 void register_cover(cover::Cover *cover) { this->covers_.push_back(cover); }
156#endif
157
158#ifdef USE_CLIMATE
159 void register_climate(climate::Climate *climate) { this->climates_.push_back(climate); }
160#endif
161
162#ifdef USE_LIGHT
163 void register_light(light::LightState *light) { this->lights_.push_back(light); }
164#endif
165
166#ifdef USE_NUMBER
167 void register_number(number::Number *number) { this->numbers_.push_back(number); }
168#endif
169
170#ifdef USE_DATETIME_DATE
171 void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
172#endif
173
174#ifdef USE_DATETIME_TIME
175 void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
176#endif
177
178#ifdef USE_DATETIME_DATETIME
179 void register_datetime(datetime::DateTimeEntity *datetime) { this->datetimes_.push_back(datetime); }
180#endif
181
182#ifdef USE_TEXT
183 void register_text(text::Text *text) { this->texts_.push_back(text); }
184#endif
185
186#ifdef USE_SELECT
187 void register_select(select::Select *select) { this->selects_.push_back(select); }
188#endif
189
190#ifdef USE_LOCK
191 void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
192#endif
193
194#ifdef USE_VALVE
195 void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
196#endif
197
198#ifdef USE_MEDIA_PLAYER
199 void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
200#endif
201
202#ifdef USE_ALARM_CONTROL_PANEL
204 this->alarm_control_panels_.push_back(a_alarm_control_panel);
205 }
206#endif
207
208#ifdef USE_EVENT
209 void register_event(event::Event *event) { this->events_.push_back(event); }
210#endif
211
212#ifdef USE_UPDATE
213 void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
214#endif
215
217 void reserve_components(size_t count) { this->components_.reserve(count); }
218
219#ifdef USE_BINARY_SENSOR
220 void reserve_binary_sensor(size_t count) { this->binary_sensors_.reserve(count); }
221#endif
222#ifdef USE_SWITCH
223 void reserve_switch(size_t count) { this->switches_.reserve(count); }
224#endif
225#ifdef USE_BUTTON
226 void reserve_button(size_t count) { this->buttons_.reserve(count); }
227#endif
228#ifdef USE_SENSOR
229 void reserve_sensor(size_t count) { this->sensors_.reserve(count); }
230#endif
231#ifdef USE_TEXT_SENSOR
232 void reserve_text_sensor(size_t count) { this->text_sensors_.reserve(count); }
233#endif
234#ifdef USE_FAN
235 void reserve_fan(size_t count) { this->fans_.reserve(count); }
236#endif
237#ifdef USE_COVER
238 void reserve_cover(size_t count) { this->covers_.reserve(count); }
239#endif
240#ifdef USE_CLIMATE
241 void reserve_climate(size_t count) { this->climates_.reserve(count); }
242#endif
243#ifdef USE_LIGHT
244 void reserve_light(size_t count) { this->lights_.reserve(count); }
245#endif
246#ifdef USE_NUMBER
247 void reserve_number(size_t count) { this->numbers_.reserve(count); }
248#endif
249#ifdef USE_DATETIME_DATE
250 void reserve_date(size_t count) { this->dates_.reserve(count); }
251#endif
252#ifdef USE_DATETIME_TIME
253 void reserve_time(size_t count) { this->times_.reserve(count); }
254#endif
255#ifdef USE_DATETIME_DATETIME
256 void reserve_datetime(size_t count) { this->datetimes_.reserve(count); }
257#endif
258#ifdef USE_SELECT
259 void reserve_select(size_t count) { this->selects_.reserve(count); }
260#endif
261#ifdef USE_TEXT
262 void reserve_text(size_t count) { this->texts_.reserve(count); }
263#endif
264#ifdef USE_LOCK
265 void reserve_lock(size_t count) { this->locks_.reserve(count); }
266#endif
267#ifdef USE_VALVE
268 void reserve_valve(size_t count) { this->valves_.reserve(count); }
269#endif
270#ifdef USE_MEDIA_PLAYER
271 void reserve_media_player(size_t count) { this->media_players_.reserve(count); }
272#endif
273#ifdef USE_ALARM_CONTROL_PANEL
274 void reserve_alarm_control_panel(size_t count) { this->alarm_control_panels_.reserve(count); }
275#endif
276#ifdef USE_EVENT
277 void reserve_event(size_t count) { this->events_.reserve(count); }
278#endif
279#ifdef USE_UPDATE
280 void reserve_update(size_t count) { this->updates_.reserve(count); }
281#endif
282#ifdef USE_AREAS
283 void reserve_area(size_t count) { this->areas_.reserve(count); }
284#endif
285#ifdef USE_DEVICES
286 void reserve_device(size_t count) { this->devices_.reserve(count); }
287#endif
288
290 template<class C> C *register_component(C *c) {
291 static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
292 this->register_component_((Component *) c);
293 return c;
294 }
295
297 void setup();
298
300 void loop();
301
303 const std::string &get_name() const { return this->name_; }
304
306 const std::string &get_friendly_name() const { return this->friendly_name_; }
307
309 const char *get_area() const {
310#ifdef USE_AREAS
311 // If we have areas registered, return the name of the first one (which is the top-level area)
312 if (!this->areas_.empty() && this->areas_[0] != nullptr) {
313 return this->areas_[0]->get_name();
314 }
315#endif
316 return "";
317 }
318
320 std::string get_comment() const { return this->comment_; }
321
323
324 std::string get_compilation_time() const { return this->compilation_time_; }
325
327 inline uint32_t IRAM_ATTR HOT get_loop_component_start_time() const { return this->loop_component_start_time_; }
328
345 void set_loop_interval(uint32_t loop_interval) {
346 this->loop_interval_ = std::min(loop_interval, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()));
347 }
348
349 uint32_t get_loop_interval() const { return static_cast<uint32_t>(this->loop_interval_); }
350
352
353 void feed_wdt(uint32_t time = 0);
354
355 void reboot();
356
357 void safe_reboot();
358
360
361 void run_powerdown_hooks();
362
367 void teardown_components(uint32_t timeout_ms);
368
369 uint8_t get_app_state() const { return this->app_state_; }
370
371// Helper macro for entity getter method declarations - reduces code duplication
372// When USE_DEVICE_ID is enabled in the future, this can be conditionally compiled to add device_id parameter
373#define GET_ENTITY_METHOD(entity_type, entity_name, entities_member) \
374 entity_type *get_##entity_name##_by_key(uint32_t key, bool include_internal = false) { \
375 for (auto *obj : this->entities_member##_) { \
376 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal())) \
377 return obj; \
378 } \
379 return nullptr; \
380 }
381
382#ifdef USE_DEVICES
383 const std::vector<Device *> &get_devices() { return this->devices_; }
384#endif
385#ifdef USE_AREAS
386 const std::vector<Area *> &get_areas() { return this->areas_; }
387#endif
388#ifdef USE_BINARY_SENSOR
389 const std::vector<binary_sensor::BinarySensor *> &get_binary_sensors() { return this->binary_sensors_; }
390 GET_ENTITY_METHOD(binary_sensor::BinarySensor, binary_sensor, binary_sensors)
391#endif
392#ifdef USE_SWITCH
393 const std::vector<switch_::Switch *> &get_switches() { return this->switches_; }
395#endif
396#ifdef USE_BUTTON
397 const std::vector<button::Button *> &get_buttons() { return this->buttons_; }
399#endif
400#ifdef USE_SENSOR
401 const std::vector<sensor::Sensor *> &get_sensors() { return this->sensors_; }
403#endif
404#ifdef USE_TEXT_SENSOR
405 const std::vector<text_sensor::TextSensor *> &get_text_sensors() { return this->text_sensors_; }
406 GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors)
407#endif
408#ifdef USE_FAN
409 const std::vector<fan::Fan *> &get_fans() { return this->fans_; }
411#endif
412#ifdef USE_COVER
413 const std::vector<cover::Cover *> &get_covers() { return this->covers_; }
415#endif
416#ifdef USE_LIGHT
417 const std::vector<light::LightState *> &get_lights() { return this->lights_; }
419#endif
420#ifdef USE_CLIMATE
421 const std::vector<climate::Climate *> &get_climates() { return this->climates_; }
423#endif
424#ifdef USE_NUMBER
425 const std::vector<number::Number *> &get_numbers() { return this->numbers_; }
427#endif
428#ifdef USE_DATETIME_DATE
429 const std::vector<datetime::DateEntity *> &get_dates() { return this->dates_; }
431#endif
432#ifdef USE_DATETIME_TIME
433 const std::vector<datetime::TimeEntity *> &get_times() { return this->times_; }
435#endif
436#ifdef USE_DATETIME_DATETIME
437 const std::vector<datetime::DateTimeEntity *> &get_datetimes() { return this->datetimes_; }
439#endif
440#ifdef USE_TEXT
441 const std::vector<text::Text *> &get_texts() { return this->texts_; }
443#endif
444#ifdef USE_SELECT
445 const std::vector<select::Select *> &get_selects() { return this->selects_; }
447#endif
448#ifdef USE_LOCK
449 const std::vector<lock::Lock *> &get_locks() { return this->locks_; }
451#endif
452#ifdef USE_VALVE
453 const std::vector<valve::Valve *> &get_valves() { return this->valves_; }
455#endif
456#ifdef USE_MEDIA_PLAYER
457 const std::vector<media_player::MediaPlayer *> &get_media_players() { return this->media_players_; }
458 GET_ENTITY_METHOD(media_player::MediaPlayer, media_player, media_players)
459#endif
460
461#ifdef USE_ALARM_CONTROL_PANEL
462 const std::vector<alarm_control_panel::AlarmControlPanel *> &get_alarm_control_panels() {
463 return this->alarm_control_panels_;
464 }
465 GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels)
466#endif
467
468#ifdef USE_EVENT
469 const std::vector<event::Event *> &get_events() { return this->events_; }
471#endif
472
473#ifdef USE_UPDATE
474 const std::vector<update::UpdateEntity *> &get_updates() { return this->updates_; }
476#endif
477
478 Scheduler scheduler;
479
481#ifdef USE_SOCKET_SELECT_SUPPORT
486 bool register_socket_fd(int fd);
487 void unregister_socket_fd(int fd);
490 bool is_socket_ready(int fd) const;
491#endif
492
493 protected:
494 friend Component;
495
496 void register_component_(Component *comp);
497
499
500 // These methods are called by Component::disable_loop() and Component::enable_loop()
501 // Components should not call these directly - use this->disable_loop() or this->enable_loop()
502 // to ensure component state is properly updated along with the loop partition
503 void disable_component_loop_(Component *component);
504 void enable_component_loop_(Component *component);
506 void activate_looping_component_(uint16_t index);
507
509
511 void yield_with_select_(uint32_t delay_ms);
512
513 // === Member variables ordered by size to minimize padding ===
514
515 // Pointer-sized members first
517 const char *comment_{nullptr};
518 const char *compilation_time_{nullptr};
519
520 // size_t members
521 size_t dump_config_at_{SIZE_MAX};
522
523 // Vectors (largest members)
524 std::vector<Component *> components_{};
525
526 // Partitioned vector design for looping components
527 // =================================================
528 // Components are partitioned into [active | inactive] sections:
529 //
530 // looping_components_: [A, B, C, D | E, F]
531 // ^
532 // looping_components_active_end_ (4)
533 //
534 // - Components A,B,C,D are active and will be called in loop()
535 // - Components E,F are inactive (disabled/failed) and won't be called
536 // - No flag checking needed during iteration - just loop 0 to active_end_
537 // - When a component is disabled, it's swapped with the last active component
538 // and active_end_ is decremented
539 // - When a component is enabled, it's swapped with the first inactive component
540 // and active_end_ is incremented
541 // - This eliminates branch mispredictions from flag checking in the hot loop
542 std::vector<Component *> looping_components_{};
543
544#ifdef USE_DEVICES
545 std::vector<Device *> devices_{};
546#endif
547#ifdef USE_AREAS
548 std::vector<Area *> areas_{};
549#endif
550#ifdef USE_BINARY_SENSOR
551 std::vector<binary_sensor::BinarySensor *> binary_sensors_{};
552#endif
553#ifdef USE_SWITCH
554 std::vector<switch_::Switch *> switches_{};
555#endif
556#ifdef USE_BUTTON
557 std::vector<button::Button *> buttons_{};
558#endif
559#ifdef USE_EVENT
560 std::vector<event::Event *> events_{};
561#endif
562#ifdef USE_SENSOR
563 std::vector<sensor::Sensor *> sensors_{};
564#endif
565#ifdef USE_TEXT_SENSOR
566 std::vector<text_sensor::TextSensor *> text_sensors_{};
567#endif
568#ifdef USE_FAN
569 std::vector<fan::Fan *> fans_{};
570#endif
571#ifdef USE_COVER
572 std::vector<cover::Cover *> covers_{};
573#endif
574#ifdef USE_CLIMATE
575 std::vector<climate::Climate *> climates_{};
576#endif
577#ifdef USE_LIGHT
578 std::vector<light::LightState *> lights_{};
579#endif
580#ifdef USE_NUMBER
581 std::vector<number::Number *> numbers_{};
582#endif
583#ifdef USE_DATETIME_DATE
584 std::vector<datetime::DateEntity *> dates_{};
585#endif
586#ifdef USE_DATETIME_TIME
587 std::vector<datetime::TimeEntity *> times_{};
588#endif
589#ifdef USE_DATETIME_DATETIME
590 std::vector<datetime::DateTimeEntity *> datetimes_{};
591#endif
592#ifdef USE_SELECT
593 std::vector<select::Select *> selects_{};
594#endif
595#ifdef USE_TEXT
596 std::vector<text::Text *> texts_{};
597#endif
598#ifdef USE_LOCK
599 std::vector<lock::Lock *> locks_{};
600#endif
601#ifdef USE_VALVE
602 std::vector<valve::Valve *> valves_{};
603#endif
604#ifdef USE_MEDIA_PLAYER
605 std::vector<media_player::MediaPlayer *> media_players_{};
606#endif
607#ifdef USE_ALARM_CONTROL_PANEL
608 std::vector<alarm_control_panel::AlarmControlPanel *> alarm_control_panels_{};
609#endif
610#ifdef USE_UPDATE
611 std::vector<update::UpdateEntity *> updates_{};
612#endif
613
614#ifdef USE_SOCKET_SELECT_SUPPORT
615 std::vector<int> socket_fds_; // Vector of all monitored socket file descriptors
616#endif
617
618 // String members
619 std::string name_;
620 std::string friendly_name_;
621
622 // 4-byte members
623 uint32_t last_loop_{0};
625
626#ifdef USE_SOCKET_SELECT_SUPPORT
627 int max_fd_{-1}; // Highest file descriptor number for select()
628#endif
629
630 // 2-byte members (grouped together for alignment)
631 uint16_t loop_interval_{16}; // Loop interval in ms (max 65535ms = 65.5 seconds)
633 uint16_t current_loop_index_{0}; // For safe reentrant modifications during iteration
634
635 // 1-byte members (grouped together to minimize padding)
636 uint8_t app_state_{0};
638 bool in_loop_{false};
640
641#ifdef USE_SOCKET_SELECT_SUPPORT
642 bool socket_fds_changed_{false}; // Flag to rebuild base_read_fds_ when socket_fds_ changes
643
644 // Variable-sized members at end
645 fd_set base_read_fds_{}; // Cached fd_set rebuilt only when socket_fds_ changes
646 fd_set read_fds_{}; // Working fd_set for select(), copied from base_read_fds_
647#endif
648};
649
651extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
652
653} // namespace esphome
void reserve_datetime(size_t count)
void setup()
Set up all the registered components. Call this at the end of your setup() function.
uint32_t get_loop_interval() const
std::string get_comment() const
Get the comment of this Application set by pre_setup().
void register_fan(fan::Fan *state)
void register_button(button::Button *button)
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
GET_ENTITY_METHOD(datetime::DateEntity, date, dates) const std
void register_light(light::LightState *light)
void register_binary_sensor(binary_sensor::BinarySensor *binary_sensor)
void reserve_number(size_t count)
void pre_setup(const std::string &name, const std::string &friendly_name, const char *comment, const char *compilation_time, bool name_add_mac_suffix)
Definition application.h:99
GET_ENTITY_METHOD(climate::Climate, climate, climates) const std
void reserve_components(size_t count)
Reserve space for components to avoid memory fragmentation.
GET_ENTITY_METHOD(number::Number, number, numbers) const std
uint16_t looping_components_active_end_
void reserve_button(size_t count)
void set_current_component(Component *component)
void reserve_lock(size_t count)
void reserve_cover(size_t count)
Component * get_current_component()
std::vector< text::Text * > texts_
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(button::Button, button, buttons) const std
GET_ENTITY_METHOD(media_player::MediaPlayer, media_player, media_players) const std
void reserve_event(size_t count)
void reserve_text_sensor(size_t count)
std::vector< update::UpdateEntity * > updates_
void register_update(update::UpdateEntity *update)
void register_media_player(media_player::MediaPlayer *media_player)
GET_ENTITY_METHOD(valve::Valve, valve, valves) const std
void reserve_valve(size_t count)
void reserve_alarm_control_panel(size_t count)
GET_ENTITY_METHOD(sensor::Sensor, sensor, sensors) const std
std::vector< media_player::MediaPlayer * > media_players_
std::vector< int > socket_fds_
GET_ENTITY_METHOD(event::Event, event, events) const std
std::vector< event::Event * > events_
void register_number(number::Number *number)
std::vector< sensor::Sensor * > sensors_
void reserve_select(size_t count)
const std::vector< Area * > & get_areas()
GET_ENTITY_METHOD(update::UpdateEntity, update, updates) Scheduler scheduler
std::vector< Component * > components_
void set_loop_interval(uint32_t loop_interval)
Set the target interval with which to run the loop() calls.
void register_climate(climate::Climate *climate)
GET_ENTITY_METHOD(cover::Cover, cover, covers) const std
void reserve_climate(size_t count)
GET_ENTITY_METHOD(switch_::Switch, switch, switches) const std
void register_cover(cover::Cover *cover)
std::vector< text_sensor::TextSensor * > text_sensors_
void reserve_time(size_t count)
void reserve_switch(size_t count)
std::string get_compilation_time() const
void register_area(Area *area)
Component * current_component_
GET_ENTITY_METHOD(binary_sensor::BinarySensor, binary_sensor, binary_sensors) const std
std::vector< datetime::TimeEntity * > times_
std::vector< cover::Cover * > covers_
void register_datetime(datetime::DateTimeEntity *datetime)
std::vector< Device * > devices_
void register_time(datetime::TimeEntity *time)
void enable_component_loop_(Component *component)
uint32_t loop_component_start_time_
void reserve_binary_sensor(size_t count)
std::vector< binary_sensor::BinarySensor * > binary_sensors_
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)
void reserve_fan(size_t count)
GET_ENTITY_METHOD(select::Select, select, selects) const std
std::vector< alarm_control_panel::AlarmControlPanel * > alarm_control_panels_
std::string friendly_name_
void register_switch(switch_::Switch *a_switch)
std::vector< lock::Lock * > locks_
const std::string & get_name() const
Get the name of this Application set by pre_setup().
GET_ENTITY_METHOD(text_sensor::TextSensor, text_sensor, text_sensors) const std
void reserve_sensor(size_t count)
void register_lock(lock::Lock *a_lock)
std::vector< datetime::DateEntity * > dates_
void reserve_media_player(size_t count)
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)
void reserve_light(size_t count)
GET_ENTITY_METHOD(text::Text, text, texts) const std
void register_sensor(sensor::Sensor *sensor)
volatile bool has_pending_enable_loop_requests_
std::vector< climate::Climate * > climates_
GET_ENTITY_METHOD(datetime::DateTimeEntity, datetime, datetimes) const std
void reserve_device(size_t count)
const char * compilation_time_
std::vector< Component * > looping_components_
void reserve_update(size_t count)
const std::vector< Device * > & get_devices()
void register_text_sensor(text_sensor::TextSensor *sensor)
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
uint16_t current_loop_index_
std::vector< switch_::Switch * > switches_
std::vector< Area * > areas_
void reserve_text(size_t count)
std::vector< fan::Fan * > fans_
std::vector< number::Number * > numbers_
GET_ENTITY_METHOD(alarm_control_panel::AlarmControlPanel, alarm_control_panel, alarm_control_panels) const std
GET_ENTITY_METHOD(fan::Fan, fan, fans) const std
void register_select(select::Select *select)
void feed_wdt(uint32_t time=0)
C * register_component(C *c)
Register the component in this Application instance.
std::vector< valve::Valve * > valves_
void loop()
Make a loop iteration. Call this in your loop() function.
GET_ENTITY_METHOD(lock::Lock, lock, locks) const std
void register_text(text::Text *text)
std::vector< button::Button * > buttons_
std::vector< light::LightState * > lights_
void reserve_date(size_t count)
void reserve_area(size_t count)
void register_device(Device *device)
void unregister_socket_fd(int fd)
std::vector< select::Select * > selects_
std::vector< datetime::DateTimeEntity * > datetimes_
GET_ENTITY_METHOD(light::LightState, light, lights) const std
bool register_socket_fd(int fd)
Register/unregister a socket file descriptor to be monitored for read events.
void calculate_looping_components_()
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(datetime::TimeEntity, time, times) const std
void register_component_(Component *comp)
void register_date(datetime::DateEntity *date)
Base class for all binary_sensor-type classes.
Base class for all buttons.
Definition button.h:29
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:168
Base class for all cover devices.
Definition cover.h:111
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:66
Base class for all locks.
Definition lock.h:103
Base-class for all numbers.
Definition number.h:39
Base-class for all selects.
Definition select.h:31
Base-class for all sensors.
Definition sensor.h:62
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:105
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:40
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Definition helpers.cpp:585
Application App
Global storage of Application pointer - only one Application can exist.