mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 01:46:11 -04:00
Set tool metadata in script (#182713)
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude
Simon Lamon
parent
a9f7c8f7b7
commit
313a3a4bc6
@@ -31,6 +31,10 @@ class ScriptTool(ActionTool):
|
||||
super().__init__(hass, DOMAIN, action)
|
||||
|
||||
self.name = f"{DOMAIN}__{script_name}"
|
||||
# The script is named by the user, so its name is already in their
|
||||
# language.
|
||||
if state := hass.states.get(script_entity_id):
|
||||
self.title = state.name
|
||||
|
||||
if entity_entry and (
|
||||
aliases := er.async_get_entity_aliases(hass, entity_entry)
|
||||
|
||||
@@ -54,6 +54,14 @@ def _llm_context() -> llm.LLMContext:
|
||||
)
|
||||
|
||||
|
||||
async def test_script_tool_title(hass: HomeAssistant) -> None:
|
||||
"""Test the script tool is titled with the name the user gave the script."""
|
||||
result = await llm_component.async_get_tools(hass, _llm_context(), "assist")
|
||||
tool = next(tool for tool in result.tools if tool.name == "script__test_script")
|
||||
assert tool.title == "test script"
|
||||
assert tool.integration == "script"
|
||||
|
||||
|
||||
async def test_script_tool_only_exposed(hass: HomeAssistant) -> None:
|
||||
"""Test only exposed scripts get a tool."""
|
||||
result = await llm_component.async_get_tools(hass, _llm_context(), "assist")
|
||||
|
||||
Reference in New Issue
Block a user