Handle match failures in intent HTTP API (#151726)

This commit is contained in:
Michael Hansen
2025-09-05 03:28:37 -05:00
committed by GitHub
parent f3b997720d
commit f4e0b9ba15
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -615,7 +615,7 @@ class IntentHandleView(http.HomeAssistantView):
intent_result = await intent.async_handle(
hass, DOMAIN, intent_name, slots, "", self.context(request)
)
except intent.IntentHandleError as err:
except (intent.IntentHandleError, intent.MatchFailedError) as err:
intent_result = intent.IntentResponse(language=language)
intent_result.async_set_speech(str(err))
+26
View File
@@ -73,6 +73,32 @@ async def test_http_handle_intent(
}
async def test_http_handle_intent_match_failure(
hass: HomeAssistant, hass_client: ClientSessionGenerator, hass_admin_user: MockUser
) -> None:
"""Test handle intent match failure via HTTP API."""
assert await async_setup_component(hass, "intent", {})
hass.states.async_set(
"cover.garage_door_1", "closed", {ATTR_FRIENDLY_NAME: "Garage Door"}
)
hass.states.async_set(
"cover.garage_door_2", "closed", {ATTR_FRIENDLY_NAME: "Garage Door"}
)
async_mock_service(hass, "cover", SERVICE_OPEN_COVER)
client = await hass_client()
resp = await client.post(
"/api/intent/handle",
json={"name": "HassTurnOn", "data": {"name": "Garage Door"}},
)
assert resp.status == 200
data = await resp.json()
assert "DUPLICATE_NAME" in data["speech"]["plain"]["speech"]
async def test_cover_intents_loading(hass: HomeAssistant) -> None:
"""Test Cover Intents Loading."""
assert await async_setup_component(hass, "intent", {})