|
ESPHome 2026.3.0-dev
|
Global registry for Controllers to receive entity state updates. More...
#include <controller_registry.h>
Protected Types | |
| using | DispatchFunc = void (*)(Controller *, void *) |
| Type-erased dispatch function pointer. | |
Static Protected Member Functions | |
| static void | __attribute__ ((noinline)) notify(void *obj |
| Shared dispatch loop - iterates controllers and calls dispatch for each. | |
Protected Attributes | |
| static void DispatchFunc | dispatch |
Static Protected Attributes | |
| static StaticVector< Controller *, CONTROLLER_REGISTRY_MAX > | controllers |
Global registry for Controllers to receive entity state updates.
This singleton registry allows Controllers (APIServer, WebServer) to receive entity state change notifications without storing per-entity callbacks.
Instead of each entity maintaining controller callbacks (32 bytes overhead per entity), entities call ControllerRegistry::notify_*_update() which iterates the small list of registered controllers (typically 2: API and WebServer).
Controllers read state directly from entities using existing accessors (obj->state, etc.) rather than receiving it as callback parameters that were being ignored anyway.
Memory savings: 32 bytes per entity (2 controllers × 16 bytes std::function overhead) Typical config (25 entities): ~780 bytes saved Large config (80 entities): ~2,540 bytes saved
Definition at line 156 of file controller_registry.h.
|
protected |
Type-erased dispatch function pointer.
Each notify method passes a small trampoline that calls the correct virtual method on Controller. The shared notify() loop iterates controllers once, calling the trampoline for each.
Definition at line 256 of file controller_registry.h.
|
staticprotected |
Shared dispatch loop - iterates controllers and calls dispatch for each.
Marked noinline to ensure only one copy of the loop exists in flash, rather than being duplicated into each notify_*_update wrapper.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Register a controller to receive entity state updates.
Controllers should call this in their setup() method. Typically only APIServer and WebServer register.
Definition at line 11 of file controller_registry.cpp.
|
staticprotected |
Definition at line 265 of file controller_registry.h.
|
protected |
Definition at line 263 of file controller_registry.h.