mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Teach call service script action about entity registry ids (#61172)
This commit is contained in:
@@ -311,6 +311,12 @@ comp_entity_ids = vol.Any(
|
||||
)
|
||||
|
||||
|
||||
comp_entity_ids_or_uuids = vol.Any(
|
||||
vol.All(vol.Lower, vol.Any(ENTITY_MATCH_ALL, ENTITY_MATCH_NONE)),
|
||||
entity_ids_or_uuids,
|
||||
)
|
||||
|
||||
|
||||
def entity_domain(domain: str | list[str]) -> Callable[[Any], str]:
|
||||
"""Validate that entity belong to domain."""
|
||||
ent_domain = entities_domain(domain)
|
||||
@@ -972,6 +978,23 @@ ENTITY_SERVICE_FIELDS = {
|
||||
),
|
||||
}
|
||||
|
||||
TARGET_SERVICE_FIELDS = {
|
||||
# Same as ENTITY_SERVICE_FIELDS but supports specifying entity by entity registry
|
||||
# ID.
|
||||
# Either accept static entity IDs, a single dynamic template or a mixed list
|
||||
# of static and dynamic templates. While this could be solved with a single
|
||||
# complex template, handling it like this, keeps config validation useful.
|
||||
vol.Optional(ATTR_ENTITY_ID): vol.Any(
|
||||
comp_entity_ids_or_uuids, dynamic_template, vol.All(list, template_complex)
|
||||
),
|
||||
vol.Optional(ATTR_DEVICE_ID): vol.Any(
|
||||
ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)])
|
||||
),
|
||||
vol.Optional(ATTR_AREA_ID): vol.Any(
|
||||
ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)])
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def make_entity_service_schema(
|
||||
schema: dict, *, extra: int = vol.PREVENT_EXTRA
|
||||
@@ -1034,7 +1057,7 @@ SERVICE_SCHEMA = vol.All(
|
||||
template, vol.All(dict, template_complex)
|
||||
),
|
||||
vol.Optional(CONF_ENTITY_ID): comp_entity_ids,
|
||||
vol.Optional(CONF_TARGET): vol.Any(ENTITY_SERVICE_FIELDS, dynamic_template),
|
||||
vol.Optional(CONF_TARGET): vol.Any(TARGET_SERVICE_FIELDS, dynamic_template),
|
||||
}
|
||||
),
|
||||
has_at_least_one_key(CONF_SERVICE, CONF_SERVICE_TEMPLATE),
|
||||
|
||||
Reference in New Issue
Block a user