"""Tests for the climate LLM tools platform.""" import pytest from homeassistant.components import llm as llm_component from homeassistant.components.climate import llm as climate_llm from homeassistant.components.homeassistant.exposed_entities import async_expose_entity from homeassistant.core import Context, HomeAssistant from homeassistant.helpers import llm from homeassistant.setup import async_setup_component ENTITY_ID = "climate.test" @pytest.fixture(autouse=True) async def setup_integrations(hass: HomeAssistant) -> None: """Set up the integrations and expose a climate entity.""" assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "intent", {}) assert await async_setup_component(hass, "climate", {}) assert await async_setup_component(hass, "llm", {}) hass.states.async_set(ENTITY_ID, "on", {"friendly_name": "Test climate"}) async_expose_entity(hass, "conversation", ENTITY_ID, True) await hass.async_block_till_done() def _llm_context() -> llm.LLMContext: """Return an LLM context for the conversation assistant.""" return llm.LLMContext( platform="test_platform", context=Context(), language="*", assistant="conversation", device_id=None, ) async def _tool_names(hass: HomeAssistant) -> set[str]: """Return the names of the tools offered by the climate platform.""" result = await llm_component.async_get_tools(hass, _llm_context(), "assist") return {tool.name for tool in result.tools} async def test_intent_tool_exposed(hass: HomeAssistant) -> None: """Test the intent tool is offered for an exposed climate entity.""" assert "HassClimateSetTemperature" in await _tool_names(hass) async def test_intent_tool_not_exposed(hass: HomeAssistant) -> None: """Test the intent tool is hidden when no climate entity is exposed.""" async_expose_entity(hass, "conversation", ENTITY_ID, False) assert "HassClimateSetTemperature" not in await _tool_names(hass) assert climate_llm.async_get_tools(hass, _llm_context(), "assist") is None async def test_no_tools_for_other_api(hass: HomeAssistant) -> None: """Test the platform returns None for an unsupported API.""" assert climate_llm.async_get_tools(hass, _llm_context(), "other") is None