mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Send entity name or original name to LCN frontend (#124518)
* Send name or original name to frontend * Use walrus operator * Fix docstring * Fix mutated config_entry.data
This commit is contained in:
parent
221f961574
commit
36b7e8569e
@ -158,7 +158,13 @@ async def websocket_get_entity_configs(
|
|||||||
else:
|
else:
|
||||||
entity_configs = config_entry.data[CONF_ENTITIES]
|
entity_configs = config_entry.data[CONF_ENTITIES]
|
||||||
|
|
||||||
connection.send_result(msg["id"], entity_configs)
|
result_entity_configs = [
|
||||||
|
{**entity_config, CONF_NAME: entity.name or entity.original_name}
|
||||||
|
for entity_config in entity_configs[:]
|
||||||
|
if (entity := get_entity_entry(hass, entity_config, config_entry)) is not None
|
||||||
|
]
|
||||||
|
|
||||||
|
connection.send_result(msg["id"], result_entity_configs)
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.require_admin
|
@websocket_api.require_admin
|
||||||
@ -438,3 +444,23 @@ async def async_create_or_update_device_in_config_entry(
|
|||||||
await async_update_device_config(device_connection, device_config)
|
await async_update_device_config(device_connection, device_config)
|
||||||
|
|
||||||
hass.config_entries.async_update_entry(config_entry, data=data)
|
hass.config_entries.async_update_entry(config_entry, data=data)
|
||||||
|
|
||||||
|
|
||||||
|
def get_entity_entry(
|
||||||
|
hass: HomeAssistant, entity_config: dict, config_entry: ConfigEntry
|
||||||
|
) -> er.RegistryEntry | None:
|
||||||
|
"""Get entity RegistryEntry from entity_config."""
|
||||||
|
entity_registry = er.async_get(hass)
|
||||||
|
domain_name = entity_config[CONF_DOMAIN]
|
||||||
|
domain_data = entity_config[CONF_DOMAIN_DATA]
|
||||||
|
resource = get_resource(domain_name, domain_data).lower()
|
||||||
|
unique_id = generate_unique_id(
|
||||||
|
config_entry.entry_id,
|
||||||
|
entity_config[CONF_ADDRESS],
|
||||||
|
resource,
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
entity_id := entity_registry.async_get_entity_id(domain_name, DOMAIN, unique_id)
|
||||||
|
) is None:
|
||||||
|
return None
|
||||||
|
return entity_registry.async_get(entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user