ESPHome  2024.10.3
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_DATETIME_DATETIME
75  for (auto *obj : App.get_datetimes()) {
76  if (include_internal || !obj->is_internal())
77  obj->add_on_state_callback([this, obj]() { this->on_datetime_update(obj); });
78  }
79 #endif
80 #ifdef USE_TEXT
81  for (auto *obj : App.get_texts()) {
82  if (include_internal || !obj->is_internal())
83  obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_update(obj, state); });
84  }
85 #endif
86 #ifdef USE_SELECT
87  for (auto *obj : App.get_selects()) {
88  if (include_internal || !obj->is_internal()) {
89  obj->add_on_state_callback(
90  [this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
91  }
92  }
93 #endif
94 #ifdef USE_LOCK
95  for (auto *obj : App.get_locks()) {
96  if (include_internal || !obj->is_internal())
97  obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
98  }
99 #endif
100 #ifdef USE_VALVE
101  for (auto *obj : App.get_valves()) {
102  if (include_internal || !obj->is_internal())
103  obj->add_on_state_callback([this, obj]() { this->on_valve_update(obj); });
104  }
105 #endif
106 #ifdef USE_MEDIA_PLAYER
107  for (auto *obj : App.get_media_players()) {
108  if (include_internal || !obj->is_internal())
109  obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
110  }
111 #endif
112 #ifdef USE_ALARM_CONTROL_PANEL
113  for (auto *obj : App.get_alarm_control_panels()) {
114  if (include_internal || !obj->is_internal())
115  obj->add_on_state_callback([this, obj]() { this->on_alarm_control_panel_update(obj); });
116  }
117 #endif
118 #ifdef USE_EVENT
119  for (auto *obj : App.get_events()) {
120  if (include_internal || !obj->is_internal())
121  obj->add_on_event_callback([this, obj](const std::string &event_type) { this->on_event(obj, event_type); });
122  }
123 #endif
124 #ifdef USE_UPDATE
125  for (auto *obj : App.get_updates()) {
126  if (include_internal || !obj->is_internal())
127  obj->add_on_state_callback([this, obj]() { this->on_update(obj); });
128  }
129 #endif
130 }
131 
132 } // namespace esphome
const std::vector< datetime::DateTimeEntity * > & get_datetimes()
Definition: application.h:367
const std::vector< climate::Climate * > & get_climates()
Definition: application.h:327
virtual void on_select_update(select::Select *obj, const std::string &state, size_t index)
Definition: controller.h:113
const std::vector< update::UpdateEntity * > & get_updates()
Definition: application.h:452
const std::vector< alarm_control_panel::AlarmControlPanel * > & get_alarm_control_panels()
Definition: application.h:428
const std::vector< valve::Valve * > & get_valves()
Definition: application.h:407
const std::vector< event::Event * > & get_events()
Definition: application.h:441
const std::vector< fan::Fan * > & get_fans()
Definition: application.h:297
const std::vector< datetime::TimeEntity * > & get_times()
Definition: application.h:357
const std::vector< lock::Lock * > & get_locks()
Definition: application.h:397
const std::vector< switch_::Switch * > & get_switches()
Definition: application.h:257
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
Definition: application.h:287
const std::vector< sensor::Sensor * > & get_sensors()
Definition: application.h:277
Application App
Global storage of Application pointer - only one Application can exist.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
Definition: application.h:247
const std::vector< text::Text * > & get_texts()
Definition: application.h:377
const std::vector< cover::Cover * > & get_covers()
Definition: application.h:307
const std::vector< light::LightState * > & get_lights()
Definition: application.h:317
void setup_controller(bool include_internal=false)
Definition: controller.cpp:7
const std::vector< media_player::MediaPlayer * > & get_media_players()
Definition: application.h:417
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
const std::vector< datetime::DateEntity * > & get_dates()
Definition: application.h:347
const std::vector< select::Select * > & get_selects()
Definition: application.h:387
const std::vector< number::Number * > & get_numbers()
Definition: application.h:337
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:168
bool state
Definition: fan.h:34