ESPHome  2024.4.0
controller.cpp
Go to the documentation of this file.
1 #include "controller.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 
7 void Controller::setup_controller(bool include_internal) {
8 #ifdef USE_BINARY_SENSOR
9  for (auto *obj : App.get_binary_sensors()) {
10  if (include_internal || !obj->is_internal())
11  obj->add_on_state_callback([this, obj](bool state) { this->on_binary_sensor_update(obj, state); });
12  }
13 #endif
14 #ifdef USE_FAN
15  for (auto *obj : App.get_fans()) {
16  if (include_internal || !obj->is_internal())
17  obj->add_on_state_callback([this, obj]() { this->on_fan_update(obj); });
18  }
19 #endif
20 #ifdef USE_LIGHT
21  for (auto *obj : App.get_lights()) {
22  if (include_internal || !obj->is_internal())
23  obj->add_new_remote_values_callback([this, obj]() { this->on_light_update(obj); });
24  }
25 #endif
26 #ifdef USE_SENSOR
27  for (auto *obj : App.get_sensors()) {
28  if (include_internal || !obj->is_internal())
29  obj->add_on_state_callback([this, obj](float state) { this->on_sensor_update(obj, state); });
30  }
31 #endif
32 #ifdef USE_SWITCH
33  for (auto *obj : App.get_switches()) {
34  if (include_internal || !obj->is_internal())
35  obj->add_on_state_callback([this, obj](bool state) { this->on_switch_update(obj, state); });
36  }
37 #endif
38 #ifdef USE_COVER
39  for (auto *obj : App.get_covers()) {
40  if (include_internal || !obj->is_internal())
41  obj->add_on_state_callback([this, obj]() { this->on_cover_update(obj); });
42  }
43 #endif
44 #ifdef USE_TEXT_SENSOR
45  for (auto *obj : App.get_text_sensors()) {
46  if (include_internal || !obj->is_internal())
47  obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_sensor_update(obj, state); });
48  }
49 #endif
50 #ifdef USE_CLIMATE
51  for (auto *obj : App.get_climates()) {
52  if (include_internal || !obj->is_internal())
53  obj->add_on_state_callback([this, obj](climate::Climate & /*unused*/) { this->on_climate_update(obj); });
54  }
55 #endif
56 #ifdef USE_NUMBER
57  for (auto *obj : App.get_numbers()) {
58  if (include_internal || !obj->is_internal())
59  obj->add_on_state_callback([this, obj](float state) { this->on_number_update(obj, state); });
60  }
61 #endif
62 #ifdef USE_DATETIME_DATE
63  for (auto *obj : App.get_dates()) {
64  if (include_internal || !obj->is_internal())
65  obj->add_on_state_callback([this, obj]() { this->on_date_update(obj); });
66  }
67 #endif
68 #ifdef USE_DATETIME_TIME
69  for (auto *obj : App.get_times()) {
70  if (include_internal || !obj->is_internal())
71  obj->add_on_state_callback([this, obj]() { this->on_time_update(obj); });
72  }
73 #endif
74 #ifdef USE_TEXT
75  for (auto *obj : App.get_texts()) {
76  if (include_internal || !obj->is_internal())
77  obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_update(obj, state); });
78  }
79 #endif
80 #ifdef USE_SELECT
81  for (auto *obj : App.get_selects()) {
82  if (include_internal || !obj->is_internal()) {
83  obj->add_on_state_callback(
84  [this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
85  }
86  }
87 #endif
88 #ifdef USE_LOCK
89  for (auto *obj : App.get_locks()) {
90  if (include_internal || !obj->is_internal())
91  obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
92  }
93 #endif
94 #ifdef USE_MEDIA_PLAYER
95  for (auto *obj : App.get_media_players()) {
96  if (include_internal || !obj->is_internal())
97  obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
98  }
99 #endif
100 #ifdef USE_ALARM_CONTROL_PANEL
101  for (auto *obj : App.get_alarm_control_panels()) {
102  if (include_internal || !obj->is_internal())
103  obj->add_on_state_callback([this, obj]() { this->on_alarm_control_panel_update(obj); });
104  }
105 #endif
106 }
107 
108 } // namespace esphome
const std::vector< climate::Climate * > & get_climates()
Definition: application.h:289
virtual void on_select_update(select::Select *obj, const std::string &state, size_t index)
Definition: controller.h:98
const std::vector< alarm_control_panel::AlarmControlPanel * > & get_alarm_control_panels()
Definition: application.h:362
const std::vector< fan::Fan * > & get_fans()
Definition: application.h:262
const std::vector< datetime::TimeEntity * > & get_times()
Definition: application.h:316
const std::vector< lock::Lock * > & get_locks()
Definition: application.h:343
const std::vector< switch_::Switch * > & get_switches()
Definition: application.h:226
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
Definition: application.h:253
const std::vector< sensor::Sensor * > & get_sensors()
Definition: application.h:244
Application App
Global storage of Application pointer - only one Application can exist.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
Definition: application.h:217
const std::vector< text::Text * > & get_texts()
Definition: application.h:325
const std::vector< cover::Cover * > & get_covers()
Definition: application.h:271
const std::vector< light::LightState * > & get_lights()
Definition: application.h:280
void setup_controller(bool include_internal=false)
Definition: controller.cpp:7
const std::vector< media_player::MediaPlayer * > & get_media_players()
Definition: application.h:352
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
const std::vector< datetime::DateEntity * > & get_dates()
Definition: application.h:307
const std::vector< select::Select * > & get_selects()
Definition: application.h:334
const std::vector< number::Number * > & get_numbers()
Definition: application.h:298
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:168
bool state
Definition: fan.h:34