Add intent integration to expose intent handle API (#29124)

* Add intent integration to expose intent handle API.

* Run hassfest + fix scaffolding

* Update __init__.py
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2019-11-27 11:25:43 +01:00
1 parent ec61a86678
commit 004476a1f8
9 files changed
+116 -85

No files matched your search

@@ -129,52 +129,6 @@ async def test_http_processing_intent(hass, hass_client, hass_admin_user):
}
async def test_http_handle_intent(hass, hass_client, hass_admin_user):
"""Test handle intent via HTTP API."""
class TestIntentHandler(intent.IntentHandler):
"""Test Intent Handler."""
intent_type = "OrderBeer"
async def async_handle(self, intent):
"""Handle the intent."""
assert intent.context.user_id == hass_admin_user.id
response = intent.create_response()
response.async_set_speech(
"I've ordered a {}!".format(intent.slots["type"]["value"])
)
response.async_set_card(
"Beer ordered", "You chose a {}.".format(intent.slots["type"]["value"])
)
return response
intent.async_register(hass, TestIntentHandler())
result = await async_setup_component(
hass,
"conversation",
{"conversation": {"intents": {"OrderBeer": ["I would like the {type} beer"]}}},
)
assert result
client = await hass_client()
resp = await client.post(
"/api/conversation/handle",
json={"name": "OrderBeer", "data": {"type": "Belgian"}},
)
assert resp.status == 200
data = await resp.json()
assert data == {
"card": {
"simple": {"content": "You chose a Belgian.", "title": "Beer ordered"}
},
"speech": {"plain": {"extra_data": None, "speech": "I've ordered a Belgian!"}},
}
@pytest.mark.parametrize("sentence", ("turn on kitchen", "turn kitchen on"))
async def test_turn_on_intent(hass, sentence):
"""Test calling the turn on intent."""
+1
View File
@@ -0,0 +1 @@
"""Tests for the Intent integration."""
+44
View File
@@ -0,0 +1,44 @@
"""Tests for Intent component."""
from homeassistant.setup import async_setup_component
from homeassistant.helpers import intent
async def test_http_handle_intent(hass, hass_client, hass_admin_user):
"""Test handle intent via HTTP API."""
class TestIntentHandler(intent.IntentHandler):
"""Test Intent Handler."""
intent_type = "OrderBeer"
async def async_handle(self, intent):
"""Handle the intent."""
assert intent.context.user_id == hass_admin_user.id
response = intent.create_response()
response.async_set_speech(
"I've ordered a {}!".format(intent.slots["type"]["value"])
)
response.async_set_card(
"Beer ordered", "You chose a {}.".format(intent.slots["type"]["value"])
)
return response
intent.async_register(hass, TestIntentHandler())
result = await async_setup_component(hass, "intent", {})
assert result
client = await hass_client()
resp = await client.post(
"/api/intent/handle", json={"name": "OrderBeer", "data": {"type": "Belgian"}}
)
assert resp.status == 200
data = await resp.json()
assert data == {
"card": {
"simple": {"content": "You chose a Belgian.", "title": "Beer ordered"}
},
"speech": {"plain": {"extra_data": None, "speech": "I've ordered a Belgian!"}},
}