ESPHome 2025.8.0b2
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_full_state_callback(
12 [this, obj](optional<bool> previous, optional<bool> state) { this->on_binary_sensor_update(obj); });
13 }
14 }
15#endif
16#ifdef USE_FAN
17 for (auto *obj : App.get_fans()) {
18 if (include_internal || !obj->is_internal())
19 obj->add_on_state_callback([this, obj]() { this->on_fan_update(obj); });
20 }
21#endif
22#ifdef USE_LIGHT
23 for (auto *obj : App.get_lights()) {
24 if (include_internal || !obj->is_internal())
25 obj->add_new_remote_values_callback([this, obj]() { this->on_light_update(obj); });
26 }
27#endif
28#ifdef USE_SENSOR
29 for (auto *obj : App.get_sensors()) {
30 if (include_internal || !obj->is_internal())
31 obj->add_on_state_callback([this, obj](float state) { this->on_sensor_update(obj, state); });
32 }
33#endif
34#ifdef USE_SWITCH
35 for (auto *obj : App.get_switches()) {
36 if (include_internal || !obj->is_internal())
37 obj->add_on_state_callback([this, obj](bool state) { this->on_switch_update(obj, state); });
38 }
39#endif
40#ifdef USE_COVER
41 for (auto *obj : App.get_covers()) {
42 if (include_internal || !obj->is_internal())
43 obj->add_on_state_callback([this, obj]() { this->on_cover_update(obj); });
44 }
45#endif
46#ifdef USE_TEXT_SENSOR
47 for (auto *obj : App.get_text_sensors()) {
48 if (include_internal || !obj->is_internal())
49 obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_sensor_update(obj, state); });
50 }
51#endif
52#ifdef USE_CLIMATE
53 for (auto *obj : App.get_climates()) {
54 if (include_internal || !obj->is_internal())
55 obj->add_on_state_callback([this, obj](climate::Climate & /*unused*/) { this->on_climate_update(obj); });
56 }
57#endif
58#ifdef USE_NUMBER
59 for (auto *obj : App.get_numbers()) {
60 if (include_internal || !obj->is_internal())
61 obj->add_on_state_callback([this, obj](float state) { this->on_number_update(obj, state); });
62 }
63#endif
64#ifdef USE_DATETIME_DATE
65 for (auto *obj : App.get_dates()) {
66 if (include_internal || !obj->is_internal())
67 obj->add_on_state_callback([this, obj]() { this->on_date_update(obj); });
68 }
69#endif
70#ifdef USE_DATETIME_TIME
71 for (auto *obj : App.get_times()) {
72 if (include_internal || !obj->is_internal())
73 obj->add_on_state_callback([this, obj]() { this->on_time_update(obj); });
74 }
75#endif
76#ifdef USE_DATETIME_DATETIME
77 for (auto *obj : App.get_datetimes()) {
78 if (include_internal || !obj->is_internal())
79 obj->add_on_state_callback([this, obj]() { this->on_datetime_update(obj); });
80 }
81#endif
82#ifdef USE_TEXT
83 for (auto *obj : App.get_texts()) {
84 if (include_internal || !obj->is_internal())
85 obj->add_on_state_callback([this, obj](const std::string &state) { this->on_text_update(obj, state); });
86 }
87#endif
88#ifdef USE_SELECT
89 for (auto *obj : App.get_selects()) {
90 if (include_internal || !obj->is_internal()) {
91 obj->add_on_state_callback(
92 [this, obj](const std::string &state, size_t index) { this->on_select_update(obj, state, index); });
93 }
94 }
95#endif
96#ifdef USE_LOCK
97 for (auto *obj : App.get_locks()) {
98 if (include_internal || !obj->is_internal())
99 obj->add_on_state_callback([this, obj]() { this->on_lock_update(obj); });
100 }
101#endif
102#ifdef USE_VALVE
103 for (auto *obj : App.get_valves()) {
104 if (include_internal || !obj->is_internal())
105 obj->add_on_state_callback([this, obj]() { this->on_valve_update(obj); });
106 }
107#endif
108#ifdef USE_MEDIA_PLAYER
109 for (auto *obj : App.get_media_players()) {
110 if (include_internal || !obj->is_internal())
111 obj->add_on_state_callback([this, obj]() { this->on_media_player_update(obj); });
112 }
113#endif
114#ifdef USE_ALARM_CONTROL_PANEL
115 for (auto *obj : App.get_alarm_control_panels()) {
116 if (include_internal || !obj->is_internal())
117 obj->add_on_state_callback([this, obj]() { this->on_alarm_control_panel_update(obj); });
118 }
119#endif
120#ifdef USE_EVENT
121 for (auto *obj : App.get_events()) {
122 if (include_internal || !obj->is_internal())
123 obj->add_on_event_callback([this, obj](const std::string &event_type) { this->on_event(obj, event_type); });
124 }
125#endif
126#ifdef USE_UPDATE
127 for (auto *obj : App.get_updates()) {
128 if (include_internal || !obj->is_internal())
129 obj->add_on_state_callback([this, obj]() { this->on_update(obj); });
130 }
131#endif
132}
133
134} // namespace esphome
auto & get_binary_sensors() const
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_binary_sensor_update(binary_sensor::BinarySensor *obj)
Definition controller.h:74
virtual void on_cover_update(cover::Cover *obj)
Definition controller.h:89
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.