Compare commits

...

10 Commits

Author SHA1 Message Date
Abílio Costa
f45b8eb0bc Merge branch 'dev' into llm_device_name 2025-10-24 00:29:37 +02:00
Abílio Costa
61b06c5cee Merge branch 'dev' into llm_device_name 2025-10-17 19:33:21 +01:00
abmantis
d599524880 Remove device name when its part of the entity name 2025-10-16 18:52:26 +01:00
abmantis
7c6c6ff7ff Merge branch 'dev' of github.com:home-assistant/core into llm_device_name 2025-10-16 18:27:36 +01:00
Abílio Costa
4b343c10a5 Merge branch 'dev' into llm_device_name 2025-10-06 17:35:37 +01:00
Abílio Costa
5532570dae Merge branch 'dev' into llm_device_name 2025-09-29 14:18:59 +01:00
Abílio Costa
5bd912c730 Merge branch 'dev' into llm_device_name 2025-09-24 11:50:37 +01:00
Abílio Costa
ad9efd6429 Merge branch 'dev' into llm_device_name 2025-09-22 10:29:46 +01:00
abmantis
3b59a03dfa Add device name to llm exposed entities info 2025-09-22 00:57:35 +01:00
abmantis
78bf54de42 Remove unused var from llm helper 2025-09-22 00:55:48 +01:00
2 changed files with 22 additions and 6 deletions

View File

@@ -660,19 +660,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)
@@ -693,6 +701,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 and not state.name.lower().startswith(device_name.lower()):
info["device"] = device_name
if area_names: if area_names:
info["areas"] = ", ".join(area_names) info["areas"] = ", ".join(area_names)

View File

@@ -458,6 +458,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(
@@ -575,9 +576,9 @@ async def test_assist_api_prompt(
device_registry.async_get_or_create( device_registry.async_get_or_create(
config_entry_id=entry.entry_id, config_entry_id=entry.entry_id,
connections={("test", "9876-integer-values")}, connections={("test", "9876-integer-values")},
name=1, name="1",
manufacturer=2, manufacturer="2",
model=3, model="3",
suggested_area="Test Area 2", suggested_area="Test Area 2",
) )
) )
@@ -595,10 +596,12 @@ 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
@@ -637,9 +640,11 @@ async def test_assist_api_prompt(
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