This commit is contained in:
J. Nick Koston
2025-11-07 16:38:32 -06:00
parent 0962024d99
commit ac85949f17
2 changed files with 12 additions and 4 deletions
+5 -2
View File
@@ -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):
+7 -2
View File
@@ -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)