ESPHome 2026.4.0
Loading...
Searching...
No Matches
controller_registry.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_CONTROLLER_REGISTRY
6
8
9// Forward declarations
10namespace esphome {
11
12class Controller;
13
14#ifdef USE_BINARY_SENSOR
15namespace binary_sensor {
16class BinarySensor;
17}
18#endif
19
20#ifdef USE_FAN
21namespace fan {
22class Fan;
23}
24#endif
25
26#ifdef USE_LIGHT
27namespace light {
28class LightState;
29}
30#endif
31
32#ifdef USE_SENSOR
33namespace sensor {
34class Sensor;
35}
36#endif
37
38#ifdef USE_SWITCH
39namespace switch_ {
40class Switch;
41}
42#endif
43
44#ifdef USE_COVER
45namespace cover {
46class Cover;
47}
48#endif
49
50#ifdef USE_TEXT_SENSOR
51namespace text_sensor {
52class TextSensor;
53}
54#endif
55
56#ifdef USE_CLIMATE
57namespace climate {
58class Climate;
59}
60#endif
61
62#ifdef USE_NUMBER
63namespace number {
64class Number;
65}
66#endif
67
68#ifdef USE_DATETIME_DATE
69namespace datetime {
70class DateEntity;
71}
72#endif
73
74#ifdef USE_DATETIME_TIME
75namespace datetime {
76class TimeEntity;
77}
78#endif
79
80#ifdef USE_DATETIME_DATETIME
81namespace datetime {
82class DateTimeEntity;
83}
84#endif
85
86#ifdef USE_TEXT
87namespace text {
88class Text;
89}
90#endif
91
92#ifdef USE_SELECT
93namespace select {
94class Select;
95}
96#endif
97
98#ifdef USE_LOCK
99namespace lock {
100class Lock;
101}
102#endif
103
104#ifdef USE_VALVE
105namespace valve {
106class Valve;
107}
108#endif
109
110#ifdef USE_MEDIA_PLAYER
111namespace media_player {
112class MediaPlayer;
113}
114#endif
115
116#ifdef USE_ALARM_CONTROL_PANEL
117namespace alarm_control_panel {
118class AlarmControlPanel;
119}
120#endif
121
122#ifdef USE_WATER_HEATER
123namespace water_heater {
124class WaterHeater;
125}
126#endif
127
128#ifdef USE_EVENT
129namespace event {
130class Event;
131}
132#endif
133
134#ifdef USE_UPDATE
135namespace update {
136class UpdateEntity;
137}
138#endif
139
157 public:
163 static void register_controller(Controller *controller);
164
165#ifdef USE_BINARY_SENSOR
167#endif
168
169#ifdef USE_FAN
170 static void notify_fan_update(fan::Fan *obj);
171#endif
172
173#ifdef USE_LIGHT
175#endif
176
177#ifdef USE_SENSOR
179#endif
180
181#ifdef USE_SWITCH
183#endif
184
185#ifdef USE_COVER
187#endif
188
189#ifdef USE_TEXT_SENSOR
191#endif
192
193#ifdef USE_CLIMATE
195#endif
196
197#ifdef USE_NUMBER
199#endif
200
201#ifdef USE_DATETIME_DATE
203#endif
204
205#ifdef USE_DATETIME_TIME
207#endif
208
209#ifdef USE_DATETIME_DATETIME
211#endif
212
213#ifdef USE_TEXT
215#endif
216
217#ifdef USE_SELECT
219#endif
220
221#ifdef USE_LOCK
223#endif
224
225#ifdef USE_VALVE
227#endif
228
229#ifdef USE_MEDIA_PLAYER
231#endif
232
233#ifdef USE_ALARM_CONTROL_PANEL
235#endif
236
237#ifdef USE_WATER_HEATER
239#endif
240
241#ifdef USE_EVENT
242 static void notify_event(event::Event *obj);
243#endif
244
245#ifdef USE_UPDATE
247#endif
248
249 protected:
251};
252
253} // namespace esphome
254
255// Include controller.h AFTER the class definition so notify methods can be
256// defined inline. This is safe because controller_registry.h is only ever
257// included from .cpp files, never from other headers.
259
260namespace esphome {
261
262// Inline notify methods — each is a tiny loop over 1-2 controllers.
263// Defining them here (rather than in controller_registry.cpp) allows the
264// compiler to inline them into the single call site in each entity's
265// notify_frontend_(), eliminating an unnecessary function-call frame.
266
267// NOLINTBEGIN(bugprone-macro-parentheses)
268#define CONTROLLER_REGISTRY_NOTIFY(entity_type, entity_name) \
269 inline void ControllerRegistry::notify_##entity_name##_update(entity_type *obj) { \
270 for (auto *controller : controllers) { \
271 controller->on_##entity_name##_update(obj); \
272 } \
273 }
274
275#define CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(entity_type, entity_name) \
276 inline void ControllerRegistry::notify_##entity_name(entity_type *obj) { \
277 for (auto *controller : controllers) { \
278 controller->on_##entity_name(obj); \
279 } \
280 }
281// NOLINTEND(bugprone-macro-parentheses)
282
283#ifdef USE_BINARY_SENSOR
284CONTROLLER_REGISTRY_NOTIFY(binary_sensor::BinarySensor, binary_sensor)
285#endif
286
287#ifdef USE_FAN
288CONTROLLER_REGISTRY_NOTIFY(fan::Fan, fan)
289#endif
290
291#ifdef USE_LIGHT
292CONTROLLER_REGISTRY_NOTIFY(light::LightState, light)
293#endif
294
295#ifdef USE_SENSOR
296CONTROLLER_REGISTRY_NOTIFY(sensor::Sensor, sensor)
297#endif
298
299#ifdef USE_SWITCH
300CONTROLLER_REGISTRY_NOTIFY(switch_::Switch, switch)
301#endif
302
303#ifdef USE_COVER
304CONTROLLER_REGISTRY_NOTIFY(cover::Cover, cover)
305#endif
306
307#ifdef USE_TEXT_SENSOR
308CONTROLLER_REGISTRY_NOTIFY(text_sensor::TextSensor, text_sensor)
309#endif
310
311#ifdef USE_CLIMATE
312CONTROLLER_REGISTRY_NOTIFY(climate::Climate, climate)
313#endif
314
315#ifdef USE_NUMBER
316CONTROLLER_REGISTRY_NOTIFY(number::Number, number)
317#endif
318
319#ifdef USE_DATETIME_DATE
320CONTROLLER_REGISTRY_NOTIFY(datetime::DateEntity, date)
321#endif
322
323#ifdef USE_DATETIME_TIME
324CONTROLLER_REGISTRY_NOTIFY(datetime::TimeEntity, time)
325#endif
326
327#ifdef USE_DATETIME_DATETIME
328CONTROLLER_REGISTRY_NOTIFY(datetime::DateTimeEntity, datetime)
329#endif
330
331#ifdef USE_TEXT
332CONTROLLER_REGISTRY_NOTIFY(text::Text, text)
333#endif
334
335#ifdef USE_SELECT
336CONTROLLER_REGISTRY_NOTIFY(select::Select, select)
337#endif
338
339#ifdef USE_LOCK
340CONTROLLER_REGISTRY_NOTIFY(lock::Lock, lock)
341#endif
342
343#ifdef USE_VALVE
344CONTROLLER_REGISTRY_NOTIFY(valve::Valve, valve)
345#endif
346
347#ifdef USE_MEDIA_PLAYER
348CONTROLLER_REGISTRY_NOTIFY(media_player::MediaPlayer, media_player)
349#endif
350
351#ifdef USE_ALARM_CONTROL_PANEL
352CONTROLLER_REGISTRY_NOTIFY(alarm_control_panel::AlarmControlPanel, alarm_control_panel)
353#endif
354
355#ifdef USE_WATER_HEATER
356CONTROLLER_REGISTRY_NOTIFY(water_heater::WaterHeater, water_heater)
357#endif
358
359#ifdef USE_EVENT
360CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(event::Event, event)
361#endif
362
363#ifdef USE_UPDATE
364CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(update::UpdateEntity, update)
365#endif
366
367#undef CONTROLLER_REGISTRY_NOTIFY
368#undef CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX
369
370} // namespace esphome
371
372#endif // USE_CONTROLLER_REGISTRY
Global registry for Controllers to receive entity state updates.
static void notify_select_update(select::Select *obj)
static void notify_binary_sensor_update(binary_sensor::BinarySensor *obj)
static void notify_datetime_update(datetime::DateTimeEntity *obj)
static void notify_cover_update(cover::Cover *obj)
static void notify_date_update(datetime::DateEntity *obj)
static void notify_event(event::Event *obj)
static void notify_lock_update(lock::Lock *obj)
static void notify_time_update(datetime::TimeEntity *obj)
static void notify_update(update::UpdateEntity *obj)
static void notify_sensor_update(sensor::Sensor *obj)
static void notify_text_update(text::Text *obj)
static void notify_light_update(light::LightState *obj)
static void notify_number_update(number::Number *obj)
static void notify_valve_update(valve::Valve *obj)
static void notify_text_sensor_update(text_sensor::TextSensor *obj)
static void notify_media_player_update(media_player::MediaPlayer *obj)
static void notify_alarm_control_panel_update(alarm_control_panel::AlarmControlPanel *obj)
static void notify_water_heater_update(water_heater::WaterHeater *obj)
static void register_controller(Controller *controller)
Register a controller to receive entity state updates.
static void notify_climate_update(climate::Climate *obj)
static void notify_fan_update(fan::Fan *obj)
static StaticVector< Controller *, CONTROLLER_REGISTRY_MAX > controllers
static void notify_switch_update(switch_::Switch *obj)
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:210
Base class for all binary_sensor-type classes.
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:187
Base class for all cover devices.
Definition cover.h:110
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
Base class for all locks.
Definition lock.h:110
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:29
Base-class for all sensors.
Definition sensor.h:47
Base class for all switches.
Definition switch.h:38
Base-class for all text inputs.
Definition text.h:21
Base class for all valve devices.
Definition valve.h:104
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7