2017-07-22 04:38:53 +00:00
|
|
|
"""Test intent_script component."""
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from homeassistant.bootstrap import async_setup_component
|
|
|
|
from homeassistant.helpers import intent
|
|
|
|
|
|
|
|
from tests.common import async_mock_service
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_intent_script(hass):
|
|
|
|
"""Test intent scripts work."""
|
2019-07-31 19:25:30 +00:00
|
|
|
calls = async_mock_service(hass, "test", "service")
|
|
|
|
|
|
|
|
yield from async_setup_component(
|
|
|
|
hass,
|
|
|
|
"intent_script",
|
|
|
|
{
|
|
|
|
"intent_script": {
|
|
|
|
"HelloWorld": {
|
|
|
|
"action": {
|
|
|
|
"service": "test.service",
|
|
|
|
"data_template": {"hello": "{{ name }}"},
|
|
|
|
},
|
|
|
|
"card": {
|
|
|
|
"title": "Hello {{ name }}",
|
|
|
|
"content": "Content for {{ name }}",
|
|
|
|
},
|
|
|
|
"speech": {"text": "Good morning {{ name }}"},
|
2017-07-22 04:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-07-22 04:38:53 +00:00
|
|
|
|
|
|
|
response = yield from intent.async_handle(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, "test", "HelloWorld", {"name": {"value": "Paulus"}}
|
2017-07-22 04:38:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert len(calls) == 1
|
2019-07-31 19:25:30 +00:00
|
|
|
assert calls[0].data["hello"] == "Paulus"
|
2017-07-22 04:38:53 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert response.speech["plain"]["speech"] == "Good morning Paulus"
|
2017-07-22 04:38:53 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert response.card["simple"]["title"] == "Hello Paulus"
|
|
|
|
assert response.card["simple"]["content"] == "Content for Paulus"
|