diff --git a/homeassistant/components/automation/config.py b/homeassistant/components/automation/config.py index ae12554b89d..ed801772e6d 100644 --- a/homeassistant/components/automation/config.py +++ b/homeassistant/components/automation/config.py @@ -41,8 +41,6 @@ from .helpers import async_get_blueprints PACKAGE_MERGE_HINT = "list" -_CONDITION_SCHEMA = vol.All(cv.ensure_list, [cv.CONDITION_SCHEMA]) - _MINIMAL_PLATFORM_SCHEMA = vol.Schema( { CONF_ID: str, @@ -65,7 +63,7 @@ PLATFORM_SCHEMA = vol.All( vol.Optional(CONF_INITIAL_STATE): cv.boolean, vol.Optional(CONF_HIDE_ENTITY): cv.boolean, vol.Required(CONF_TRIGGER): cv.TRIGGER_SCHEMA, - vol.Optional(CONF_CONDITION): _CONDITION_SCHEMA, + vol.Optional(CONF_CONDITION): cv.CONDITIONS_SCHEMA, vol.Optional(CONF_VARIABLES): cv.SCRIPT_VARIABLES_SCHEMA, vol.Optional(CONF_TRIGGER_VARIABLES): cv.SCRIPT_VARIABLES_SCHEMA, vol.Required(CONF_ACTION): cv.SCRIPT_SCHEMA, diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index ee76ec17ba4..619fc913e09 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -725,14 +725,14 @@ async def handle_validate_config( for key, schema, validator in ( ("trigger", cv.TRIGGER_SCHEMA, trigger.async_validate_trigger_config), - ("condition", cv.CONDITION_SCHEMA, condition.async_validate_condition_config), + ("condition", cv.CONDITIONS_SCHEMA, condition.async_validate_conditions_config), ("action", cv.SCRIPT_SCHEMA, script.async_validate_actions_config), ): if key not in msg: continue try: - await validator(hass, schema(msg[key])) # type: ignore[operator] + await validator(hass, schema(msg[key])) except vol.Invalid as err: result[key] = {"valid": False, "error": str(err)} else: diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 3c07ecea00f..cea8a866f5c 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -1527,6 +1527,7 @@ CONDITION_SCHEMA: vol.Schema = vol.Schema( ) ) +CONDITIONS_SCHEMA = vol.All(ensure_list, [CONDITION_SCHEMA]) dynamic_template_condition_action = vol.All( # Wrap a shorthand template condition action in a template condition diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 0916aaf46e4..c8f494a0071 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -1823,11 +1823,17 @@ async def test_integration_setup_info( ("key", "config"), ( ("trigger", {"platform": "event", "event_type": "hello"}), + ("trigger", [{"platform": "event", "event_type": "hello"}]), ( "condition", {"condition": "state", "entity_id": "hello.world", "state": "paulus"}, ), + ( + "condition", + [{"condition": "state", "entity_id": "hello.world", "state": "paulus"}], + ), ("action", {"service": "domain_test.test_service"}), + ("action", [{"service": "domain_test.test_service"}]), ), ) async def test_validate_config_works(websocket_client, key, config) -> None: @@ -1858,7 +1864,8 @@ async def test_validate_config_works(websocket_client, key, config) -> None: }, ( "Unexpected value for condition: 'non_existing'. Expected and, device," - " not, numeric_state, or, state, sun, template, time, trigger, zone" + " not, numeric_state, or, state, sun, template, time, trigger, zone " + "@ data[0]" ), ), (