ESPHome  2022.9.2
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]() { 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_SELECT
63  for (auto *obj : App.get_selects()) {
64  if (include_internal || !obj->is_internal()) {
65  obj->add_on_state_callback(
66  [this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
67  }
68  }
69 #endif
70 #ifdef USE_LOCK
71  for (auto *obj : App.get_locks()) {
72  if (include_internal || !obj->is_internal())
73  obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
74  }
75 #endif
76 #ifdef USE_MEDIA_PLAYER
77  for (auto *obj : App.get_media_players()) {
78  if (include_internal || !obj->is_internal())
79  obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
80  }
81 #endif
82 }
83 
84 } // namespace esphome
const std::vector< climate::Climate * > & get_climates()
Definition: application.h:241
virtual void on_select_update(select::Select *obj, const std::string &state, size_t index)
Definition: controller.h:77
const std::vector< fan::Fan * > & get_fans()
Definition: application.h:214
const std::vector< lock::Lock * > & get_locks()
Definition: application.h:268
const std::vector< switch_::Switch * > & get_switches()
Definition: application.h:178
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
Definition: application.h:205
const std::vector< sensor::Sensor * > & get_sensors()
Definition: application.h:196
Application App
Global storage of Application pointer - only one Application can exist.
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
Definition: application.h:169
const std::vector< cover::Cover * > & get_covers()
Definition: application.h:223
const std::vector< light::LightState * > & get_lights()
Definition: application.h:232
void setup_controller(bool include_internal=false)
Definition: controller.cpp:7
const std::vector< media_player::MediaPlayer * > & get_media_players()
Definition: application.h:277
Definition: a4988.cpp:4
const std::vector< select::Select * > & get_selects()
Definition: application.h:259
const std::vector< number::Number * > & get_numbers()
Definition: application.h:250
bool state
Definition: fan.h:34