Validate selectors in the trigger helper (#149662)

This commit is contained in:
Artur Pragacz 2025-07-30 14:22:55 +02:00 committed by GitHub
parent 828f979c78
commit 749fc318ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 8 deletions

View File

@ -19,6 +19,7 @@ from homeassistant.const import (
CONF_ENABLED,
CONF_ID,
CONF_PLATFORM,
CONF_SELECTOR,
CONF_VARIABLES,
)
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.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 .selector import TargetSelector
from .template import Template
from .typing import ConfigType, TemplateVarsType
@ -73,12 +75,15 @@ TRIGGERS: HassKey[dict[str, str]] = HassKey("triggers")
# Basic schemas to sanity check the trigger descriptions,
# full validation is done by hassfest.triggers
_FIELD_SCHEMA = vol.Schema(
{},
{
vol.Optional(CONF_SELECTOR): selector.validate_selector,
},
extra=vol.ALLOW_EXTRA,
)
_TRIGGER_SCHEMA = vol.Schema(
{
vol.Optional("target"): vol.Any(TargetSelector.CONFIG_SCHEMA, None),
vol.Optional("fields"): vol.Schema({str: _FIELD_SCHEMA}),
},
extra=vol.ALLOW_EXTRA,

View File

@ -569,7 +569,15 @@ async def test_async_get_all_descriptions(
) -> None:
"""Test async_get_all_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, {})
@ -611,9 +619,16 @@ async def test_async_get_all_descriptions(
"fields": {
"event": {
"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": {
"event": {
"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: {
"fields": {},
"fields": {
"entity": {
"selector": {
"entity": {
"filter": [
{
"domain": ["alarm_control_panel"],
"supported_features": [1],
}
],
"multiple": False,
"reorder": False,
},
},
},
}
},
}