mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Rename async_resolve_entity_ids to async_validate_entity_ids (#67603)
This commit is contained in:
parent
fbc39d1206
commit
cd25769667
@ -74,7 +74,7 @@ async def async_validate_trigger_config(
|
||||
"""Validate trigger config."""
|
||||
config = _TRIGGER_SCHEMA(config)
|
||||
registry = er.async_get(hass)
|
||||
config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
|
||||
config[CONF_ENTITY_ID] = er.async_validate_entity_ids(
|
||||
registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID])
|
||||
)
|
||||
return config
|
||||
|
@ -77,7 +77,7 @@ async def async_validate_trigger_config(
|
||||
config = TRIGGER_STATE_SCHEMA(config)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
|
||||
config[CONF_ENTITY_ID] = er.async_validate_entity_ids(
|
||||
registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID])
|
||||
)
|
||||
|
||||
|
@ -49,7 +49,7 @@ async def async_validate_trigger_config(
|
||||
"""Validate trigger config."""
|
||||
config = _TRIGGER_SCHEMA(config)
|
||||
registry = er.async_get(hass)
|
||||
config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
|
||||
config[CONF_ENTITY_ID] = er.async_validate_entity_ids(
|
||||
registry, config[CONF_ENTITY_ID]
|
||||
)
|
||||
return config
|
||||
|
@ -897,7 +897,7 @@ def numeric_state_validate_config(
|
||||
|
||||
registry = er.async_get(hass)
|
||||
config = dict(config)
|
||||
config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
|
||||
config[CONF_ENTITY_ID] = er.async_validate_entity_ids(
|
||||
registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID])
|
||||
)
|
||||
return config
|
||||
@ -908,7 +908,7 @@ def state_validate_config(hass: HomeAssistant, config: ConfigType) -> ConfigType
|
||||
|
||||
registry = er.async_get(hass)
|
||||
config = dict(config)
|
||||
config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
|
||||
config[CONF_ENTITY_ID] = er.async_validate_entity_ids(
|
||||
registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID])
|
||||
)
|
||||
return config
|
||||
|
@ -924,13 +924,22 @@ async def async_migrate_entries(
|
||||
|
||||
|
||||
@callback
|
||||
def async_resolve_entity_ids(
|
||||
def async_validate_entity_ids(
|
||||
registry: EntityRegistry, entity_ids_or_uuids: list[str]
|
||||
) -> list[str]:
|
||||
"""Resolve a list of entity ids or UUIDs to a list of entity ids."""
|
||||
"""Validate and resolve a list of entity ids or UUIDs to a list of entity ids.
|
||||
|
||||
def resolve_entity(entity_id_or_uuid: str) -> str | None:
|
||||
"""Resolve an entity id or UUID to an entity id or None."""
|
||||
Returns a list with UUID resolved to entity_ids.
|
||||
Raises vol.Invalid if any item is invalid, or if any a UUID is not associated with
|
||||
an entity registry item.
|
||||
"""
|
||||
|
||||
def async_validate_entity_id(entity_id_or_uuid: str) -> str | None:
|
||||
"""Resolve an entity id or UUID to an entity id.
|
||||
|
||||
Raises vol.Invalid if the entity or UUID is invalid, or if the UUID is not
|
||||
associated with an entity registry item.
|
||||
"""
|
||||
if valid_entity_id(entity_id_or_uuid):
|
||||
return entity_id_or_uuid
|
||||
if (entry := registry.entities.get_entry(entity_id_or_uuid)) is None:
|
||||
@ -940,6 +949,6 @@ def async_resolve_entity_ids(
|
||||
tmp = [
|
||||
resolved_item
|
||||
for item in entity_ids_or_uuids
|
||||
if (resolved_item := resolve_entity(item)) is not None
|
||||
if (resolved_item := async_validate_entity_id(item)) is not None
|
||||
]
|
||||
return tmp
|
||||
|
@ -218,7 +218,7 @@ def async_prepare_call_from_config(
|
||||
|
||||
if CONF_ENTITY_ID in target:
|
||||
registry = entity_registry.async_get(hass)
|
||||
target[CONF_ENTITY_ID] = entity_registry.async_resolve_entity_ids(
|
||||
target[CONF_ENTITY_ID] = entity_registry.async_validate_entity_ids(
|
||||
registry, cv.comp_entity_ids_or_uuids(target[CONF_ENTITY_ID])
|
||||
)
|
||||
except TemplateError as ex:
|
||||
|
@ -1174,19 +1174,19 @@ async def test_resolve_entity_ids(hass, registry):
|
||||
assert entry2.entity_id == "light.milk"
|
||||
|
||||
expected = ["light.beer", "light.milk"]
|
||||
assert er.async_resolve_entity_ids(registry, [entry1.id, entry2.id]) == expected
|
||||
assert er.async_validate_entity_ids(registry, [entry1.id, entry2.id]) == expected
|
||||
|
||||
expected = ["light.beer", "light.milk"]
|
||||
assert er.async_resolve_entity_ids(registry, ["light.beer", entry2.id]) == expected
|
||||
assert er.async_validate_entity_ids(registry, ["light.beer", entry2.id]) == expected
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
er.async_resolve_entity_ids(registry, ["light.beer", "bad_uuid"])
|
||||
er.async_validate_entity_ids(registry, ["light.beer", "bad_uuid"])
|
||||
|
||||
expected = ["light.unknown"]
|
||||
assert er.async_resolve_entity_ids(registry, ["light.unknown"]) == expected
|
||||
assert er.async_validate_entity_ids(registry, ["light.unknown"]) == expected
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
er.async_resolve_entity_ids(registry, ["unknown_uuid"])
|
||||
er.async_validate_entity_ids(registry, ["unknown_uuid"])
|
||||
|
||||
|
||||
def test_entity_registry_items():
|
||||
|
Loading…
x
Reference in New Issue
Block a user