mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 09:38:21 +00:00
Validate selectors in the trigger helper (#149662)
This commit is contained in:
parent
828f979c78
commit
749fc318ca
@ -19,6 +19,7 @@ from homeassistant.const import (
|
|||||||
CONF_ENABLED,
|
CONF_ENABLED,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
|
CONF_SELECTOR,
|
||||||
CONF_VARIABLES,
|
CONF_VARIABLES,
|
||||||
)
|
)
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
@ -41,8 +42,9 @@ from homeassistant.util.hass_dict import HassKey
|
|||||||
from homeassistant.util.yaml import load_yaml_dict
|
from homeassistant.util.yaml import load_yaml_dict
|
||||||
from homeassistant.util.yaml.loader import JSON_TYPE
|
from homeassistant.util.yaml.loader import JSON_TYPE
|
||||||
|
|
||||||
from . import config_validation as cv
|
from . import config_validation as cv, selector
|
||||||
from .integration_platform import async_process_integration_platforms
|
from .integration_platform import async_process_integration_platforms
|
||||||
|
from .selector import TargetSelector
|
||||||
from .template import Template
|
from .template import Template
|
||||||
from .typing import ConfigType, TemplateVarsType
|
from .typing import ConfigType, TemplateVarsType
|
||||||
|
|
||||||
@ -73,12 +75,15 @@ TRIGGERS: HassKey[dict[str, str]] = HassKey("triggers")
|
|||||||
# Basic schemas to sanity check the trigger descriptions,
|
# Basic schemas to sanity check the trigger descriptions,
|
||||||
# full validation is done by hassfest.triggers
|
# full validation is done by hassfest.triggers
|
||||||
_FIELD_SCHEMA = vol.Schema(
|
_FIELD_SCHEMA = vol.Schema(
|
||||||
{},
|
{
|
||||||
|
vol.Optional(CONF_SELECTOR): selector.validate_selector,
|
||||||
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
_TRIGGER_SCHEMA = vol.Schema(
|
_TRIGGER_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
|
vol.Optional("target"): vol.Any(TargetSelector.CONFIG_SCHEMA, None),
|
||||||
vol.Optional("fields"): vol.Schema({str: _FIELD_SCHEMA}),
|
vol.Optional("fields"): vol.Schema({str: _FIELD_SCHEMA}),
|
||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
|
@ -569,7 +569,15 @@ async def test_async_get_all_descriptions(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test async_get_all_descriptions."""
|
"""Test async_get_all_descriptions."""
|
||||||
tag_trigger_descriptions = """
|
tag_trigger_descriptions = """
|
||||||
tag: {}
|
tag:
|
||||||
|
fields:
|
||||||
|
entity:
|
||||||
|
selector:
|
||||||
|
entity:
|
||||||
|
filter:
|
||||||
|
domain: alarm_control_panel
|
||||||
|
supported_features:
|
||||||
|
- alarm_control_panel.AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN_SUN, {})
|
assert await async_setup_component(hass, DOMAIN_SUN, {})
|
||||||
@ -611,9 +619,16 @@ async def test_async_get_all_descriptions(
|
|||||||
"fields": {
|
"fields": {
|
||||||
"event": {
|
"event": {
|
||||||
"example": "sunrise",
|
"example": "sunrise",
|
||||||
"selector": {"select": {"options": ["sunrise", "sunset"]}},
|
"selector": {
|
||||||
|
"select": {
|
||||||
|
"custom_value": False,
|
||||||
|
"multiple": False,
|
||||||
|
"options": ["sunrise", "sunset"],
|
||||||
|
"sort": False,
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"offset": {"selector": {"time": None}},
|
"offset": {"selector": {"time": {}}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,13 +654,35 @@ async def test_async_get_all_descriptions(
|
|||||||
"fields": {
|
"fields": {
|
||||||
"event": {
|
"event": {
|
||||||
"example": "sunrise",
|
"example": "sunrise",
|
||||||
"selector": {"select": {"options": ["sunrise", "sunset"]}},
|
"selector": {
|
||||||
|
"select": {
|
||||||
|
"custom_value": False,
|
||||||
|
"multiple": False,
|
||||||
|
"options": ["sunrise", "sunset"],
|
||||||
|
"sort": False,
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"offset": {"selector": {"time": None}},
|
"offset": {"selector": {"time": {}}},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DOMAIN_TAG: {
|
DOMAIN_TAG: {
|
||||||
"fields": {},
|
"fields": {
|
||||||
|
"entity": {
|
||||||
|
"selector": {
|
||||||
|
"entity": {
|
||||||
|
"filter": [
|
||||||
|
{
|
||||||
|
"domain": ["alarm_control_panel"],
|
||||||
|
"supported_features": [1],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"multiple": False,
|
||||||
|
"reorder": False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user