mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add support for entity aliases to Google Assistant (#84405)
This commit is contained in:
parent
0d874899ea
commit
1f0ea73463
@ -52,7 +52,11 @@ LOCAL_SDK_MIN_VERSION = AwesomeVersion("2.1.5")
|
||||
@callback
|
||||
def _get_registry_entries(
|
||||
hass: HomeAssistant, entity_id: str
|
||||
) -> tuple[device_registry.DeviceEntry | None, area_registry.AreaEntry | None]:
|
||||
) -> tuple[
|
||||
entity_registry.RegistryEntry | None,
|
||||
device_registry.DeviceEntry | None,
|
||||
area_registry.AreaEntry | None,
|
||||
]:
|
||||
"""Get registry entries."""
|
||||
ent_reg = entity_registry.async_get(hass)
|
||||
dev_reg = device_registry.async_get(hass)
|
||||
@ -75,7 +79,7 @@ def _get_registry_entries(
|
||||
else:
|
||||
area_entry = None
|
||||
|
||||
return device_entry, area_entry
|
||||
return entity_entry, device_entry, area_entry
|
||||
|
||||
|
||||
class AbstractConfig(ABC):
|
||||
@ -588,7 +592,9 @@ class GoogleEntity:
|
||||
name = (entity_config.get(CONF_NAME) or state.name).strip()
|
||||
|
||||
# Find entity/device/area registry entries
|
||||
device_entry, area_entry = _get_registry_entries(self.hass, self.entity_id)
|
||||
entity_entry, device_entry, area_entry = _get_registry_entries(
|
||||
self.hass, self.entity_id
|
||||
)
|
||||
|
||||
# Build the device info
|
||||
device = {
|
||||
@ -603,8 +609,12 @@ class GoogleEntity:
|
||||
}
|
||||
|
||||
# Add aliases
|
||||
if aliases := entity_config.get(CONF_ALIASES):
|
||||
device["name"]["nicknames"] = [name] + aliases
|
||||
if (config_aliases := entity_config.get(CONF_ALIASES, [])) or (
|
||||
entity_entry and entity_entry.aliases
|
||||
):
|
||||
device["name"]["nicknames"] = [name] + config_aliases
|
||||
if entity_entry:
|
||||
device["name"]["nicknames"].extend(entity_entry.aliases)
|
||||
|
||||
# Add local SDK info if enabled
|
||||
if self.config.is_local_sdk_active and self.should_expose_local():
|
||||
|
@ -3,6 +3,7 @@ import asyncio
|
||||
from unittest.mock import ANY, call, patch
|
||||
|
||||
import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.climate import ATTR_MAX_TEMP, ATTR_MIN_TEMP, HVACMode
|
||||
@ -101,10 +102,21 @@ async def test_async_handle_message(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_sync_message(hass):
|
||||
async def test_sync_message(hass, registries):
|
||||
"""Test a sync message."""
|
||||
entity = registries.entity.async_get_or_create(
|
||||
"light",
|
||||
"test",
|
||||
"unique-demo-light",
|
||||
suggested_object_id="demo_light",
|
||||
)
|
||||
registries.entity.async_update_entity(
|
||||
entity.entity_id,
|
||||
aliases={"Stay", "Healthy"},
|
||||
)
|
||||
|
||||
light = DemoLight(
|
||||
None,
|
||||
"unique-demo-light",
|
||||
"Demo Light",
|
||||
state=False,
|
||||
hs_color=(180, 75),
|
||||
@ -150,7 +162,15 @@ async def test_sync_message(hass):
|
||||
"id": "light.demo_light",
|
||||
"name": {
|
||||
"name": "Demo Light",
|
||||
"nicknames": ["Demo Light", "Hello", "World"],
|
||||
"nicknames": unordered(
|
||||
[
|
||||
"Demo Light",
|
||||
"Hello",
|
||||
"World",
|
||||
"Stay",
|
||||
"Healthy",
|
||||
]
|
||||
),
|
||||
},
|
||||
"traits": [
|
||||
trait.TRAIT_BRIGHTNESS,
|
||||
@ -181,7 +201,10 @@ async def test_sync_message(hass):
|
||||
{
|
||||
"setting_name": "none",
|
||||
"setting_values": [
|
||||
{"lang": "en", "setting_synonym": ["none"]}
|
||||
{
|
||||
"lang": "en",
|
||||
"setting_synonym": ["none"],
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user