Compare commits

...
2 changed files with 22 additions and 6 deletions
+14 -3
View File
@@ -660,19 +660,27 @@ def _get_exposed_entities(
entity_entry = entity_registry.async_get(state.entity_id)
names = [state.name]
device_name = None
area_names = []
if entity_entry is not None:
names.extend(entity_entry.aliases)
device = (
device_registry.async_get(entity_entry.device_id)
if entity_entry.device_id
else None
)
if device:
device_name = device.name_by_user or device.name
if entity_entry.area_id and (
area := area_registry.async_get_area(entity_entry.area_id)
):
# Entity is in area
area_names.append(area.name)
area_names.extend(area.aliases)
elif entity_entry.device_id and (
device := device_registry.async_get(entity_entry.device_id)
):
elif device:
# Check device area
if device.area_id and (
area := area_registry.async_get_area(device.area_id)
@@ -693,6 +701,9 @@ def _get_exposed_entities(
if (parsed_utc := dt_util.parse_datetime(state.state)) is not None:
info["state"] = dt_util.as_local(parsed_utc).isoformat()
if device_name and not state.name.lower().startswith(device_name.lower()):
info["device"] = device_name
if area_names:
info["areas"] = ", ".join(area_names)
+8 -3
View File
@@ -458,6 +458,7 @@ async def test_assist_api_prompt(
connections={("test", "1234")},
suggested_area="Test Area",
)
device_registry.async_update_device(device.id, name_by_user="Friendly Device")
area = area_registry.async_get_area_by_name("Test Area")
area_registry.async_update(area.id, aliases=["Alternative name"])
entry1 = entity_registry.async_get_or_create(
@@ -575,9 +576,9 @@ async def test_assist_api_prompt(
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
connections={("test", "9876-integer-values")},
name=1,
manufacturer=2,
model=3,
name="1",
manufacturer="2",
model="3",
suggested_area="Test Area 2",
)
)
@@ -595,10 +596,12 @@ async def test_assist_api_prompt(
- names: Living Room
domain: light
state: 'on'
device: Friendly Device
areas: Test Area, Alternative name
- names: Test Device, my test light
domain: light
state: unavailable
device: Friendly Device
areas: Test Area, Alternative name
- names: Test Device 2
domain: light
@@ -637,9 +640,11 @@ async def test_assist_api_prompt(
domain: light
- names: Living Room
domain: light
device: Friendly Device
areas: Test Area, Alternative name
- names: Test Device, my test light
domain: light
device: Friendly Device
areas: Test Area, Alternative name
- names: Test Device 2
domain: light