mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Check config to use config platforms (#43407)
This commit is contained in:
parent
d3f952f831
commit
390668e192
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user