mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 19:09:32 +00:00
Add device name to llm exposed entities info
This commit is contained in:
@@ -658,19 +658,27 @@ def _get_exposed_entities(
|
|||||||
|
|
||||||
entity_entry = entity_registry.async_get(state.entity_id)
|
entity_entry = entity_registry.async_get(state.entity_id)
|
||||||
names = [state.name]
|
names = [state.name]
|
||||||
|
device_name = None
|
||||||
area_names = []
|
area_names = []
|
||||||
|
|
||||||
if entity_entry is not None:
|
if entity_entry is not None:
|
||||||
names.extend(entity_entry.aliases)
|
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 (
|
if entity_entry.area_id and (
|
||||||
area := area_registry.async_get_area(entity_entry.area_id)
|
area := area_registry.async_get_area(entity_entry.area_id)
|
||||||
):
|
):
|
||||||
# Entity is in area
|
# Entity is in area
|
||||||
area_names.append(area.name)
|
area_names.append(area.name)
|
||||||
area_names.extend(area.aliases)
|
area_names.extend(area.aliases)
|
||||||
elif entity_entry.device_id and (
|
elif device:
|
||||||
device := device_registry.async_get(entity_entry.device_id)
|
|
||||||
):
|
|
||||||
# Check device area
|
# Check device area
|
||||||
if device.area_id and (
|
if device.area_id and (
|
||||||
area := area_registry.async_get_area(device.area_id)
|
area := area_registry.async_get_area(device.area_id)
|
||||||
@@ -691,6 +699,9 @@ def _get_exposed_entities(
|
|||||||
if (parsed_utc := dt_util.parse_datetime(state.state)) is not None:
|
if (parsed_utc := dt_util.parse_datetime(state.state)) is not None:
|
||||||
info["state"] = dt_util.as_local(parsed_utc).isoformat()
|
info["state"] = dt_util.as_local(parsed_utc).isoformat()
|
||||||
|
|
||||||
|
if device_name:
|
||||||
|
info["device"] = device_name
|
||||||
|
|
||||||
if area_names:
|
if area_names:
|
||||||
info["areas"] = ", ".join(area_names)
|
info["areas"] = ", ".join(area_names)
|
||||||
|
|
||||||
|
|||||||
@@ -453,6 +453,7 @@ async def test_assist_api_prompt(
|
|||||||
connections={("test", "1234")},
|
connections={("test", "1234")},
|
||||||
suggested_area="Test Area",
|
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 = area_registry.async_get_area_by_name("Test Area")
|
||||||
area_registry.async_update(area.id, aliases=["Alternative name"])
|
area_registry.async_update(area.id, aliases=["Alternative name"])
|
||||||
entry1 = entity_registry.async_get_or_create(
|
entry1 = entity_registry.async_get_or_create(
|
||||||
@@ -580,6 +581,7 @@ async def test_assist_api_prompt(
|
|||||||
- names: '1'
|
- names: '1'
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: 1
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Kitchen
|
- names: Kitchen
|
||||||
domain: light
|
domain: light
|
||||||
@@ -590,34 +592,42 @@ async def test_assist_api_prompt(
|
|||||||
- names: Living Room
|
- names: Living Room
|
||||||
domain: light
|
domain: light
|
||||||
state: 'on'
|
state: 'on'
|
||||||
|
device: Friendly Device
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Device, my test light
|
- names: Test Device, my test light
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Friendly Device
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Device 2
|
- names: Test Device 2
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Device 2
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Device 3
|
- names: Test Device 3
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Device 3
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Device 4
|
- names: Test Device 4
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Device 4
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
state: unavailable
|
state: unavailable
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Unnamed Device
|
- names: Unnamed Device
|
||||||
domain: light
|
domain: light
|
||||||
@@ -627,32 +637,41 @@ async def test_assist_api_prompt(
|
|||||||
stateless_exposed_entities_prompt = """Static Context: An overview of the areas and the devices in this smart home:
|
stateless_exposed_entities_prompt = """Static Context: An overview of the areas and the devices in this smart home:
|
||||||
- names: '1'
|
- names: '1'
|
||||||
domain: light
|
domain: light
|
||||||
|
device: 1
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Kitchen
|
- names: Kitchen
|
||||||
domain: light
|
domain: light
|
||||||
- names: Living Room
|
- names: Living Room
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Friendly Device
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Device, my test light
|
- names: Test Device, my test light
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Friendly Device
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Device 2
|
- names: Test Device 2
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Device 2
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Device 3
|
- names: Test Device 3
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Device 3
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Device 4
|
- names: Test Device 4
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Device 4
|
||||||
areas: Test Area 2
|
areas: Test Area 2
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Test Service
|
- names: Test Service
|
||||||
domain: light
|
domain: light
|
||||||
|
device: Test Service
|
||||||
areas: Test Area, Alternative name
|
areas: Test Area, Alternative name
|
||||||
- names: Unnamed Device
|
- names: Unnamed Device
|
||||||
domain: light
|
domain: light
|
||||||
|
|||||||
Reference in New Issue
Block a user