mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add config flow for switch.light (#67447)
* Add config flow for switch.light * Refactor according to code review * Setup light switch from config entry * Improve async_resolve_entity * Prepare for multiple steps * Remove name and options flow from switch light * Check type before adding description to schema keys * Remove options flow enabler * Copy name from the switch * Move helper flows to new file * Improve test coverage * Fix name * Remove dead code from abstract method * Remove manifest 'helper' option * Validate registry entry id before forwarding to light platform * Improve test * Add translations * Improve config entry setup * Log when config entry fails setup * Update homeassistant/components/switch/__init__.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
@@ -923,6 +923,20 @@ async def async_migrate_entries(
|
||||
ent_reg.async_update_entity(entry.entity_id, **updates)
|
||||
|
||||
|
||||
@callback
|
||||
def async_validate_entity_id(registry: EntityRegistry, entity_id_or_uuid: str) -> str:
|
||||
"""Validate and 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:
|
||||
raise vol.Invalid(f"Unknown entity registry entry {entity_id_or_uuid}")
|
||||
return entry.entity_id
|
||||
|
||||
|
||||
@callback
|
||||
def async_validate_entity_ids(
|
||||
registry: EntityRegistry, entity_ids_or_uuids: list[str]
|
||||
@@ -934,21 +948,4 @@ def async_validate_entity_ids(
|
||||
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:
|
||||
raise vol.Invalid(f"Unknown entity registry entry {entity_id_or_uuid}")
|
||||
return entry.entity_id
|
||||
|
||||
tmp = [
|
||||
resolved_item
|
||||
for item in entity_ids_or_uuids
|
||||
if (resolved_item := async_validate_entity_id(item)) is not None
|
||||
]
|
||||
return tmp
|
||||
return [async_validate_entity_id(registry, item) for item in entity_ids_or_uuids]
|
||||
|
||||
Reference in New Issue
Block a user