ESPHome  2024.2.0
controller.cpp
Go to the documentation of this file.
1 #include "controller.h"
2 #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_TEXT
63  for (auto *obj : App.get_texts()) {
64  if (include_internal || !obj->is_internal())
65  obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_update(obj, state); });
66  }
67 #endif
68 #ifdef USE_SELECT
69  for (auto *obj : App.get_selects()) {
70  if (include_internal || !obj->is_internal()) {
71  obj->add_on_state_callback(
72  [this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
73  }
74  }
75 #endif
76 #ifdef USE_LOCK
77  for (auto *obj : App.get_locks()) {
78  if (include_internal || !obj->is_internal())
79  obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
80  }
81 #endif
82 #ifdef USE_MEDIA_PLAYER
83  for (auto *obj : App.get_media_players()) {
84  if (include_internal || !obj->is_internal())
85  obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
86  }
87 #endif
88 #ifdef USE_ALARM_CONTROL_PANEL
89  for (auto *obj : App.get_alarm_control_panels()) {
90  if (include_internal || !obj->is_internal())
91  obj->add_on_state_callback([this, obj]() { this->on_alarm_control_panel_update(obj); });
92  }
93 #endif
94 }
95 
96 } // namespace esphome
const std::vector< climate::Climate * > & get_climates()
Definition: application.h:275
virtual void on_select_update(select::Select *obj, const std::string &state, size_t index)
Definition: controller.h:86
const std::vector< alarm_control_panel::AlarmControlPanel * > & get_alarm_control_panels()
Definition: application.h:330
const std::vector< fan::Fan * > & get_fans()
Definition: application.h:248
const std::vector< lock::Lock * > & get_locks()
Definition: application.h:311
const std::vector< switch_::Switch * > & get_switches()
Definition: application.h:212
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
Definition: application.h:239
const std::vector< sensor::Sensor * > & get_sensors()
Definition: application.h:230
Application App
Global storage of Application pointer - only one Application can exist.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
Definition: application.h:203
const std::vector< text::Text * > & get_texts()
Definition: application.h:293
const std::vector< cover::Cover * > & get_covers()
Definition: application.h:257
const std::vector< light::LightState * > & get_lights()
Definition: application.h:266
void setup_controller(bool include_internal=false)
Definition: controller.cpp:7
const std::vector< media_player::MediaPlayer * > & get_media_players()
Definition: application.h:320
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< select::Select * > & get_selects()
Definition: application.h:302
const std::vector< number::Number * > & get_numbers()
Definition: application.h:284
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:168
bool state
Definition: fan.h:34