From 7fdcbe0687e544f760d082a2b43e92bcb4425c4e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 20 Oct 2025 08:11:41 -1000 Subject: [PATCH] [core] Fix crash when config keys contain periods during platform detection --- esphome/core/config.py | 3 +- tests/unit_tests/core/test_config.py | 49 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/esphome/core/config.py b/esphome/core/config.py index 8a5876dbcf..8301ea0adf 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -318,7 +318,8 @@ def preload_core_config(config, result) -> str: target_platforms = [] for domain in config: - if domain.startswith("."): + # Skip package keys which may contain periods (e.g., "ratgdo.esphome") + if "." in domain: continue if _is_target_platform(domain): target_platforms += [domain] diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index 4fddfc9678..9f7f373b3f 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -476,6 +476,55 @@ def test_preload_core_config_multiple_platforms(setup_core: Path) -> None: preload_core_config(config, result) +def test_preload_core_config_skips_package_keys_with_periods(setup_core: Path) -> None: + """Test preload_core_config skips package keys containing periods. + + Package keys can contain periods (e.g., "ratgdo.esphome") and should be + skipped when searching for target platforms to avoid triggering the + assertion in get_component() that component names cannot contain periods. + + Regression test for: https://github.com/esphome/esphome/issues/11182 + """ + config = { + CONF_ESPHOME: { + CONF_NAME: "test_device", + }, + "esp32": {}, + # Package key with period should be ignored + "ratgdo.esphome": "github://ratgdo/esphome-ratgdo/v32disco_secplusv1.yaml", + } + result = {} + + # Should not raise AssertionError from get_component() + platform = preload_core_config(config, result) + + assert platform == "esp32" + assert CORE.name == "test_device" + + +def test_preload_core_config_skips_keys_starting_with_period(setup_core: Path) -> None: + """Test preload_core_config skips keys starting with period. + + Keys starting with "." are special ESPHome internal keys and should be + skipped when searching for target platforms. + """ + config = { + CONF_ESPHOME: { + CONF_NAME: "test_device", + }, + "esp8266": {}, + # Internal key starting with period should be ignored + ".platformio_options": {"board_build.flash_mode": "dout"}, + } + result = {} + + # Should not raise any errors + platform = preload_core_config(config, result) + + assert platform == "esp8266" + assert CORE.name == "test_device" + + def test_include_file_header(tmp_path: Path, mock_copy_file_if_changed: Mock) -> None: """Test include_file adds include statement for header files.""" src_file = tmp_path / "source.h"