1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 07:45:56 +00:00

[core] Implement Global Controller Registry to reduce RAM usage (#11772)

This commit is contained in:
J. Nick Koston
2025-11-09 17:34:08 -06:00
committed by GitHub
parent 1dabe83d04
commit 7abb6d4998
33 changed files with 583 additions and 198 deletions

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,
@@ -462,6 +467,15 @@ async def _add_platform_defines() -> None:
cg.add_define(f"USE_{platform_name.upper()}")
@coroutine_with_priority(CoroPriority.FINAL)
async def _add_controller_registry_define() -> None:
# Generate StaticVector size for ControllerRegistry
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)
@coroutine_with_priority(CoroPriority.CORE)
async def to_code(config: ConfigType) -> None:
cg.add_global(cg.global_ns.namespace("esphome").using)
@@ -483,6 +497,7 @@ async def to_code(config: ConfigType) -> None:
cg.add_define("ESPHOME_COMPONENT_COUNT", len(CORE.component_ids))
CORE.add_job(_add_platform_defines)
CORE.add_job(_add_controller_registry_define)
CORE.add_job(_add_automations, config)