diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index 84c9e36002..08753b0f2d 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -48,6 +48,9 @@ if TYPE_CHECKING: _LOGGER = logging.getLogger(__name__) +# Key for tracking controller count in CORE.data for ControllerRegistry StaticVector sizing +KEY_CONTROLLER_REGISTRY_COUNT = "controller_registry_count" + class EsphomeError(Exception): """General ESPHome exception occurred.""" @@ -912,8 +915,8 @@ class EsphomeCore: def register_controller(self) -> None: """Track registration of a Controller for ControllerRegistry StaticVector sizing.""" - controller_count = self.data.setdefault("controller_registry_count", 0) - self.data["controller_registry_count"] = controller_count + 1 + controller_count = self.data.setdefault(KEY_CONTROLLER_REGISTRY_COUNT, 0) + self.data[KEY_CONTROLLER_REGISTRY_COUNT] = controller_count + 1 @property def cpp_main_section(self): diff --git a/esphome/core/config.py b/esphome/core/config.py index 3d98eda8bb..ce94ec11f2 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -40,7 +40,12 @@ from esphome.const import ( PlatformFramework, __version__ as ESPHOME_VERSION, ) -from esphome.core import CORE, CoroPriority, coroutine_with_priority +from esphome.core import ( + CORE, + KEY_CONTROLLER_REGISTRY_COUNT, + CoroPriority, + coroutine_with_priority, +) from esphome.helpers import ( copy_file_if_changed, fnv1a_32bit_hash, @@ -465,7 +470,7 @@ async def _add_platform_defines() -> None: @coroutine_with_priority(CoroPriority.FINAL) async def _add_controller_registry_define() -> None: # Generate StaticVector size for ControllerRegistry - controller_count = CORE.data.get("controller_registry_count", 0) + controller_count = CORE.data.get(KEY_CONTROLLER_REGISTRY_COUNT, 0) if controller_count > 0: cg.add_define("USE_CONTROLLER_REGISTRY") cg.add_define("CONTROLLER_REGISTRY_MAX", controller_count)