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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user