ESPHome 2025.12.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
13// Macro for standard registry notification dispatch - calls on_<entity_name>_update()
14#define CONTROLLER_REGISTRY_NOTIFY(entity_type, entity_name) \
15 void ControllerRegistry::notify_##entity_name##_update(entity_type *obj) { /* NOLINT(bugprone-macro-parentheses) */ \
16 for (auto *controller : controllers) { \
17 controller->on_##entity_name##_update(obj); \
18 } \
19 }
20
21// Macro for entities where controller method has no "_update" suffix (Event, Update)
22#define CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(entity_type, entity_name) \
23 void ControllerRegistry::notify_##entity_name(entity_type *obj) { /* NOLINT(bugprone-macro-parentheses) */ \
24 for (auto *controller : controllers) { \
25 controller->on_##entity_name(obj); \
26 } \
27 }
28
29#ifdef USE_BINARY_SENSOR
30CONTROLLER_REGISTRY_NOTIFY(binary_sensor::BinarySensor, binary_sensor)
31#endif
32
33#ifdef USE_FAN
34CONTROLLER_REGISTRY_NOTIFY(fan::Fan, fan)
35#endif
36
37#ifdef USE_LIGHT
38CONTROLLER_REGISTRY_NOTIFY(light::LightState, light)
39#endif
40
41#ifdef USE_SENSOR
42CONTROLLER_REGISTRY_NOTIFY(sensor::Sensor, sensor)
43#endif
44
45#ifdef USE_SWITCH
46CONTROLLER_REGISTRY_NOTIFY(switch_::Switch, switch)
47#endif
48
49#ifdef USE_COVER
50CONTROLLER_REGISTRY_NOTIFY(cover::Cover, cover)
51#endif
52
53#ifdef USE_TEXT_SENSOR
54CONTROLLER_REGISTRY_NOTIFY(text_sensor::TextSensor, text_sensor)
55#endif
56
57#ifdef USE_CLIMATE
58CONTROLLER_REGISTRY_NOTIFY(climate::Climate, climate)
59#endif
60
61#ifdef USE_NUMBER
62CONTROLLER_REGISTRY_NOTIFY(number::Number, number)
63#endif
64
65#ifdef USE_DATETIME_DATE
66CONTROLLER_REGISTRY_NOTIFY(datetime::DateEntity, date)
67#endif
68
69#ifdef USE_DATETIME_TIME
70CONTROLLER_REGISTRY_NOTIFY(datetime::TimeEntity, time)
71#endif
72
73#ifdef USE_DATETIME_DATETIME
74CONTROLLER_REGISTRY_NOTIFY(datetime::DateTimeEntity, datetime)
75#endif
76
77#ifdef USE_TEXT
78CONTROLLER_REGISTRY_NOTIFY(text::Text, text)
79#endif
80
81#ifdef USE_SELECT
82CONTROLLER_REGISTRY_NOTIFY(select::Select, select)
83#endif
84
85#ifdef USE_LOCK
86CONTROLLER_REGISTRY_NOTIFY(lock::Lock, lock)
87#endif
88
89#ifdef USE_VALVE
90CONTROLLER_REGISTRY_NOTIFY(valve::Valve, valve)
91#endif
92
93#ifdef USE_MEDIA_PLAYER
94CONTROLLER_REGISTRY_NOTIFY(media_player::MediaPlayer, media_player)
95#endif
96
97#ifdef USE_ALARM_CONTROL_PANEL
98CONTROLLER_REGISTRY_NOTIFY(alarm_control_panel::AlarmControlPanel, alarm_control_panel)
99#endif
100
101#ifdef USE_EVENT
102CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(event::Event, event)
103#endif
104
105#ifdef USE_UPDATE
106CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX(update::UpdateEntity, update)
107#endif
108
109#undef CONTROLLER_REGISTRY_NOTIFY
110#undef CONTROLLER_REGISTRY_NOTIFY_NO_UPDATE_SUFFIX
111
112} // namespace esphome
113
114#endif // USE_CONTROLLER_REGISTRY
static void register_controller(Controller *controller)
Register a controller to receive entity state updates.
static StaticVector< Controller *, CONTROLLER_REGISTRY_MAX > controllers
Base class for all binary_sensor-type classes.
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:178
Base class for all cover devices.
Definition cover.h:112
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:69
Base class for all locks.
Definition lock.h:109
Base-class for all numbers.
Definition number.h:30
Base-class for all selects.
Definition select.h:31
Base-class for all sensors.
Definition sensor.h:42
Base class for all switches.
Definition switch.h:39
Base-class for all text inputs.
Definition text.h:24
Base class for all valve devices.
Definition valve.h:105
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7