ESPHome 2025.5.0
Loading...
Searching...
No Matches
controller.cpp
Go to the documentation of this file.
1#include "controller.h"
3#include "esphome/core/log.h"
4
5namespace esphome {
6
7void 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::TimeEntity * > & get_times()
const std::vector< valve::Valve * > & get_valves()
const std::vector< fan::Fan * > & get_fans()
const std::vector< switch_::Switch * > & get_switches()
const std::vector< sensor::Sensor * > & get_sensors()
const std::vector< text_sensor::TextSensor * > & get_text_sensors()
const std::vector< lock::Lock * > & get_locks()
const std::vector< datetime::DateTimeEntity * > & get_datetimes()
const std::vector< select::Select * > & get_selects()
const std::vector< text::Text * > & get_texts()
const std::vector< climate::Climate * > & get_climates()
const std::vector< light::LightState * > & get_lights()
const std::vector< update::UpdateEntity * > & get_updates()
const std::vector< datetime::DateEntity * > & get_dates()
const std::vector< alarm_control_panel::AlarmControlPanel * > & get_alarm_control_panels()
const std::vector< cover::Cover * > & get_covers()
const std::vector< media_player::MediaPlayer * > & get_media_players()
const std::vector< binary_sensor::BinarySensor * > & get_binary_sensors()
const std::vector< event::Event * > & get_events()
const std::vector< number::Number * > & get_numbers()
virtual void on_number_update(number::Number *obj, float state)
Definition controller.h:98
virtual void on_valve_update(valve::Valve *obj)
Definition controller.h:119
virtual void on_update(update::UpdateEntity *obj)
Definition controller.h:131
virtual void on_lock_update(lock::Lock *obj)
Definition controller.h:116
virtual void on_select_update(select::Select *obj, const std::string &state, size_t index)
Definition controller.h:113
virtual void on_datetime_update(datetime::DateTimeEntity *obj)
Definition controller.h:107
virtual void on_text_sensor_update(text_sensor::TextSensor *obj, const std::string &state)
Definition controller.h:92
virtual void on_climate_update(climate::Climate *obj)
Definition controller.h:95
virtual void on_date_update(datetime::DateEntity *obj)
Definition controller.h:101
virtual void on_event(event::Event *obj, const std::string &event_type)
Definition controller.h:128
void setup_controller(bool include_internal=false)
Definition controller.cpp:7
virtual void on_switch_update(switch_::Switch *obj, bool state)
Definition controller.h:86
virtual void on_cover_update(cover::Cover *obj)
Definition controller.h:89
virtual void on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state)
Definition controller.h:74
virtual void on_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj)
Definition controller.h:125
virtual void on_media_player_update(media_player::MediaPlayer *obj)
Definition controller.h:122
virtual void on_time_update(datetime::TimeEntity *obj)
Definition controller.h:104
virtual void on_fan_update(fan::Fan *obj)
Definition controller.h:77
virtual void on_sensor_update(sensor::Sensor *obj, float state)
Definition controller.h:83
virtual void on_light_update(light::LightState *obj)
Definition controller.h:80
virtual void on_text_update(text::Text *obj, const std::string &state)
Definition controller.h:110
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:168
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Application App
Global storage of Application pointer - only one Application can exist.