Feature alexa launch request (#8730)

* Add support for LaunchRequest alexa intent

* Support LaunchRequest for multiple skills

* formatting

* adding tests to cover launch request

* formatting
This commit is contained in:
Steve Rhoades 2017-08-01 22:53:36 -07:00 committed by Paulus Schoutsen
parent 47dad547eb
commit 1adb5040e7
2 changed files with 48 additions and 10 deletions

View File

@ -128,19 +128,18 @@ class AlexaIntentsView(http.HomeAssistantView):
alexa_intent_info = req.get('intent')
alexa_response = AlexaResponse(hass, alexa_intent_info)
if req_type == 'LaunchRequest':
alexa_response.add_speech(
SpeechType.plaintext,
"Hello, and welcome to the future. How may I help?")
return self.json(alexa_response)
if req_type != 'IntentRequest':
if req_type != 'IntentRequest' and req_type != 'LaunchRequest':
_LOGGER.warning('Received unsupported request: %s', req_type)
return self.json_message(
'Received unsupported request: {}'.format(req_type),
HTTP_BAD_REQUEST)
intent_name = alexa_intent_info['name']
if req_type == 'LaunchRequest':
intent_name = data.get('session', {}) \
.get('application', {}) \
.get('applicationId')
else:
intent_name = alexa_intent_info['name']
try:
intent_response = yield from intent.async_handle(

View File

@ -100,6 +100,12 @@ def alexa_client(loop, hass, test_client):
},
"entity_id": "switch.test",
}
},
APPLICATION_ID: {
"speech": {
"type": "plain",
"text": "LaunchRequest has been received.",
}
}
}
}))
@ -140,8 +146,41 @@ def test_intent_launch_request(alexa_client):
}
req = yield from _intent_req(alexa_client, data)
assert req.status == 200
resp = yield from req.json()
assert "outputSpeech" in resp["response"]
data = yield from req.json()
text = data.get("response", {}).get("outputSpeech",
{}).get("text")
assert text == "LaunchRequest has been received."
@asyncio.coroutine
def test_intent_launch_request_not_configured(alexa_client):
"""Test the launch of a request."""
data = {
"version": "1.0",
"session": {
"new": True,
"sessionId": SESSION_ID,
"application": {
"applicationId":
'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00000'
},
"attributes": {},
"user": {
"userId": "amzn1.account.AM3B00000000000000000000000"
}
},
"request": {
"type": "LaunchRequest",
"requestId": REQUEST_ID,
"timestamp": "2015-05-13T12:34:56Z"
}
}
req = yield from _intent_req(alexa_client, data)
assert req.status == 200
data = yield from req.json()
text = data.get("response", {}).get("outputSpeech",
{}).get("text")
assert text == "This intent is not yet configured within Home Assistant."
@asyncio.coroutine