mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Add a GetHomeState tool to return the current state of the home (#140971)
* Add a GetHomeState tool to return the current state of the home * Fix check for exposing entities * Add "all" to get home state description
This commit is contained in:
@@ -181,19 +181,19 @@ async def test_assist_api(
|
||||
|
||||
assert len(llm.async_get_apis(hass)) == 1
|
||||
api = await llm.async_get_api(hass, "assist", llm_context)
|
||||
assert len(api.tools) == 0
|
||||
assert [tool.name for tool in api.tools] == ["get_home_state"]
|
||||
|
||||
# Match all
|
||||
intent_handler.platforms = None
|
||||
|
||||
api = await llm.async_get_api(hass, "assist", llm_context)
|
||||
assert len(api.tools) == 1
|
||||
assert [tool.name for tool in api.tools] == ["test_intent", "get_home_state"]
|
||||
|
||||
# Match specific domain
|
||||
intent_handler.platforms = {"light"}
|
||||
|
||||
api = await llm.async_get_api(hass, "assist", llm_context)
|
||||
assert len(api.tools) == 1
|
||||
assert len(api.tools) == 2
|
||||
tool = api.tools[0]
|
||||
assert tool.name == "test_intent"
|
||||
assert tool.description == "Execute Home Assistant test_intent intent"
|
||||
@@ -643,6 +643,15 @@ async def test_assist_api_prompt(
|
||||
{exposed_entities_prompt}"""
|
||||
)
|
||||
|
||||
# Verify that the get_home_state tool returns the same results as the exposed_entities_prompt
|
||||
result = await api.async_call_tool(
|
||||
llm.ToolInput(tool_name="get_home_state", tool_args={})
|
||||
)
|
||||
assert result == {
|
||||
"success": True,
|
||||
"result": exposed_entities_prompt,
|
||||
}
|
||||
|
||||
# Fake that request is made from a specific device ID with an area
|
||||
llm_context.device_id = device.id
|
||||
area_prompt = (
|
||||
@@ -1267,3 +1276,19 @@ async def test_calendar_get_events_tool(hass: HomeAssistant) -> None:
|
||||
"start_date_time": now,
|
||||
"end_date_time": dt_util.start_of_local_day() + timedelta(days=7),
|
||||
}
|
||||
|
||||
|
||||
async def test_no_tools_exposed(hass: HomeAssistant) -> None:
|
||||
"""Test that tools are not exposed when no entities are exposed."""
|
||||
assert await async_setup_component(hass, "homeassistant", {})
|
||||
context = Context()
|
||||
llm_context = llm.LLMContext(
|
||||
platform="test_platform",
|
||||
context=context,
|
||||
user_prompt="test_text",
|
||||
language="*",
|
||||
assistant="conversation",
|
||||
device_id=None,
|
||||
)
|
||||
api = await llm.async_get_api(hass, "assist", llm_context)
|
||||
assert api.tools == []
|
||||
|
||||
Reference in New Issue
Block a user