ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
controller_registry.cpp
Go to the documentation of this file.
2
3#ifdef USE_CONTROLLER_REGISTRY
4
6
7namespace esphome {
8
9StaticVector<Controller *, CONTROLLER_REGISTRY_MAX> ControllerRegistry::controllers;
10
11void ControllerRegistry::register_controller(Controller *controller) { controllers.push_back(controller); }
12
13void ControllerRegistry::notify(void *obj, DispatchFunc dispatch) {
14 for (auto *controller : controllers) {
15 dispatch(controller, obj);
16 }
17}
18
19// Macro for standard registry notification dispatch - calls on_<entity_name>_update()
20// Each wrapper passes a small trampoline lambda that calls the correct virtual method.
21// NOLINTBEGIN(bugprone-macro-parentheses)
22#define CONTROLLER_REGISTRY_NOTIFY(entity_type, entity_name) \
23 void ControllerRegistry::notify_##entity_name##_update(entity_type *obj) { \
24 notify(obj, [](Controller *c, void *o) { c->on_##entity_name##_update(static_cast<entity_type *>(o)); }); \
25 }
26
27// Macro for entities where controller method has no "_update" suffix (Event, Update)
28#define CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(entity_type, entity_name) \
29 void ControllerRegistry::notify_##entity_name(entity_type *obj) { \
30 notify(obj, [](Controller *c, void *o) { c->on_##entity_name(static_cast<entity_type *>(o)); }); \
31 }
32// NOLINTEND(bugprone-macro-parentheses)
33
34#ifdef USE_BINARY_SENSOR
35CONTROLLER_REGISTRY_NOTIFY(binary_sensor::BinarySensor, binary_sensor)
36#endif
37
38#ifdef USE_FAN
39CONTROLLER_REGISTRY_NOTIFY(fan::Fan, fan)
40#endif
41
42#ifdef USE_LIGHT
43CONTROLLER_REGISTRY_NOTIFY(light::LightState, light)
44#endif
45
46#ifdef USE_SENSOR
47CONTROLLER_REGISTRY_NOTIFY(sensor::Sensor, sensor)
48#endif
49
50#ifdef USE_SWITCH
51CONTROLLER_REGISTRY_NOTIFY(switch_::Switch, switch)
52#endif
53
54#ifdef USE_COVER
55CONTROLLER_REGISTRY_NOTIFY(cover::Cover, cover)
56#endif
57
58#ifdef USE_TEXT_SENSOR
59CONTROLLER_REGISTRY_NOTIFY(text_sensor::TextSensor, text_sensor)
60#endif
61
62#ifdef USE_CLIMATE
63CONTROLLER_REGISTRY_NOTIFY(climate::Climate, climate)
64#endif
65
66#ifdef USE_NUMBER
67CONTROLLER_REGISTRY_NOTIFY(number::Number, number)
68#endif
69
70#ifdef USE_DATETIME_DATE
71CONTROLLER_REGISTRY_NOTIFY(datetime::DateEntity, date)
72#endif
73
74#ifdef USE_DATETIME_TIME
75CONTROLLER_REGISTRY_NOTIFY(datetime::TimeEntity, time)
76#endif
77
78#ifdef USE_DATETIME_DATETIME
79CONTROLLER_REGISTRY_NOTIFY(datetime::DateTimeEntity, datetime)
80#endif
81
82#ifdef USE_TEXT
83CONTROLLER_REGISTRY_NOTIFY(text::Text, text)
84#endif
85
86#ifdef USE_SELECT
87CONTROLLER_REGISTRY_NOTIFY(select::Select, select)
88#endif
89
90#ifdef USE_LOCK
91CONTROLLER_REGISTRY_NOTIFY(lock::Lock, lock)
92#endif
93
94#ifdef USE_VALVE
95CONTROLLER_REGISTRY_NOTIFY(valve::Valve, valve)
96#endif
97
98#ifdef USE_MEDIA_PLAYER
99CONTROLLER_REGISTRY_NOTIFY(media_player::MediaPlayer, media_player)
100#endif
101
102#ifdef USE_ALARM_CONTROL_PANEL
103CONTROLLER_REGISTRY_NOTIFY(alarm_control_panel::AlarmControlPanel, alarm_control_panel)
104#endif
105
106#ifdef USE_WATER_HEATER
107CONTROLLER_REGISTRY_NOTIFY(water_heater::WaterHeater, water_heater)
108#endif
109
110#ifdef USE_EVENT
111CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(event::Event, event)
112#endif
113
114#ifdef USE_UPDATE
115CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(update::UpdateEntity, update)
116#endif
117
118#undef CONTROLLER_REGISTRY_NOTIFY
119#undef CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX
120
121} // namespace esphome
122
123#endif // USE_CONTROLLER_REGISTRY
static void DispatchFunc dispatch
static void register_controller(Controller *controller)
Register a controller to receive entity state updates.
static StaticVector< Controller *, CONTROLLER_REGISTRY_MAX > controllers
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7