mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
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:
parent
47dad547eb
commit
1adb5040e7
@ -128,19 +128,18 @@ class AlexaIntentsView(http.HomeAssistantView):
|
|||||||
alexa_intent_info = req.get('intent')
|
alexa_intent_info = req.get('intent')
|
||||||
alexa_response = AlexaResponse(hass, alexa_intent_info)
|
alexa_response = AlexaResponse(hass, alexa_intent_info)
|
||||||
|
|
||||||
if req_type == 'LaunchRequest':
|
if req_type != 'IntentRequest' and 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':
|
|
||||||
_LOGGER.warning('Received unsupported request: %s', req_type)
|
_LOGGER.warning('Received unsupported request: %s', req_type)
|
||||||
return self.json_message(
|
return self.json_message(
|
||||||
'Received unsupported request: {}'.format(req_type),
|
'Received unsupported request: {}'.format(req_type),
|
||||||
HTTP_BAD_REQUEST)
|
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:
|
try:
|
||||||
intent_response = yield from intent.async_handle(
|
intent_response = yield from intent.async_handle(
|
||||||
|
@ -100,6 +100,12 @@ def alexa_client(loop, hass, test_client):
|
|||||||
},
|
},
|
||||||
"entity_id": "switch.test",
|
"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)
|
req = yield from _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
resp = yield from req.json()
|
data = yield from req.json()
|
||||||
assert "outputSpeech" in resp["response"]
|
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
|
@asyncio.coroutine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user