1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-15 10:34:19 +01:00
Files
2026-07-03 17:39:51 -07:00

39 lines
1.2 KiB
Python

"""LLM tools for the light integration."""
from homeassistant.components.homeassistant import async_should_expose
from homeassistant.components.llm import LLMTools
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import intent
from homeassistant.helpers.llm import LLM_API_ASSIST, IntentTool, LLMContext, Tool
from .const import DOMAIN
from .intent import INTENT_SET
# Intents owned by this integration that are exposed as LLM tools.
LLM_INTENTS = (INTENT_SET,)
@callback
def async_get_tools(
hass: HomeAssistant, llm_context: LLMContext, api_id: str
) -> LLMTools | None:
"""Return LLM tools for the integration's intents when its domain is exposed."""
if api_id != LLM_API_ASSIST:
return None
if not llm_context.assistant:
return None
if not any(
async_should_expose(hass, llm_context.assistant, state.entity_id)
for state in hass.states.async_all(DOMAIN)
):
return None
tools: list[Tool] = [
IntentTool(handler.intent_type, handler)
for handler in intent.async_get(hass)
if handler.intent_type in LLM_INTENTS
]
return LLMTools(tools=tools)