mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
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
This commit is contained in:
parent
aaff8d8602
commit
a2f17cccbb
@ -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."""
|
||||
|
@ -101,6 +101,12 @@ def setUpModule():
|
||||
"text": "You told us your sign is {{ ZodiacSign }}.",
|
||||
}
|
||||
},
|
||||
"AMAZON.PlaybackAction<object@MusicCreativeWork>": {
|
||||
"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<object@MusicCreativeWork>',
|
||||
'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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user