ESPHome 2025.6.2
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
7#include "esphome/core/hal.h"
11
12#ifdef USE_SOCKET_SELECT_SUPPORT
13#include <sys/select.h>
14#endif
15
16#ifdef USE_BINARY_SENSOR
18#endif
19#ifdef USE_SENSOR
21#endif
22#ifdef USE_SWITCH
24#endif
25#ifdef USE_BUTTON
27#endif
28#ifdef USE_TEXT_SENSOR
30#endif
31#ifdef USE_FAN
33#endif
34#ifdef USE_CLIMATE
36#endif
37#ifdef USE_LIGHT
39#endif
40#ifdef USE_COVER
42#endif
43#ifdef USE_NUMBER
45#endif
46#ifdef USE_DATETIME_DATE
48#endif
49#ifdef USE_DATETIME_TIME
51#endif
52#ifdef USE_DATETIME_DATETIME
54#endif
55#ifdef USE_TEXT
57#endif
58#ifdef USE_SELECT
60#endif
61#ifdef USE_LOCK
63#endif
64#ifdef USE_VALVE
66#endif
67#ifdef USE_MEDIA_PLAYER
69#endif
70#ifdef USE_ALARM_CONTROL_PANEL
72#endif
73#ifdef USE_EVENT
75#endif
76#ifdef USE_UPDATE
78#endif
79
80namespace esphome {
81
82// Teardown timeout constant (in milliseconds)
83// For reboots, it's more important to shut down quickly than disconnect cleanly
84// since we're not entering deep sleep. The only consequence of not shutting down
85// cleanly is a warning in the log.
86static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000; // 1 second for quick reboot
87
89 public:
90 void pre_setup(const std::string &name, const std::string &friendly_name, const char *area, const char *comment,
91 const char *compilation_time, bool name_add_mac_suffix) {
92 arch_init();
93 this->name_add_mac_suffix_ = name_add_mac_suffix;
94 if (name_add_mac_suffix) {
95 this->name_ = name + "-" + get_mac_address().substr(6);
96 if (friendly_name.empty()) {
97 this->friendly_name_ = "";
98 } else {
99 this->friendly_name_ = friendly_name + " " + get_mac_address().substr(6);
100 }
101 } else {
102 this->name_ = name;
103 this->friendly_name_ = friendly_name;
104 }
105 this->area_ = area;
106 this->comment_ = comment;
107 this->compilation_time_ = compilation_time;
108 }
109
110 void set_current_component(Component *component) { this->current_component_ = component; }
112
113#ifdef USE_BINARY_SENSOR
115 this->binary_sensors_.push_back(binary_sensor);
116 }
117#endif
118
119#ifdef USE_SENSOR
120 void register_sensor(sensor::Sensor *sensor) { this->sensors_.push_back(sensor); }
121#endif
122
123#ifdef USE_SWITCH
124 void register_switch(switch_::Switch *a_switch) { this->switches_.push_back(a_switch); }
125#endif
126
127#ifdef USE_BUTTON
128 void register_button(button::Button *button) { this->buttons_.push_back(button); }
129#endif
130
131#ifdef USE_TEXT_SENSOR
132 void register_text_sensor(text_sensor::TextSensor *sensor) { this->text_sensors_.push_back(sensor); }
133#endif
134
135#ifdef USE_FAN
136 void register_fan(fan::Fan *state) { this->fans_.push_back(state); }
137#endif
138
139#ifdef USE_COVER
140 void register_cover(cover::Cover *cover) { this->covers_.push_back(cover); }
141#endif
142
143#ifdef USE_CLIMATE
144 void register_climate(climate::Climate *climate) { this->climates_.push_back(climate); }
145#endif
146
147#ifdef USE_LIGHT
148 void register_light(light::LightState *light) { this->lights_.push_back(light); }
149#endif
150
151#ifdef USE_NUMBER
152 void register_number(number::Number *number) { this->numbers_.push_back(number); }
153#endif
154
155#ifdef USE_DATETIME_DATE
156 void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
157#endif
158
159#ifdef USE_DATETIME_TIME
160 void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
161#endif
162
163#ifdef USE_DATETIME_DATETIME
164 void register_datetime(datetime::DateTimeEntity *datetime) { this->datetimes_.push_back(datetime); }
165#endif
166
167#ifdef USE_TEXT
168 void register_text(text::Text *text) { this->texts_.push_back(text); }
169#endif
170
171#ifdef USE_SELECT
172 void register_select(select::Select *select) { this->selects_.push_back(select); }
173#endif
174
175#ifdef USE_LOCK
176 void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
177#endif
178
179#ifdef USE_VALVE
180 void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
181#endif
182
183#ifdef USE_MEDIA_PLAYER
184 void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
185#endif
186
187#ifdef USE_ALARM_CONTROL_PANEL
189 this->alarm_control_panels_.push_back(a_alarm_control_panel);
190 }
191#endif
192
193#ifdef USE_EVENT
194 void register_event(event::Event *event) { this->events_.push_back(event); }
195#endif
196
197#ifdef USE_UPDATE
198 void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
199#endif
200
202 void reserve_components(size_t count) { this->components_.reserve(count); }
203
204#ifdef USE_BINARY_SENSOR
205 void reserve_binary_sensor(size_t count) { this->binary_sensors_.reserve(count); }
206#endif
207#ifdef USE_SWITCH
208 void reserve_switch(size_t count) { this->switches_.reserve(count); }
209#endif
210#ifdef USE_BUTTON
211 void reserve_button(size_t count) { this->buttons_.reserve(count); }
212#endif
213#ifdef USE_SENSOR
214 void reserve_sensor(size_t count) { this->sensors_.reserve(count); }
215#endif
216#ifdef USE_TEXT_SENSOR
217 void reserve_text_sensor(size_t count) { this->text_sensors_.reserve(count); }
218#endif
219#ifdef USE_FAN
220 void reserve_fan(size_t count) { this->fans_.reserve(count); }
221#endif
222#ifdef USE_COVER
223 void reserve_cover(size_t count) { this->covers_.reserve(count); }
224#endif
225#ifdef USE_CLIMATE
226 void reserve_climate(size_t count) { this->climates_.reserve(count); }
227#endif
228#ifdef USE_LIGHT
229 void reserve_light(size_t count) { this->lights_.reserve(count); }
230#endif
231#ifdef USE_NUMBER
232 void reserve_number(size_t count) { this->numbers_.reserve(count); }
233#endif
234#ifdef USE_DATETIME_DATE
235 void reserve_date(size_t count) { this->dates_.reserve(count); }
236#endif
237#ifdef USE_DATETIME_TIME
238 void reserve_time(size_t count) { this->times_.reserve(count); }
239#endif
240#ifdef USE_DATETIME_DATETIME
241 void reserve_datetime(size_t count) { this->datetimes_.reserve(count); }
242#endif
243#ifdef USE_SELECT
244 void reserve_select(size_t count) { this->selects_.reserve(count); }
245#endif
246#ifdef USE_TEXT
247 void reserve_text(size_t count) { this->texts_.reserve(count); }
248#endif
249#ifdef USE_LOCK
250 void reserve_lock(size_t count) { this->locks_.reserve(count); }
251#endif
252#ifdef USE_VALVE
253 void reserve_valve(size_t count) { this->valves_.reserve(count); }
254#endif
255#ifdef USE_MEDIA_PLAYER
256 void reserve_media_player(size_t count) { this->media_players_.reserve(count); }
257#endif
258#ifdef USE_ALARM_CONTROL_PANEL
259 void reserve_alarm_control_panel(size_t count) { this->alarm_control_panels_.reserve(count); }
260#endif
261#ifdef USE_EVENT
262 void reserve_event(size_t count) { this->events_.reserve(count); }
263#endif
264#ifdef USE_UPDATE
265 void reserve_update(size_t count) { this->updates_.reserve(count); }
266#endif
267
269 template<class C> C *register_component(C *c) {
270 static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
271 this->register_component_((Component *) c);
272 return c;
273 }
274
276 void setup();
277
279 void loop();
280
282 const std::string &get_name() const { return this->name_; }
283
285 const std::string &get_friendly_name() const { return this->friendly_name_; }
286
288 std::string get_area() const { return this->area_ == nullptr ? "" : this->area_; }
289
291 std::string get_comment() const { return this->comment_; }
292
294
295 std::string get_compilation_time() const { return this->compilation_time_; }
296
298 inline uint32_t IRAM_ATTR HOT get_loop_component_start_time() const { return this->loop_component_start_time_; }
299
313 void set_loop_interval(uint32_t loop_interval) { this->loop_interval_ = loop_interval; }
314
315 uint32_t get_loop_interval() const { return this->loop_interval_; }
316
318
319 void feed_wdt(uint32_t time = 0);
320
321 void reboot();
322
323 void safe_reboot();
324
326
327 void run_powerdown_hooks();
328
333 void teardown_components(uint32_t timeout_ms);
334
335 uint8_t get_app_state() const { return this->app_state_; }
336
337#ifdef USE_BINARY_SENSOR
338 const std::vector<binary_sensor::BinarySensor *> &get_binary_sensors() { return this->binary_sensors_; }
339 binary_sensor::BinarySensor *get_binary_sensor_by_key(uint32_t key, bool include_internal = false) {
340 for (auto *obj : this->binary_sensors_) {
341 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
342 return obj;
343 }
344 return nullptr;
345 }
346#endif
347#ifdef USE_SWITCH
348 const std::vector<switch_::Switch *> &get_switches() { return this->switches_; }
349 switch_::Switch *get_switch_by_key(uint32_t key, bool include_internal = false) {
350 for (auto *obj : this->switches_) {
351 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
352 return obj;
353 }
354 return nullptr;
355 }
356#endif
357#ifdef USE_BUTTON
358 const std::vector<button::Button *> &get_buttons() { return this->buttons_; }
359 button::Button *get_button_by_key(uint32_t key, bool include_internal = false) {
360 for (auto *obj : this->buttons_) {
361 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
362 return obj;
363 }
364 return nullptr;
365 }
366#endif
367#ifdef USE_SENSOR
368 const std::vector<sensor::Sensor *> &get_sensors() { return this->sensors_; }
369 sensor::Sensor *get_sensor_by_key(uint32_t key, bool include_internal = false) {
370 for (auto *obj : this->sensors_) {
371 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
372 return obj;
373 }
374 return nullptr;
375 }
376#endif
377#ifdef USE_TEXT_SENSOR
378 const std::vector<text_sensor::TextSensor *> &get_text_sensors() { return this->text_sensors_; }
379 text_sensor::TextSensor *get_text_sensor_by_key(uint32_t key, bool include_internal = false) {
380 for (auto *obj : this->text_sensors_) {
381 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
382 return obj;
383 }
384 return nullptr;
385 }
386#endif
387#ifdef USE_FAN
388 const std::vector<fan::Fan *> &get_fans() { return this->fans_; }
389 fan::Fan *get_fan_by_key(uint32_t key, bool include_internal = false) {
390 for (auto *obj : this->fans_) {
391 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
392 return obj;
393 }
394 return nullptr;
395 }
396#endif
397#ifdef USE_COVER
398 const std::vector<cover::Cover *> &get_covers() { return this->covers_; }
399 cover::Cover *get_cover_by_key(uint32_t key, bool include_internal = false) {
400 for (auto *obj : this->covers_) {
401 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
402 return obj;
403 }
404 return nullptr;
405 }
406#endif
407#ifdef USE_LIGHT
408 const std::vector<light::LightState *> &get_lights() { return this->lights_; }
409 light::LightState *get_light_by_key(uint32_t key, bool include_internal = false) {
410 for (auto *obj : this->lights_) {
411 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
412 return obj;
413 }
414 return nullptr;
415 }
416#endif
417#ifdef USE_CLIMATE
418 const std::vector<climate::Climate *> &get_climates() { return this->climates_; }
419 climate::Climate *get_climate_by_key(uint32_t key, bool include_internal = false) {
420 for (auto *obj : this->climates_) {
421 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
422 return obj;
423 }
424 return nullptr;
425 }
426#endif
427#ifdef USE_NUMBER
428 const std::vector<number::Number *> &get_numbers() { return this->numbers_; }
429 number::Number *get_number_by_key(uint32_t key, bool include_internal = false) {
430 for (auto *obj : this->numbers_) {
431 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
432 return obj;
433 }
434 return nullptr;
435 }
436#endif
437#ifdef USE_DATETIME_DATE
438 const std::vector<datetime::DateEntity *> &get_dates() { return this->dates_; }
439 datetime::DateEntity *get_date_by_key(uint32_t key, bool include_internal = false) {
440 for (auto *obj : this->dates_) {
441 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
442 return obj;
443 }
444 return nullptr;
445 }
446#endif
447#ifdef USE_DATETIME_TIME
448 const std::vector<datetime::TimeEntity *> &get_times() { return this->times_; }
449 datetime::TimeEntity *get_time_by_key(uint32_t key, bool include_internal = false) {
450 for (auto *obj : this->times_) {
451 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
452 return obj;
453 }
454 return nullptr;
455 }
456#endif
457#ifdef USE_DATETIME_DATETIME
458 const std::vector<datetime::DateTimeEntity *> &get_datetimes() { return this->datetimes_; }
459 datetime::DateTimeEntity *get_datetime_by_key(uint32_t key, bool include_internal = false) {
460 for (auto *obj : this->datetimes_) {
461 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
462 return obj;
463 }
464 return nullptr;
465 }
466#endif
467#ifdef USE_TEXT
468 const std::vector<text::Text *> &get_texts() { return this->texts_; }
469 text::Text *get_text_by_key(uint32_t key, bool include_internal = false) {
470 for (auto *obj : this->texts_) {
471 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
472 return obj;
473 }
474 return nullptr;
475 }
476#endif
477#ifdef USE_SELECT
478 const std::vector<select::Select *> &get_selects() { return this->selects_; }
479 select::Select *get_select_by_key(uint32_t key, bool include_internal = false) {
480 for (auto *obj : this->selects_) {
481 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
482 return obj;
483 }
484 return nullptr;
485 }
486#endif
487#ifdef USE_LOCK
488 const std::vector<lock::Lock *> &get_locks() { return this->locks_; }
489 lock::Lock *get_lock_by_key(uint32_t key, bool include_internal = false) {
490 for (auto *obj : this->locks_) {
491 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
492 return obj;
493 }
494 return nullptr;
495 }
496#endif
497#ifdef USE_VALVE
498 const std::vector<valve::Valve *> &get_valves() { return this->valves_; }
499 valve::Valve *get_valve_by_key(uint32_t key, bool include_internal = false) {
500 for (auto *obj : this->valves_) {
501 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
502 return obj;
503 }
504 return nullptr;
505 }
506#endif
507#ifdef USE_MEDIA_PLAYER
508 const std::vector<media_player::MediaPlayer *> &get_media_players() { return this->media_players_; }
509 media_player::MediaPlayer *get_media_player_by_key(uint32_t key, bool include_internal = false) {
510 for (auto *obj : this->media_players_) {
511 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
512 return obj;
513 }
514 return nullptr;
515 }
516#endif
517
518#ifdef USE_ALARM_CONTROL_PANEL
519 const std::vector<alarm_control_panel::AlarmControlPanel *> &get_alarm_control_panels() {
520 return this->alarm_control_panels_;
521 }
522 alarm_control_panel::AlarmControlPanel *get_alarm_control_panel_by_key(uint32_t key, bool include_internal = false) {
523 for (auto *obj : this->alarm_control_panels_) {
524 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
525 return obj;
526 }
527 return nullptr;
528 }
529#endif
530
531#ifdef USE_EVENT
532 const std::vector<event::Event *> &get_events() { return this->events_; }
533 event::Event *get_event_by_key(uint32_t key, bool include_internal = false) {
534 for (auto *obj : this->events_) {
535 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
536 return obj;
537 }
538 return nullptr;
539 }
540#endif
541
542#ifdef USE_UPDATE
543 const std::vector<update::UpdateEntity *> &get_updates() { return this->updates_; }
544 update::UpdateEntity *get_update_by_key(uint32_t key, bool include_internal = false) {
545 for (auto *obj : this->updates_) {
546 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
547 return obj;
548 }
549 return nullptr;
550 }
551#endif
552
554
556#ifdef USE_SOCKET_SELECT_SUPPORT
561 bool register_socket_fd(int fd);
562 void unregister_socket_fd(int fd);
565 bool is_socket_ready(int fd) const;
566#endif
567
568 protected:
569 friend Component;
570
571 void register_component_(Component *comp);
572
574
576
578 void yield_with_select_(uint32_t delay_ms);
579
580 std::vector<Component *> components_{};
581 std::vector<Component *> looping_components_{};
582
583#ifdef USE_BINARY_SENSOR
584 std::vector<binary_sensor::BinarySensor *> binary_sensors_{};
585#endif
586#ifdef USE_SWITCH
587 std::vector<switch_::Switch *> switches_{};
588#endif
589#ifdef USE_BUTTON
590 std::vector<button::Button *> buttons_{};
591#endif
592#ifdef USE_EVENT
593 std::vector<event::Event *> events_{};
594#endif
595#ifdef USE_SENSOR
596 std::vector<sensor::Sensor *> sensors_{};
597#endif
598#ifdef USE_TEXT_SENSOR
599 std::vector<text_sensor::TextSensor *> text_sensors_{};
600#endif
601#ifdef USE_FAN
602 std::vector<fan::Fan *> fans_{};
603#endif
604#ifdef USE_COVER
605 std::vector<cover::Cover *> covers_{};
606#endif
607#ifdef USE_CLIMATE
608 std::vector<climate::Climate *> climates_{};
609#endif
610#ifdef USE_LIGHT
611 std::vector<light::LightState *> lights_{};
612#endif
613#ifdef USE_NUMBER
614 std::vector<number::Number *> numbers_{};
615#endif
616#ifdef USE_DATETIME_DATE
617 std::vector<datetime::DateEntity *> dates_{};
618#endif
619#ifdef USE_DATETIME_TIME
620 std::vector<datetime::TimeEntity *> times_{};
621#endif
622#ifdef USE_DATETIME_DATETIME
623 std::vector<datetime::DateTimeEntity *> datetimes_{};
624#endif
625#ifdef USE_SELECT
626 std::vector<select::Select *> selects_{};
627#endif
628#ifdef USE_TEXT
629 std::vector<text::Text *> texts_{};
630#endif
631#ifdef USE_LOCK
632 std::vector<lock::Lock *> locks_{};
633#endif
634#ifdef USE_VALVE
635 std::vector<valve::Valve *> valves_{};
636#endif
637#ifdef USE_MEDIA_PLAYER
638 std::vector<media_player::MediaPlayer *> media_players_{};
639#endif
640#ifdef USE_ALARM_CONTROL_PANEL
641 std::vector<alarm_control_panel::AlarmControlPanel *> alarm_control_panels_{};
642#endif
643#ifdef USE_UPDATE
644 std::vector<update::UpdateEntity *> updates_{};
645#endif
646
647 std::string name_;
648 std::string friendly_name_;
649 const char *area_{nullptr};
650 const char *comment_{nullptr};
651 const char *compilation_time_{nullptr};
653 uint32_t last_loop_{0};
654 uint32_t loop_interval_{16};
655 size_t dump_config_at_{SIZE_MAX};
656 uint8_t app_state_{0};
659
660#ifdef USE_SOCKET_SELECT_SUPPORT
661 // Socket select management
662 std::vector<int> socket_fds_; // Vector of all monitored socket file descriptors
663 bool socket_fds_changed_{false}; // Flag to rebuild base_read_fds_ when socket_fds_ changes
664 int max_fd_{-1}; // Highest file descriptor number for select()
665 fd_set base_read_fds_{}; // Cached fd_set rebuilt only when socket_fds_ changes
666 fd_set read_fds_{}; // Working fd_set for select(), copied from base_read_fds_
667#endif
668};
669
671extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
672
673} // 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)
datetime::DateEntity * get_date_by_key(uint32_t key, bool include_internal=false)
alarm_control_panel::AlarmControlPanel * get_alarm_control_panel_by_key(uint32_t key, bool include_internal=false)
void register_button(button::Button *button)
binary_sensor::BinarySensor * get_binary_sensor_by_key(uint32_t key, bool include_internal=false)
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
const std::vector< button::Button * > & get_buttons()
void register_light(light::LightState *light)
void register_binary_sensor(binary_sensor::BinarySensor *binary_sensor)
const std::vector< datetime::TimeEntity * > & get_times()
void reserve_number(size_t count)
void reserve_components(size_t count)
Reserve space for components to avoid memory fragmentation.
const std::vector< valve::Valve * > & get_valves()
text::Text * get_text_by_key(uint32_t key, bool include_internal=false)
button::Button * get_button_by_key(uint32_t key, bool include_internal=false)
const std::vector< fan::Fan * > & get_fans()
void reserve_button(size_t count)
void set_current_component(Component *component)
const std::vector< switch_::Switch * > & get_switches()
std::string get_area() const
Get the area of this Application set by pre_setup().
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)
fan::Fan * get_fan_by_key(uint32_t key, bool include_internal=false)
sensor::Sensor * get_sensor_by_key(uint32_t key, bool include_internal=false)
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)
void reserve_valve(size_t count)
void reserve_alarm_control_panel(size_t count)
std::vector< media_player::MediaPlayer * > media_players_
std::vector< int > socket_fds_
std::vector< event::Event * > events_
void register_number(number::Number *number)
std::vector< sensor::Sensor * > sensors_
void reserve_select(size_t count)
std::vector< Component * > components_
const std::vector< sensor::Sensor * > & get_sensors()
void set_loop_interval(uint32_t loop_interval)
Set the target interval with which to run the loop() calls.
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
void register_climate(climate::Climate *climate)
void reserve_climate(size_t count)
void register_cover(cover::Cover *cover)
std::vector< text_sensor::TextSensor * > text_sensors_
const std::vector< lock::Lock * > & get_locks()
void reserve_time(size_t count)
const std::vector< datetime::DateTimeEntity * > & get_datetimes()
void reserve_switch(size_t count)
std::string get_compilation_time() const
const std::vector< select::Select * > & get_selects()
const std::vector< text::Text * > & get_texts()
Component * current_component_
const std::vector< climate::Climate * > & get_climates()
const std::vector< light::LightState * > & get_lights()
light::LightState * get_light_by_key(uint32_t key, bool include_internal=false)
std::vector< datetime::TimeEntity * > times_
std::vector< cover::Cover * > covers_
void register_datetime(datetime::DateTimeEntity *datetime)
media_player::MediaPlayer * get_media_player_by_key(uint32_t key, bool include_internal=false)
void register_time(datetime::TimeEntity *time)
const std::vector< update::UpdateEntity * > & get_updates()
uint32_t loop_component_start_time_
climate::Climate * get_climate_by_key(uint32_t key, bool include_internal=false)
void reserve_binary_sensor(size_t count)
std::vector< binary_sensor::BinarySensor * > binary_sensors_
const char * comment_
bool is_name_add_mac_suffix_enabled() const
void reserve_fan(size_t count)
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().
void reserve_sensor(size_t count)
void register_lock(lock::Lock *a_lock)
event::Event * get_event_by_key(uint32_t key, bool include_internal=false)
std::vector< datetime::DateEntity * > dates_
lock::Lock * get_lock_by_key(uint32_t key, bool include_internal=false)
void reserve_media_player(size_t count)
void pre_setup(const std::string &name, const std::string &friendly_name, const char *area, const char *comment, const char *compilation_time, bool name_add_mac_suffix)
Definition application.h:90
switch_::Switch * get_switch_by_key(uint32_t key, bool include_internal=false)
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)
number::Number * get_number_by_key(uint32_t key, bool include_internal=false)
void register_sensor(sensor::Sensor *sensor)
datetime::TimeEntity * get_time_by_key(uint32_t key, bool include_internal=false)
std::vector< climate::Climate * > climates_
const std::vector< datetime::DateEntity * > & get_dates()
const char * compilation_time_
const std::vector< alarm_control_panel::AlarmControlPanel * > & get_alarm_control_panels()
std::vector< Component * > looping_components_
const std::vector< cover::Cover * > & get_covers()
update::UpdateEntity * get_update_by_key(uint32_t key, bool include_internal=false)
void reserve_update(size_t count)
const std::vector< media_player::MediaPlayer * > & get_media_players()
datetime::DateTimeEntity * get_datetime_by_key(uint32_t key, bool include_internal=false)
void register_text_sensor(text_sensor::TextSensor *sensor)
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
std::vector< switch_::Switch * > switches_
void reserve_text(size_t count)
valve::Valve * get_valve_by_key(uint32_t key, bool include_internal=false)
std::vector< fan::Fan * > fans_
std::vector< number::Number * > numbers_
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.
text_sensor::TextSensor * get_text_sensor_by_key(uint32_t key, bool include_internal=false)
std::vector< valve::Valve * > valves_
void loop()
Make a loop iteration. Call this in your loop() function.
void register_text(text::Text *text)
std::vector< button::Button * > buttons_
std::vector< light::LightState * > lights_
void reserve_date(size_t count)
select::Select * get_select_by_key(uint32_t key, bool include_internal=false)
void unregister_socket_fd(int fd)
std::vector< select::Select * > selects_
std::vector< datetime::DateTimeEntity * > datetimes_
bool register_socket_fd(int fd)
Register/unregister a socket file descriptor to be monitored for read events.
void calculate_looping_components_()
cover::Cover * get_cover_by_key(uint32_t key, bool include_internal=false)
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
const std::vector< event::Event * > & get_events()
const std::vector< number::Number * > & get_numbers()
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:63
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:726
Application App
Global storage of Application pointer - only one Application can exist.