[core] Dispatch controller updates through generated direct calls (#19588)

This commit is contained in:
J. Nick Koston
2026-09-24 17:24:10 +00:00
committed by GitHub
parent 9df7e825d3
commit 211fd3ce54
23 changed files with 178 additions and 181 deletions
-2
View File
@@ -1,5 +1,4 @@
import esphome.codegen as cg
from esphome.core import CORE
from tests.testing_helpers import ComponentManifestOverride
@@ -12,6 +11,5 @@ def override_manifest(manifest: ComponentManifestOverride) -> None:
cg.add_define("API_MAX_SEND_QUEUE", 8)
cg.add_define("MAX_API_CONNECTIONS", 1)
cg.add_define("USE_SOCKET_IMPL_BSD_SOCKETS")
CORE.register_controller() # api_server registers with the controller registry
manifest.to_code = to_code_testing
+31 -1
View File
@@ -9,6 +9,7 @@ from unittest.mock import MagicMock, Mock, patch
import pytest
from esphome import config_validation as cv, core
import esphome.codegen as cg
from esphome.components.safe_mode import to_code as safe_mode_to_code
from esphome.const import (
CONF_AREA,
@@ -23,7 +24,7 @@ from esphome.const import (
KEY_TARGET_PLATFORM,
Toolchain,
)
from esphome.core import CORE, config
from esphome.core import CORE, KEY_CONTROLLER_REGISTRY_CONTROLLERS, config
from esphome.core.config import (
Area,
make_app_name_cpp,
@@ -455,6 +456,35 @@ async def test_add_looping_components_with_entries() -> None:
assert "(1 * HasLoopOverride<esphome::logger::Logger>::value)" in text
@pytest.mark.asyncio
async def test_add_controller_registry_dispatch_without_controllers() -> None:
"""Nothing is emitted when no controller registered."""
CORE.data.pop(KEY_CONTROLLER_REGISTRY_CONTROLLERS, None)
await config._add_controller_registry_dispatch()
assert "USE_CONTROLLER_REGISTRY" not in {d.name for d in CORE.defines}
assert not [s for s in CORE.global_statements if "controller" in str(s)]
@pytest.mark.asyncio
async def test_add_controller_registry_dispatch_with_controllers() -> None:
"""Registered controllers become one tuple plus the dispatch include."""
CORE.register_controller(cg.MockObj("api_apiserver_id"))
CORE.register_controller(cg.MockObj("web_server_webserver_id"))
await config._add_controller_registry_dispatch()
assert "USE_CONTROLLER_REGISTRY" in {d.name for d in CORE.defines}
statements = [str(s) for s in CORE.global_statements]
assert "#include <tuple>" in statements
assert (
"static auto esphome_controllers() { return std::tuple{api_apiserver_id, web_server_webserver_id}; }"
in statements
)
assert '#include "esphome/core/controller_dispatch.h"' in statements
def test_valid_include_with_angle_brackets() -> None:
"""Test valid_include accepts angle bracket includes."""
assert valid_include("<ArduinoJson.h>") == "<ArduinoJson.h>"
-1
View File
@@ -70,7 +70,6 @@ from esphome.cpp_generator import _extract_component_ns
"arduino_json_ns",
"JsonObject",
"JsonObjectConst",
"Controller",
"GPIOPin",
),
)