From 0ba2531ca4ef613115125359670b97a482106e02 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 20 Jul 2023 11:45:44 +0200 Subject: [PATCH] Fix bug in check_config when an integration is removed by its own validator (#96068) * Raise if present is False * Fix feedback * Update homeassistant/helpers/check_config.py Co-authored-by: Erik Montnemery * Update homeassistant/helpers/check_config.py Co-authored-by: Erik Montnemery * Fix tests --------- Co-authored-by: Erik Montnemery --- homeassistant/helpers/check_config.py | 4 +++- tests/helpers/test_check_config.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index 21a54d64728..ba69a76fbdd 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -181,7 +181,9 @@ async def async_check_ha_config_file( # noqa: C901 if config_schema is not None: try: config = config_schema(config) - result[domain] = config[domain] + # Don't fail if the validator removed the domain from the config + if domain in config: + result[domain] = config[domain] except vol.Invalid as ex: _comp_error(ex, domain, config) continue diff --git a/tests/helpers/test_check_config.py b/tests/helpers/test_check_config.py index 91ef17d526d..3b9b3cf6558 100644 --- a/tests/helpers/test_check_config.py +++ b/tests/helpers/test_check_config.py @@ -8,9 +8,10 @@ from homeassistant.helpers.check_config import ( CheckConfigError, async_check_ha_config_file, ) +import homeassistant.helpers.config_validation as cv from homeassistant.requirements import RequirementsNotFound -from tests.common import mock_platform, patch_yaml_files +from tests.common import MockModule, mock_integration, mock_platform, patch_yaml_files _LOGGER = logging.getLogger(__name__) @@ -246,3 +247,20 @@ bla: assert err.domain == "bla" assert err.message == "Unexpected error calling config validator: Broken" assert err.config == {"value": 1} + + +async def test_removed_yaml_support(hass: HomeAssistant) -> None: + """Test config validation check with removed CONFIG_SCHEMA without raise if present.""" + mock_integration( + hass, + MockModule( + domain="bla", config_schema=cv.removed("bla", raise_if_present=False) + ), + False, + ) + files = {YAML_CONFIG_FILE: BASE_CONFIG + "bla:\n platform: demo"} + with patch("os.path.isfile", return_value=True), patch_yaml_files(files): + res = await async_check_ha_config_file(hass) + log_ha_config(res) + + assert res.keys() == {"homeassistant"}