diff --git a/homeassistant/helpers/llm.py b/homeassistant/helpers/llm.py index 177e3735bc0..4c8e2df06a4 100644 --- a/homeassistant/helpers/llm.py +++ b/homeassistant/helpers/llm.py @@ -324,8 +324,7 @@ class AssistAPI(API): ( "When controlling Home Assistant always call the intent tools. " "Use HassTurnOn to lock and HassTurnOff to unlock a lock. " - "When controlling a device, prefer passing just its name and its domain " - "(what comes before the dot in its entity id). " + "When controlling a device, prefer passing just name and domain. " "When controlling an area, prefer passing just area name and domain." ) ] @@ -363,7 +362,7 @@ class AssistAPI(API): prompt.append( "An overview of the areas and the devices in this smart home:" ) - prompt.append(yaml.dump(exposed_entities)) + prompt.append(yaml.dump(list(exposed_entities.values()))) return "\n".join(prompt) @@ -477,6 +476,7 @@ def _get_exposed_entities( info: dict[str, Any] = { "names": ", ".join(names), + "domain": state.domain, "state": state.state, } diff --git a/tests/helpers/test_llm.py b/tests/helpers/test_llm.py index e1f55942d10..3ad5b23b731 100644 --- a/tests/helpers/test_llm.py +++ b/tests/helpers/test_llm.py @@ -22,7 +22,6 @@ from homeassistant.helpers import ( selector, ) from homeassistant.setup import async_setup_component -from homeassistant.util import yaml from tests.common import MockConfigEntry @@ -506,74 +505,58 @@ async def test_assist_api_prompt( suggested_area="Test Area 2", ) ) - - exposed_entities = llm._get_exposed_entities(hass, llm_context.assistant) - assert exposed_entities == { - "light.1": { - "areas": "Test Area 2", - "names": "1", - "state": "unavailable", - }, - entry1.entity_id: { - "names": "Kitchen", - "state": "on", - "attributes": {"temperature": "0.9", "humidity": "65"}, - }, - entry2.entity_id: { - "areas": "Test Area, Alternative name", - "names": "Living Room", - "state": "on", - }, - "light.test_device": { - "areas": "Test Area, Alternative name", - "names": "Test Device", - "state": "unavailable", - }, - "light.test_device_2": { - "areas": "Test Area 2", - "names": "Test Device 2", - "state": "unavailable", - }, - "light.test_device_3": { - "areas": "Test Area 2", - "names": "Test Device 3", - "state": "unavailable", - }, - "light.test_device_4": { - "areas": "Test Area 2", - "names": "Test Device 4", - "state": "unavailable", - }, - "light.test_service": { - "areas": "Test Area, Alternative name", - "names": "Test Service", - "state": "unavailable", - }, - "light.test_service_2": { - "areas": "Test Area, Alternative name", - "names": "Test Service", - "state": "unavailable", - }, - "light.test_service_3": { - "areas": "Test Area, Alternative name", - "names": "Test Service", - "state": "unavailable", - }, - "light.unnamed_device": { - "areas": "Test Area 2", - "names": "Unnamed Device", - "state": "unavailable", - }, - } - exposed_entities_prompt = ( - "An overview of the areas and the devices in this smart home:\n" - + yaml.dump(exposed_entities) - ) + exposed_entities_prompt = """An overview of the areas and the devices in this smart home: +- names: Kitchen + domain: light + state: 'on' + attributes: + temperature: '0.9' + humidity: '65' +- names: Living Room + domain: light + state: 'on' + areas: Test Area, Alternative name +- names: Test Device + domain: light + state: unavailable + areas: Test Area, Alternative name +- names: Test Service + domain: light + state: unavailable + areas: Test Area, Alternative name +- names: Test Service + domain: light + state: unavailable + areas: Test Area, Alternative name +- names: Test Service + domain: light + state: unavailable + areas: Test Area, Alternative name +- names: Test Device 2 + domain: light + state: unavailable + areas: Test Area 2 +- names: Test Device 3 + domain: light + state: unavailable + areas: Test Area 2 +- names: Test Device 4 + domain: light + state: unavailable + areas: Test Area 2 +- names: Unnamed Device + domain: light + state: unavailable + areas: Test Area 2 +- names: '1' + domain: light + state: unavailable + areas: Test Area 2 +""" first_part_prompt = ( "When controlling Home Assistant always call the intent tools. " "Use HassTurnOn to lock and HassTurnOff to unlock a lock. " - "When controlling a device, prefer passing just its name and its domain " - "(what comes before the dot in its entity id). " + "When controlling a device, prefer passing just name and domain. " "When controlling an area, prefer passing just area name and domain." ) no_timer_prompt = "This device is not able to start timers."