mirror of
https://github.com/home-assistant/core.git
synced 2026-06-11 11:41:42 +02:00
Handle match failures in intent HTTP API (#151726)
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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", {})
|
||||
|
||||
Reference in New Issue
Block a user