Improve trigger schema validation to ask for trigger instead of platform (#126750)

* Add check for missing trigger

* Fix

* Fix

* Escape
This commit is contained in:
Joost Lekkerkerker 2024-09-25 16:44:14 +02:00 committed by GitHub
parent f4c339db8c
commit 3810c3cbaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 9 deletions

View file

@ -1771,7 +1771,7 @@ CONDITION_ACTION_SCHEMA: vol.Schema = vol.Schema(
)
def _backward_compat_trigger_schema(value: Any | None) -> Any:
def _trigger_pre_validator(value: Any | None) -> Any:
"""Rewrite trigger `trigger` to `platform`.
`platform` has been renamed to `trigger` in user documentation and in the automation
@ -1790,6 +1790,8 @@ def _backward_compat_trigger_schema(value: Any | None) -> Any:
)
value = dict(value)
value[CONF_PLATFORM] = value.pop(CONF_TRIGGER)
elif CONF_PLATFORM not in value:
raise vol.Invalid("required key not provided", [CONF_TRIGGER])
return value
@ -1831,7 +1833,7 @@ def _base_trigger_validator(value: Any) -> Any:
TRIGGER_SCHEMA = vol.All(
ensure_list,
_base_trigger_list_flatten,
[vol.All(_backward_compat_trigger_schema, _base_trigger_validator)],
[vol.All(_trigger_pre_validator, _base_trigger_validator)],
)
_SCRIPT_DELAY_SCHEMA = vol.Schema(