12#ifdef USE_SOCKET_SELECT_SUPPORT
13#include <sys/select.h>
16#ifdef USE_BINARY_SENSOR
46#ifdef USE_DATETIME_DATE
49#ifdef USE_DATETIME_TIME
52#ifdef USE_DATETIME_DATETIME
67#ifdef USE_MEDIA_PLAYER
70#ifdef USE_ALARM_CONTROL_PANEL
86static const uint32_t TEARDOWN_TIMEOUT_REBOOT_MS = 1000;
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) {
94 if (name_add_mac_suffix) {
96 if (friendly_name.empty()) {
113#ifdef USE_BINARY_SENSOR
131#ifdef USE_TEXT_SENSOR
155#ifdef USE_DATETIME_DATE
159#ifdef USE_DATETIME_TIME
163#ifdef USE_DATETIME_DATETIME
183#ifdef USE_MEDIA_PLAYER
187#ifdef USE_ALARM_CONTROL_PANEL
204#ifdef USE_BINARY_SENSOR
216#ifdef USE_TEXT_SENSOR
234#ifdef USE_DATETIME_DATE
237#ifdef USE_DATETIME_TIME
240#ifdef USE_DATETIME_DATETIME
255#ifdef USE_MEDIA_PLAYER
258#ifdef USE_ALARM_CONTROL_PANEL
270 static_assert(std::is_base_of<Component, C>::value,
"Only Component subclasses can be registered");
337#ifdef USE_BINARY_SENSOR
341 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
351 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
361 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
371 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
377#ifdef USE_TEXT_SENSOR
381 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
390 for (
auto *obj : this->
fans_) {
391 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
400 for (
auto *obj : this->
covers_) {
401 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
410 for (
auto *obj : this->
lights_) {
411 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
421 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
431 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
437#ifdef USE_DATETIME_DATE
440 for (
auto *obj : this->
dates_) {
441 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
447#ifdef USE_DATETIME_TIME
450 for (
auto *obj : this->
times_) {
451 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
457#ifdef USE_DATETIME_DATETIME
461 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
470 for (
auto *obj : this->
texts_) {
471 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
481 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
490 for (
auto *obj : this->
locks_) {
491 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
500 for (
auto *obj : this->
valves_) {
501 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
507#ifdef USE_MEDIA_PLAYER
511 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
518#ifdef USE_ALARM_CONTROL_PANEL
524 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
534 for (
auto *obj : this->
events_) {
535 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
546 if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
556#ifdef USE_SOCKET_SELECT_SUPPORT
583#ifdef USE_BINARY_SENSOR
598#ifdef USE_TEXT_SENSOR
616#ifdef USE_DATETIME_DATE
617 std::vector<datetime::DateEntity *>
dates_{};
619#ifdef USE_DATETIME_TIME
620 std::vector<datetime::TimeEntity *>
times_{};
622#ifdef USE_DATETIME_DATETIME
637#ifdef USE_MEDIA_PLAYER
640#ifdef USE_ALARM_CONTROL_PANEL
660#ifdef USE_SOCKET_SELECT_SUPPORT
671extern Application
App;
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_
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)
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)
bool name_add_mac_suffix_
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_
void schedule_dump_config()
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)
void run_safe_shutdown_hooks()
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
void run_powerdown_hooks()
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.
ClimateDevice - This is the base class for all climate integrations.
Base class for all cover devices.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Base class for all locks.
Base-class for all numbers.
Base-class for all selects.
Base-class for all sensors.
Base class for all switches.
Base-class for all text inputs.
Base class for all valve devices.
Providing packet encoding functions for exchanging data with a remote host.
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Application App
Global storage of Application pointer - only one Application can exist.