Add multiple LLM API support for MCP Server (#147785)

* Add multiple LLM API support for MCP Server

* Update homeassistant/components/mcp_server/config_flow.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* ruff

* Update tests/components/mcp_server/conftest.py

Co-authored-by: Allen Porter <allen.porter@gmail.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Allen Porter <allen.porter@gmail.com>
This commit is contained in:
Denis Shulyaka
2025-07-01 06:14:03 -07:00
committed by GitHub
co-authored by Copilot Allen Porter
parent 073a467fb2
commit 7deca35172
6 changed files with 55 additions and 12 deletions
+5 -3
View File
@@ -23,13 +23,15 @@ def mock_setup_entry() -> Generator[AsyncMock]:
@pytest.fixture(name="llm_hass_api")
def llm_hass_api_fixture() -> str:
def llm_hass_api_fixture() -> list[str]:
"""Fixture for the config entry llm_hass_api."""
return llm.LLM_API_ASSIST
return [llm.LLM_API_ASSIST]
@pytest.fixture(name="config_entry")
def mock_config_entry(hass: HomeAssistant, llm_hass_api: str) -> MockConfigEntry:
def mock_config_entry(
hass: HomeAssistant, llm_hass_api: str | list[str]
) -> MockConfigEntry:
"""Fixture to load the integration."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@@ -16,7 +16,7 @@ from homeassistant.data_entry_flow import FlowResultType
"params",
[
{},
{CONF_LLM_HASS_API: "assist"},
{CONF_LLM_HASS_API: ["assist"]},
],
)
async def test_form(
@@ -38,4 +38,33 @@ async def test_form(
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "Assist"
assert len(mock_setup_entry.mock_calls) == 1
assert result["data"] == {CONF_LLM_HASS_API: "assist"}
assert result["data"] == {CONF_LLM_HASS_API: ["assist"]}
@pytest.mark.parametrize(
("params", "errors"),
[
({CONF_LLM_HASS_API: []}, {CONF_LLM_HASS_API: "llm_api_required"}),
],
)
async def test_form_errors(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
params: dict[str, Any],
errors: dict[str, str],
) -> None:
"""Test we get the errors on invalid user input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == FlowResultType.FORM
assert not result["errors"]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
params,
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.FORM
assert result["errors"] == errors
+1 -1
View File
@@ -194,7 +194,7 @@ async def test_http_sse_multiple_config_entries(
"""
config_entry = MockConfigEntry(
domain="mcp_server", data={CONF_LLM_HASS_API: "llm-api-id"}
domain="mcp_server", data={CONF_LLM_HASS_API: ["llm-api-id"]}
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)