2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include "esphome/core/component.h"
|
2023-01-17 01:02:54 +01:00
|
|
|
#include "esphome/core/defines.h"
|
2021-12-01 21:05:42 +01:00
|
|
|
#include "esphome/core/hal.h"
|
2019-04-17 12:06:00 +02:00
|
|
|
#include "esphome/core/helpers.h"
|
2023-01-17 01:02:54 +01:00
|
|
|
#include "esphome/core/preferences.h"
|
2019-06-07 14:26:40 +02:00
|
|
|
#include "esphome/core/scheduler.h"
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SENSOR
|
|
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
#include "esphome/components/switch/switch.h"
|
|
|
|
#endif
|
2021-11-29 20:00:51 +01:00
|
|
|
#ifdef USE_BUTTON
|
|
|
|
#include "esphome/components/button/button.h"
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
#ifdef USE_TEXT_SENSOR
|
|
|
|
#include "esphome/components/text_sensor/text_sensor.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FAN
|
|
|
|
#include "esphome/components/fan/fan_state.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_CLIMATE
|
|
|
|
#include "esphome/components/climate/climate.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
#include "esphome/components/light/light_state.h"
|
|
|
|
#endif
|
|
|
|
#ifdef USE_COVER
|
|
|
|
#include "esphome/components/cover/cover.h"
|
|
|
|
#endif
|
2021-07-12 21:20:12 +02:00
|
|
|
#ifdef USE_NUMBER
|
|
|
|
#include "esphome/components/number/number.h"
|
|
|
|
#endif
|
2024-03-10 19:52:22 +01:00
|
|
|
#ifdef USE_DATETIME_DATE
|
|
|
|
#include "esphome/components/datetime/date_entity.h"
|
|
|
|
#endif
|
2024-04-09 03:46:35 +02:00
|
|
|
#ifdef USE_DATETIME_TIME
|
|
|
|
#include "esphome/components/datetime/time_entity.h"
|
|
|
|
#endif
|
2024-04-25 23:19:54 +02:00
|
|
|
#ifdef USE_DATETIME_DATETIME
|
|
|
|
#include "esphome/components/datetime/datetime_entity.h"
|
|
|
|
#endif
|
2023-10-25 11:00:32 +02:00
|
|
|
#ifdef USE_TEXT
|
|
|
|
#include "esphome/components/text/text.h"
|
|
|
|
#endif
|
2021-08-02 10:00:51 +02:00
|
|
|
#ifdef USE_SELECT
|
|
|
|
#include "esphome/components/select/select.h"
|
|
|
|
#endif
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
#include "esphome/components/lock/lock.h"
|
|
|
|
#endif
|
2024-04-23 06:47:03 +02:00
|
|
|
#ifdef USE_VALVE
|
|
|
|
#include "esphome/components/valve/valve.h"
|
|
|
|
#endif
|
2022-06-02 07:00:17 +02:00
|
|
|
#ifdef USE_MEDIA_PLAYER
|
|
|
|
#include "esphome/components/media_player/media_player.h"
|
|
|
|
#endif
|
2023-06-15 02:34:39 +02:00
|
|
|
#ifdef USE_ALARM_CONTROL_PANEL
|
|
|
|
#include "esphome/components/alarm_control_panel/alarm_control_panel.h"
|
|
|
|
#endif
|
2024-04-24 04:35:26 +02:00
|
|
|
#ifdef USE_EVENT
|
|
|
|
#include "esphome/components/event/event.h"
|
|
|
|
#endif
|
2024-06-11 23:57:36 +02:00
|
|
|
#ifdef USE_UPDATE
|
|
|
|
#include "esphome/components/update/update_entity.h"
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
|
|
|
|
class Application {
|
|
|
|
public:
|
2023-10-27 00:38:52 +02:00
|
|
|
void pre_setup(const std::string &name, const std::string &friendly_name, const std::string &area,
|
|
|
|
const char *comment, const char *compilation_time, bool name_add_mac_suffix) {
|
2021-12-01 21:05:42 +01:00
|
|
|
arch_init();
|
2021-06-16 03:49:06 +02:00
|
|
|
this->name_add_mac_suffix_ = name_add_mac_suffix;
|
2021-03-17 21:22:48 +01:00
|
|
|
if (name_add_mac_suffix) {
|
2021-04-27 03:41:16 +02:00
|
|
|
this->name_ = name + "-" + get_mac_address().substr(6);
|
2023-01-16 22:28:09 +01:00
|
|
|
if (friendly_name.empty()) {
|
|
|
|
this->friendly_name_ = "";
|
|
|
|
} else {
|
|
|
|
this->friendly_name_ = friendly_name + " " + get_mac_address().substr(6);
|
|
|
|
}
|
2021-03-17 21:22:48 +01:00
|
|
|
} else {
|
|
|
|
this->name_ = name;
|
2023-01-16 22:28:09 +01:00
|
|
|
this->friendly_name_ = friendly_name;
|
2021-03-17 21:22:48 +01:00
|
|
|
}
|
2023-10-27 00:38:52 +02:00
|
|
|
this->area_ = area;
|
2023-01-17 01:02:54 +01:00
|
|
|
this->comment_ = comment;
|
2019-04-17 12:06:00 +02:00
|
|
|
this->compilation_time_ = compilation_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
void register_binary_sensor(binary_sensor::BinarySensor *binary_sensor) {
|
|
|
|
this->binary_sensors_.push_back(binary_sensor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SENSOR
|
|
|
|
void register_sensor(sensor::Sensor *sensor) { this->sensors_.push_back(sensor); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
void register_switch(switch_::Switch *a_switch) { this->switches_.push_back(a_switch); }
|
|
|
|
#endif
|
|
|
|
|
2021-11-29 20:00:51 +01:00
|
|
|
#ifdef USE_BUTTON
|
|
|
|
void register_button(button::Button *button) { this->buttons_.push_back(button); }
|
|
|
|
#endif
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
#ifdef USE_TEXT_SENSOR
|
|
|
|
void register_text_sensor(text_sensor::TextSensor *sensor) { this->text_sensors_.push_back(sensor); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_FAN
|
2022-01-23 10:21:54 +01:00
|
|
|
void register_fan(fan::Fan *state) { this->fans_.push_back(state); }
|
2019-04-17 12:06:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_COVER
|
|
|
|
void register_cover(cover::Cover *cover) { this->covers_.push_back(cover); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_CLIMATE
|
|
|
|
void register_climate(climate::Climate *climate) { this->climates_.push_back(climate); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
void register_light(light::LightState *light) { this->lights_.push_back(light); }
|
|
|
|
#endif
|
|
|
|
|
2021-07-12 21:20:12 +02:00
|
|
|
#ifdef USE_NUMBER
|
|
|
|
void register_number(number::Number *number) { this->numbers_.push_back(number); }
|
|
|
|
#endif
|
|
|
|
|
2024-03-10 19:52:22 +01:00
|
|
|
#ifdef USE_DATETIME_DATE
|
|
|
|
void register_date(datetime::DateEntity *date) { this->dates_.push_back(date); }
|
|
|
|
#endif
|
|
|
|
|
2024-04-09 03:46:35 +02:00
|
|
|
#ifdef USE_DATETIME_TIME
|
|
|
|
void register_time(datetime::TimeEntity *time) { this->times_.push_back(time); }
|
|
|
|
#endif
|
|
|
|
|
2024-04-25 23:19:54 +02:00
|
|
|
#ifdef USE_DATETIME_DATETIME
|
|
|
|
void register_datetime(datetime::DateTimeEntity *datetime) { this->datetimes_.push_back(datetime); }
|
|
|
|
#endif
|
|
|
|
|
2023-10-25 11:00:32 +02:00
|
|
|
#ifdef USE_TEXT
|
|
|
|
void register_text(text::Text *text) { this->texts_.push_back(text); }
|
|
|
|
#endif
|
|
|
|
|
2021-08-02 10:00:51 +02:00
|
|
|
#ifdef USE_SELECT
|
|
|
|
void register_select(select::Select *select) { this->selects_.push_back(select); }
|
|
|
|
#endif
|
|
|
|
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
void register_lock(lock::Lock *a_lock) { this->locks_.push_back(a_lock); }
|
|
|
|
#endif
|
|
|
|
|
2024-04-23 06:47:03 +02:00
|
|
|
#ifdef USE_VALVE
|
|
|
|
void register_valve(valve::Valve *valve) { this->valves_.push_back(valve); }
|
|
|
|
#endif
|
|
|
|
|
2022-06-02 07:00:17 +02:00
|
|
|
#ifdef USE_MEDIA_PLAYER
|
|
|
|
void register_media_player(media_player::MediaPlayer *media_player) { this->media_players_.push_back(media_player); }
|
|
|
|
#endif
|
|
|
|
|
2023-06-15 02:34:39 +02:00
|
|
|
#ifdef USE_ALARM_CONTROL_PANEL
|
|
|
|
void register_alarm_control_panel(alarm_control_panel::AlarmControlPanel *a_alarm_control_panel) {
|
|
|
|
this->alarm_control_panels_.push_back(a_alarm_control_panel);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-04-24 04:35:26 +02:00
|
|
|
#ifdef USE_EVENT
|
|
|
|
void register_event(event::Event *event) { this->events_.push_back(event); }
|
|
|
|
#endif
|
|
|
|
|
2024-06-11 23:57:36 +02:00
|
|
|
#ifdef USE_UPDATE
|
|
|
|
void register_update(update::UpdateEntity *update) { this->updates_.push_back(update); }
|
|
|
|
#endif
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
/// Register the component in this Application instance.
|
|
|
|
template<class C> C *register_component(C *c) {
|
|
|
|
static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
|
|
|
|
this->register_component_((Component *) c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set up all the registered components. Call this at the end of your setup() function.
|
|
|
|
void setup();
|
|
|
|
|
|
|
|
/// Make a loop iteration. Call this in your loop() function.
|
2019-05-29 11:13:05 +02:00
|
|
|
void loop();
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2023-01-17 01:02:54 +01:00
|
|
|
/// Get the name of this Application set by pre_setup().
|
2019-04-17 12:06:00 +02:00
|
|
|
const std::string &get_name() const { return this->name_; }
|
|
|
|
|
2023-01-17 01:02:54 +01:00
|
|
|
/// Get the friendly name of this Application set by pre_setup().
|
2023-01-16 22:28:09 +01:00
|
|
|
const std::string &get_friendly_name() const { return this->friendly_name_; }
|
2023-10-27 00:38:52 +02:00
|
|
|
|
|
|
|
/// Get the area of this Application set by pre_setup().
|
|
|
|
const std::string &get_area() const { return this->area_; }
|
|
|
|
|
2023-01-17 01:02:54 +01:00
|
|
|
/// Get the comment of this Application set by pre_setup().
|
2023-06-19 01:35:47 +02:00
|
|
|
std::string get_comment() const { return this->comment_; }
|
2023-01-16 22:28:09 +01:00
|
|
|
|
2021-06-16 03:49:06 +02:00
|
|
|
bool is_name_add_mac_suffix_enabled() const { return this->name_add_mac_suffix_; }
|
|
|
|
|
2023-06-19 01:35:47 +02:00
|
|
|
std::string get_compilation_time() const { return this->compilation_time_; }
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
/** Set the target interval with which to run the loop() calls.
|
|
|
|
* If the loop() method takes longer than the target interval, ESPHome won't
|
|
|
|
* sleep in loop(), but if the time spent in loop() is small than the target, ESPHome
|
|
|
|
* will delay at the end of the App.loop() method.
|
|
|
|
*
|
|
|
|
* This is done to conserve power: In most use-cases, high-speed loop() calls are not required
|
|
|
|
* and degrade power consumption.
|
|
|
|
*
|
|
|
|
* Each component can request a high frequency loop execution by using the HighFrequencyLoopRequester
|
|
|
|
* helper in helpers.h
|
|
|
|
*
|
|
|
|
* @param loop_interval The interval in milliseconds to run the core loop at. Defaults to 16 milliseconds.
|
|
|
|
*/
|
|
|
|
void set_loop_interval(uint32_t loop_interval) { this->loop_interval_ = loop_interval; }
|
|
|
|
|
2024-05-02 02:39:15 +02:00
|
|
|
uint32_t get_loop_interval() const { return this->loop_interval_; }
|
|
|
|
|
2019-06-03 15:21:36 +02:00
|
|
|
void schedule_dump_config() { this->dump_config_at_ = 0; }
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void feed_wdt();
|
|
|
|
|
|
|
|
void reboot();
|
|
|
|
|
|
|
|
void safe_reboot();
|
|
|
|
|
2022-06-21 01:26:34 +02:00
|
|
|
void run_safe_shutdown_hooks();
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
uint32_t get_app_state() const { return this->app_state_; }
|
|
|
|
|
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
const std::vector<binary_sensor::BinarySensor *> &get_binary_sensors() { return this->binary_sensors_; }
|
|
|
|
binary_sensor::BinarySensor *get_binary_sensor_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->binary_sensors_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
const std::vector<switch_::Switch *> &get_switches() { return this->switches_; }
|
|
|
|
switch_::Switch *get_switch_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->switches_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-29 20:00:51 +01:00
|
|
|
#ifdef USE_BUTTON
|
|
|
|
const std::vector<button::Button *> &get_buttons() { return this->buttons_; }
|
|
|
|
button::Button *get_button_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->buttons_) {
|
2021-11-29 20:00:51 +01:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2021-11-29 20:00:51 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
#ifdef USE_SENSOR
|
|
|
|
const std::vector<sensor::Sensor *> &get_sensors() { return this->sensors_; }
|
|
|
|
sensor::Sensor *get_sensor_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->sensors_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_TEXT_SENSOR
|
|
|
|
const std::vector<text_sensor::TextSensor *> &get_text_sensors() { return this->text_sensors_; }
|
|
|
|
text_sensor::TextSensor *get_text_sensor_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->text_sensors_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FAN
|
2022-01-23 10:21:54 +01:00
|
|
|
const std::vector<fan::Fan *> &get_fans() { return this->fans_; }
|
|
|
|
fan::Fan *get_fan_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->fans_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_COVER
|
|
|
|
const std::vector<cover::Cover *> &get_covers() { return this->covers_; }
|
|
|
|
cover::Cover *get_cover_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->covers_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
const std::vector<light::LightState *> &get_lights() { return this->lights_; }
|
|
|
|
light::LightState *get_light_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->lights_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_CLIMATE
|
|
|
|
const std::vector<climate::Climate *> &get_climates() { return this->climates_; }
|
|
|
|
climate::Climate *get_climate_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->climates_) {
|
2019-04-17 12:06:00 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2019-04-17 12:06:00 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-12 21:20:12 +02:00
|
|
|
#ifdef USE_NUMBER
|
|
|
|
const std::vector<number::Number *> &get_numbers() { return this->numbers_; }
|
|
|
|
number::Number *get_number_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->numbers_) {
|
2021-07-12 21:20:12 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2021-07-12 21:20:12 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2024-03-10 19:52:22 +01:00
|
|
|
#ifdef USE_DATETIME_DATE
|
|
|
|
const std::vector<datetime::DateEntity *> &get_dates() { return this->dates_; }
|
|
|
|
datetime::DateEntity *get_date_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->dates_) {
|
2024-03-10 19:52:22 +01:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-03-10 19:52:22 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2024-04-09 03:46:35 +02:00
|
|
|
#ifdef USE_DATETIME_TIME
|
|
|
|
const std::vector<datetime::TimeEntity *> &get_times() { return this->times_; }
|
|
|
|
datetime::TimeEntity *get_time_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->times_) {
|
2024-04-09 03:46:35 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-04-09 03:46:35 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2024-04-25 23:19:54 +02:00
|
|
|
#ifdef USE_DATETIME_DATETIME
|
|
|
|
const std::vector<datetime::DateTimeEntity *> &get_datetimes() { return this->datetimes_; }
|
|
|
|
datetime::DateTimeEntity *get_datetime_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->datetimes_) {
|
2024-04-25 23:19:54 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-04-25 23:19:54 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2023-10-25 11:00:32 +02:00
|
|
|
#ifdef USE_TEXT
|
|
|
|
const std::vector<text::Text *> &get_texts() { return this->texts_; }
|
|
|
|
text::Text *get_text_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->texts_) {
|
2023-10-25 11:00:32 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2023-10-25 11:00:32 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-02 10:00:51 +02:00
|
|
|
#ifdef USE_SELECT
|
|
|
|
const std::vector<select::Select *> &get_selects() { return this->selects_; }
|
|
|
|
select::Select *get_select_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->selects_) {
|
2021-08-02 10:00:51 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2021-08-02 10:00:51 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
const std::vector<lock::Lock *> &get_locks() { return this->locks_; }
|
|
|
|
lock::Lock *get_lock_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->locks_) {
|
2022-02-03 19:24:31 +01:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2022-02-03 19:24:31 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2024-04-23 06:47:03 +02:00
|
|
|
#ifdef USE_VALVE
|
|
|
|
const std::vector<valve::Valve *> &get_valves() { return this->valves_; }
|
|
|
|
valve::Valve *get_valve_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->valves_) {
|
2024-04-23 06:47:03 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-04-23 06:47:03 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2022-06-02 07:00:17 +02:00
|
|
|
#ifdef USE_MEDIA_PLAYER
|
|
|
|
const std::vector<media_player::MediaPlayer *> &get_media_players() { return this->media_players_; }
|
|
|
|
media_player::MediaPlayer *get_media_player_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->media_players_) {
|
2022-06-02 07:00:17 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2022-06-02 07:00:17 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2023-06-15 02:34:39 +02:00
|
|
|
#ifdef USE_ALARM_CONTROL_PANEL
|
|
|
|
const std::vector<alarm_control_panel::AlarmControlPanel *> &get_alarm_control_panels() {
|
|
|
|
return this->alarm_control_panels_;
|
|
|
|
}
|
|
|
|
alarm_control_panel::AlarmControlPanel *get_alarm_control_panel_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->alarm_control_panels_) {
|
2023-06-15 02:34:39 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2023-06-15 02:34:39 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-04-24 04:35:26 +02:00
|
|
|
#ifdef USE_EVENT
|
|
|
|
const std::vector<event::Event *> &get_events() { return this->events_; }
|
|
|
|
event::Event *get_event_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->events_) {
|
2024-04-24 04:35:26 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-04-24 04:35:26 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-06-11 23:57:36 +02:00
|
|
|
#ifdef USE_UPDATE
|
|
|
|
const std::vector<update::UpdateEntity *> &get_updates() { return this->updates_; }
|
|
|
|
update::UpdateEntity *get_update_by_key(uint32_t key, bool include_internal = false) {
|
2024-08-14 04:14:29 +02:00
|
|
|
for (auto *obj : this->updates_) {
|
2024-06-11 23:57:36 +02:00
|
|
|
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
|
|
|
|
return obj;
|
2024-08-14 04:14:29 +02:00
|
|
|
}
|
2024-06-11 23:57:36 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-07 14:26:40 +02:00
|
|
|
Scheduler scheduler;
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
protected:
|
|
|
|
friend Component;
|
|
|
|
|
|
|
|
void register_component_(Component *comp);
|
|
|
|
|
2019-12-04 16:03:37 +01:00
|
|
|
void calculate_looping_components_();
|
|
|
|
|
2021-08-10 11:10:52 +02:00
|
|
|
void feed_wdt_arch_();
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
std::vector<Component *> components_{};
|
2019-12-04 16:03:37 +01:00
|
|
|
std::vector<Component *> looping_components_{};
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
std::vector<binary_sensor::BinarySensor *> binary_sensors_{};
|
|
|
|
#endif
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
std::vector<switch_::Switch *> switches_{};
|
|
|
|
#endif
|
2021-11-29 20:00:51 +01:00
|
|
|
#ifdef USE_BUTTON
|
|
|
|
std::vector<button::Button *> buttons_{};
|
|
|
|
#endif
|
2024-04-24 04:35:26 +02:00
|
|
|
#ifdef USE_EVENT
|
|
|
|
std::vector<event::Event *> events_{};
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
#ifdef USE_SENSOR
|
|
|
|
std::vector<sensor::Sensor *> sensors_{};
|
|
|
|
#endif
|
|
|
|
#ifdef USE_TEXT_SENSOR
|
|
|
|
std::vector<text_sensor::TextSensor *> text_sensors_{};
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FAN
|
2022-01-23 10:21:54 +01:00
|
|
|
std::vector<fan::Fan *> fans_{};
|
2019-04-17 12:06:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef USE_COVER
|
|
|
|
std::vector<cover::Cover *> covers_{};
|
|
|
|
#endif
|
|
|
|
#ifdef USE_CLIMATE
|
|
|
|
std::vector<climate::Climate *> climates_{};
|
|
|
|
#endif
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
std::vector<light::LightState *> lights_{};
|
|
|
|
#endif
|
2021-07-12 21:20:12 +02:00
|
|
|
#ifdef USE_NUMBER
|
|
|
|
std::vector<number::Number *> numbers_{};
|
|
|
|
#endif
|
2024-03-10 19:52:22 +01:00
|
|
|
#ifdef USE_DATETIME_DATE
|
|
|
|
std::vector<datetime::DateEntity *> dates_{};
|
|
|
|
#endif
|
2024-04-09 03:46:35 +02:00
|
|
|
#ifdef USE_DATETIME_TIME
|
|
|
|
std::vector<datetime::TimeEntity *> times_{};
|
|
|
|
#endif
|
2024-04-25 23:19:54 +02:00
|
|
|
#ifdef USE_DATETIME_DATETIME
|
|
|
|
std::vector<datetime::DateTimeEntity *> datetimes_{};
|
|
|
|
#endif
|
2021-08-02 10:00:51 +02:00
|
|
|
#ifdef USE_SELECT
|
|
|
|
std::vector<select::Select *> selects_{};
|
|
|
|
#endif
|
2023-10-25 11:00:32 +02:00
|
|
|
#ifdef USE_TEXT
|
|
|
|
std::vector<text::Text *> texts_{};
|
|
|
|
#endif
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
std::vector<lock::Lock *> locks_{};
|
|
|
|
#endif
|
2024-04-23 06:47:03 +02:00
|
|
|
#ifdef USE_VALVE
|
|
|
|
std::vector<valve::Valve *> valves_{};
|
|
|
|
#endif
|
2022-06-02 07:00:17 +02:00
|
|
|
#ifdef USE_MEDIA_PLAYER
|
|
|
|
std::vector<media_player::MediaPlayer *> media_players_{};
|
|
|
|
#endif
|
2023-06-15 02:34:39 +02:00
|
|
|
#ifdef USE_ALARM_CONTROL_PANEL
|
|
|
|
std::vector<alarm_control_panel::AlarmControlPanel *> alarm_control_panels_{};
|
|
|
|
#endif
|
2024-06-11 23:57:36 +02:00
|
|
|
#ifdef USE_UPDATE
|
|
|
|
std::vector<update::UpdateEntity *> updates_{};
|
|
|
|
#endif
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
std::string name_;
|
2023-01-16 22:28:09 +01:00
|
|
|
std::string friendly_name_;
|
2023-10-27 00:38:52 +02:00
|
|
|
std::string area_;
|
2023-06-19 01:35:47 +02:00
|
|
|
const char *comment_{nullptr};
|
|
|
|
const char *compilation_time_{nullptr};
|
2021-06-16 03:49:06 +02:00
|
|
|
bool name_add_mac_suffix_;
|
2019-04-17 12:06:00 +02:00
|
|
|
uint32_t last_loop_{0};
|
|
|
|
uint32_t loop_interval_{16};
|
2021-12-01 21:03:51 +01:00
|
|
|
size_t dump_config_at_{SIZE_MAX};
|
2019-04-17 12:06:00 +02:00
|
|
|
uint32_t app_state_{0};
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Global storage of Application pointer - only one Application can exist.
|
2021-06-10 22:19:44 +02:00
|
|
|
extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
} // namespace esphome
|