From a2f17cccbbf59b6c3b3bcfd93c18e0867cb63e69 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Thu, 29 Dec 2016 10:26:23 -0600 Subject: [PATCH] Replace dots in Alexa built-in intent slots w/ underscores (#5092) * Replace dots in built-in intent slots w/ underscores * Add a built-in intent test --- homeassistant/components/alexa.py | 9 +++-- tests/components/test_alexa.py | 65 +++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/alexa.py b/homeassistant/components/alexa.py index 9bd0d783fee..59d2ec8852a 100644 --- a/homeassistant/components/alexa.py +++ b/homeassistant/components/alexa.py @@ -203,11 +203,12 @@ class AlexaResponse(object): self.reprompt = None self.session_attributes = {} self.should_end_session = True + self.variables = {} if intent is not None and 'slots' in intent: - self.variables = {key: value['value'] for key, value - in intent['slots'].items() if 'value' in value} - else: - self.variables = {} + for key, value in intent['slots'].items(): + if 'value' in value: + underscored_key = key.replace('.', '_') + self.variables[underscored_key] = value['value'] def add_card(self, card_type, title, content): """Add a card to the response.""" diff --git a/tests/components/test_alexa.py b/tests/components/test_alexa.py index 41e7474974d..fe980bf05b3 100644 --- a/tests/components/test_alexa.py +++ b/tests/components/test_alexa.py @@ -101,6 +101,12 @@ def setUpModule(): "text": "You told us your sign is {{ ZodiacSign }}.", } }, + "AMAZON.PlaybackAction": { + "speech": { + "type": "plaintext", + "text": "Playing {{ object_byArtist_name }}.", + } + }, "CallServiceIntent": { "speech": { "type": "plaintext", @@ -376,6 +382,65 @@ class TestAlexa(unittest.TestCase): self.assertEqual(200, req.status_code) self.assertEqual("", req.text) + def test_intent_from_built_in_intent_library(self): + """Test intents from the Built-in Intent Library.""" + data = { + 'request': { + 'intent': { + 'name': 'AMAZON.PlaybackAction', + 'slots': { + 'object.byArtist.name': { + 'name': 'object.byArtist.name', + 'value': 'the shins' + }, + 'object.composer.name': { + 'name': 'object.composer.name' + }, + 'object.contentSource': { + 'name': 'object.contentSource' + }, + 'object.era': { + 'name': 'object.era' + }, + 'object.genre': { + 'name': 'object.genre' + }, + 'object.name': { + 'name': 'object.name' + }, + 'object.owner.name': { + 'name': 'object.owner.name' + }, + 'object.select': { + 'name': 'object.select' + }, + 'object.sort': { + 'name': 'object.sort' + }, + 'object.type': { + 'name': 'object.type', + 'value': 'music' + } + } + }, + 'timestamp': '2016-12-14T23:23:37Z', + 'type': 'IntentRequest', + 'requestId': REQUEST_ID, + + }, + 'session': { + 'sessionId': SESSION_ID, + 'application': { + 'applicationId': APPLICATION_ID + } + } + } + req = _intent_req(data) + self.assertEqual(200, req.status_code) + text = req.json().get("response", {}).get("outputSpeech", + {}).get("text") + self.assertEqual("Playing the shins.", text) + def test_flash_briefing_invalid_id(self): """Test an invalid Flash Briefing ID.""" req = _flash_briefing_req()