From 6f9375c9054ff50162ebc1ff8ac63d6538ba5aec Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 18 Sep 2026 11:24:24 -0400 Subject: [PATCH] Use ToolResult in todo (#182540) Co-authored-by: Claude --- homeassistant/components/todo/llm.py | 10 +++++----- tests/components/todo/test_llm.py | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/todo/llm.py b/homeassistant/components/todo/llm.py index d9f28e37dbc5..41335100f8a3 100644 --- a/homeassistant/components/todo/llm.py +++ b/homeassistant/components/todo/llm.py @@ -15,8 +15,8 @@ from homeassistant.helpers.llm import ( LLMContext, Tool, ToolInput, + ToolResult, ) -from homeassistant.util.json import JsonObjectType from .const import DOMAIN, TodoServices from .intent import ( @@ -61,7 +61,7 @@ class TodoGetItemsTool(Tool): @override async def async_call( self, hass: HomeAssistant, tool_input: ToolInput, llm_context: LLMContext - ) -> JsonObjectType: + ) -> ToolResult: """Query a to-do list.""" data = self.parameters(tool_input.tool_args) result = intent.async_match_targets( @@ -73,7 +73,7 @@ class TodoGetItemsTool(Tool): ), ) if not result.is_match: - return {"success": False, "error": "To-do list not found"} + return ToolResult(data={"error": "To-do list not found"}, error=True) entity_id = result.states[0].entity_id service_data: dict[str, Any] = {"entity_id": entity_id} status = data["status"] @@ -89,9 +89,9 @@ class TodoGetItemsTool(Tool): return_response=True, ) if not service_result: - return {"success": False, "error": "To-do list not found"} + return ToolResult(data={"error": "To-do list not found"}, error=True) items = cast(dict, service_result)[entity_id]["items"] - return {"success": True, "result": items} + return ToolResult(data={"items": items}) @callback diff --git a/tests/components/todo/test_llm.py b/tests/components/todo/test_llm.py index bb56b76d47b3..547ca17fad9e 100644 --- a/tests/components/todo/test_llm.py +++ b/tests/components/todo/test_llm.py @@ -80,10 +80,11 @@ async def test_todo_get_items_tool(hass: HomeAssistant) -> None: assert len(calls) == 1 assert calls[0].data == {"entity_id": [ENTITY_ID], "status": ["needs_action"]} - assert result == { - "success": True, - "result": [{"uid": "1234", "status": "needs_action", "summary": "Buy milk"}], - } + assert result == llm.ToolResult( + data={ + "items": [{"uid": "1234", "status": "needs_action", "summary": "Buy milk"}] + } + ) @pytest.mark.parametrize(