Skip to content

Commit 89c3359

Browse files
synesthesiamfrenck
authored andcommitted
Handle match failures in intent HTTP API (home-assistant#151726)
1 parent 2bb4573 commit 89c3359

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

homeassistant/components/intent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ async def post(self, request: web.Request, data: dict[str, Any]) -> web.Response
615615
intent_result = await intent.async_handle(
616616
hass, DOMAIN, intent_name, slots, "", self.context(request)
617617
)
618-
except intent.IntentHandleError as err:
618+
except (intent.IntentHandleError, intent.MatchFailedError) as err:
619619
intent_result = intent.IntentResponse(language=language)
620620
intent_result.async_set_speech(str(err))
621621

tests/components/intent/test_init.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ async def async_handle(self, intent_obj):
7373
}
7474

7575

76+
async def test_http_handle_intent_match_failure(
77+
hass: HomeAssistant, hass_client: ClientSessionGenerator, hass_admin_user: MockUser
78+
) -> None:
79+
"""Test handle intent match failure via HTTP API."""
80+
81+
assert await async_setup_component(hass, "intent", {})
82+
83+
hass.states.async_set(
84+
"cover.garage_door_1", "closed", {ATTR_FRIENDLY_NAME: "Garage Door"}
85+
)
86+
hass.states.async_set(
87+
"cover.garage_door_2", "closed", {ATTR_FRIENDLY_NAME: "Garage Door"}
88+
)
89+
async_mock_service(hass, "cover", SERVICE_OPEN_COVER)
90+
91+
client = await hass_client()
92+
resp = await client.post(
93+
"/api/intent/handle",
94+
json={"name": "HassTurnOn", "data": {"name": "Garage Door"}},
95+
)
96+
assert resp.status == 200
97+
data = await resp.json()
98+
99+
assert "DUPLICATE_NAME" in data["speech"]["plain"]["speech"]
100+
101+
76102
async def test_cover_intents_loading(hass: HomeAssistant) -> None:
77103
"""Test Cover Intents Loading."""
78104
assert await async_setup_component(hass, "intent", {})

0 commit comments

Comments
 (0)