From 390668e192b99b111e4c135a54989db30d32e875 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 19 Nov 2020 22:05:36 +0100 Subject: [PATCH] Check config to use config platforms (#43407) --- homeassistant/helpers/check_config.py | 26 +++++++++++++++++++++ tests/helpers/test_check_config.py | 33 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index 7b71b7aae2b..018bbe5cfe0 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -123,6 +123,32 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig result.add_error(f"Component error: {domain} - {ex}") continue + # Check if the integration has a custom config validator + config_validator = None + try: + config_validator = integration.get_platform("config") + except ImportError as err: + # Filter out import error of the config platform. + # If the config platform contains bad imports, make sure + # that still fails. + if err.name != f"{integration.pkg_path}.config": + result.add_error(f"Error importing config platform {domain}: {err}") + continue + + if config_validator is not None and hasattr( + config_validator, "async_validate_config" + ): + try: + return await config_validator.async_validate_config( # type: ignore + hass, config + ) + except (vol.Invalid, HomeAssistantError) as ex: + _comp_error(ex, domain, config) + continue + except Exception: # pylint: disable=broad-except + result.add_error("Unknown error calling %s config validator", domain) + continue + config_schema = getattr(component, "CONFIG_SCHEMA", None) if config_schema is not None: try: diff --git a/tests/helpers/test_check_config.py b/tests/helpers/test_check_config.py index ffc05544694..786fa986a14 100644 --- a/tests/helpers/test_check_config.py +++ b/tests/helpers/test_check_config.py @@ -133,3 +133,36 @@ async def test_bootstrap_error(hass, loop): # Only 1 error expected res.errors.pop(0) assert not res.errors + + +async def test_automation_config_platform(hass): + """Test automation async config.""" + files = { + YAML_CONFIG_FILE: BASE_CONFIG + + """ +automation: + use_blueprint: + path: test_event_service.yaml + input: + trigger_event: blueprint_event + service_to_call: test.automation +""", + hass.config.path( + "blueprints/automation/test_event_service.yaml" + ): """ +blueprint: + name: "Call service based on event" + domain: automation + input: + trigger_event: + service_to_call: +trigger: + platform: event + event_type: !placeholder trigger_event +action: + service: !placeholder service_to_call +""", + } + with patch("os.path.isfile", return_value=True), patch_yaml_files(files): + res = await async_check_ha_config_file(hass) + assert len(res["automation"]) == 1