mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 07:16:11 +08:00
[core] Fix CORE.raw_config not updated after package merge (#12456)
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
Stale / stale (push) Has been cancelled
Lock closed issues and PRs / lock (push) Has been cancelled
Publish Release / Initialize build (push) Has been cancelled
Publish Release / Build and publish to PyPi (push) Has been cancelled
Publish Release / Build ESPHome amd64 (push) Has been cancelled
Publish Release / Build ESPHome arm64 (push) Has been cancelled
Publish Release / Publish ESPHome docker to dockerhub (push) Has been cancelled
Publish Release / Publish ESPHome docker to ghcr (push) Has been cancelled
Publish Release / Publish ESPHome ha-addon to dockerhub (push) Has been cancelled
Publish Release / Publish ESPHome ha-addon to ghcr (push) Has been cancelled
Publish Release / deploy-ha-addon-repo (push) Has been cancelled
Publish Release / deploy-esphome-schema (push) Has been cancelled
Publish Release / version-notifier (push) Has been cancelled
Synchronise Device Classes from Home Assistant / Sync Device Classes (push) Has been cancelled
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
Stale / stale (push) Has been cancelled
Lock closed issues and PRs / lock (push) Has been cancelled
Publish Release / Initialize build (push) Has been cancelled
Publish Release / Build and publish to PyPi (push) Has been cancelled
Publish Release / Build ESPHome amd64 (push) Has been cancelled
Publish Release / Build ESPHome arm64 (push) Has been cancelled
Publish Release / Publish ESPHome docker to dockerhub (push) Has been cancelled
Publish Release / Publish ESPHome docker to ghcr (push) Has been cancelled
Publish Release / Publish ESPHome ha-addon to dockerhub (push) Has been cancelled
Publish Release / Publish ESPHome ha-addon to ghcr (push) Has been cancelled
Publish Release / deploy-ha-addon-repo (push) Has been cancelled
Publish Release / deploy-esphome-schema (push) Has been cancelled
Publish Release / version-notifier (push) Has been cancelled
Synchronise Device Classes from Home Assistant / Sync Device Classes (push) Has been cancelled
This commit is contained in:
+2
-2
@@ -1010,14 +1010,14 @@ def validate_config(
|
|||||||
result.add_error(err)
|
result.add_error(err)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
CORE.raw_config = config
|
|
||||||
|
|
||||||
# 1.1. Merge packages
|
# 1.1. Merge packages
|
||||||
if CONF_PACKAGES in config:
|
if CONF_PACKAGES in config:
|
||||||
from esphome.components.packages import merge_packages
|
from esphome.components.packages import merge_packages
|
||||||
|
|
||||||
config = merge_packages(config)
|
config = merge_packages(config)
|
||||||
|
|
||||||
|
CORE.raw_config = config
|
||||||
|
|
||||||
# 1.2. Resolve !extend and !remove and check for REPLACEME
|
# 1.2. Resolve !extend and !remove and check for REPLACEME
|
||||||
# After this step, there will not be any Extend or Remove values in the config anymore
|
# After this step, there will not be any Extend or Remove values in the config anymore
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from esphome.components.packages import CONFIG_SCHEMA, do_packages_pass, merge_packages
|
from esphome.components.packages import CONFIG_SCHEMA, do_packages_pass, merge_packages
|
||||||
|
import esphome.config as config_module
|
||||||
from esphome.config import resolve_extend_remove
|
from esphome.config import resolve_extend_remove
|
||||||
from esphome.config_helpers import Extend, Remove
|
from esphome.config_helpers import Extend, Remove
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
@@ -33,6 +34,7 @@ from esphome.const import (
|
|||||||
CONF_VARS,
|
CONF_VARS,
|
||||||
CONF_WIFI,
|
CONF_WIFI,
|
||||||
)
|
)
|
||||||
|
from esphome.core import CORE
|
||||||
from esphome.util import OrderedDict
|
from esphome.util import OrderedDict
|
||||||
|
|
||||||
# Test strings
|
# Test strings
|
||||||
@@ -991,3 +993,35 @@ def test_package_merge_invalid(invalid_package) -> None:
|
|||||||
|
|
||||||
with pytest.raises(cv.Invalid):
|
with pytest.raises(cv.Invalid):
|
||||||
merge_packages(config)
|
merge_packages(config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_raw_config_contains_merged_esphome_from_package(tmp_path) -> None:
|
||||||
|
"""Test that CORE.raw_config contains esphome section from merged package.
|
||||||
|
|
||||||
|
This is a regression test for the bug where CORE.raw_config was set before
|
||||||
|
packages were merged, causing KeyError when components accessed
|
||||||
|
CORE.raw_config[CONF_ESPHOME] and the esphome section came from a package.
|
||||||
|
"""
|
||||||
|
# Create a config where esphome section comes from a package
|
||||||
|
test_config = OrderedDict()
|
||||||
|
test_config[CONF_PACKAGES] = {
|
||||||
|
"base": {
|
||||||
|
CONF_ESPHOME: {CONF_NAME: TEST_DEVICE_NAME},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test_config["esp32"] = {"board": "esp32dev"}
|
||||||
|
|
||||||
|
# Set up CORE for the test
|
||||||
|
test_yaml = tmp_path / "test.yaml"
|
||||||
|
test_yaml.write_text("# test config")
|
||||||
|
CORE.reset()
|
||||||
|
CORE.config_path = test_yaml
|
||||||
|
|
||||||
|
# Call validate_config - this should merge packages and set CORE.raw_config
|
||||||
|
config_module.validate_config(test_config, {})
|
||||||
|
|
||||||
|
# Verify that CORE.raw_config contains the esphome section from the package
|
||||||
|
assert CONF_ESPHOME in CORE.raw_config, (
|
||||||
|
"CORE.raw_config should contain esphome section after package merge"
|
||||||
|
)
|
||||||
|
assert CORE.raw_config[CONF_ESPHOME][CONF_NAME] == TEST_DEVICE_NAME
|
||||||
|
|||||||
Reference in New Issue
Block a user