From 3797b6b012b79e384e20fecd9786a539b6941b22 Mon Sep 17 00:00:00 2001 From: Tod Schmidt <tschmidty@yahoo.com> Date: Sat, 1 Sep 2018 18:01:11 -0400 Subject: [PATCH] Snips: Added special slot values, session_id and slotname_raw (#16185) * Added special slot values, site_id, session_id, and slotname_raw * Update snips.py --- homeassistant/components/snips.py | 3 +++ tests/components/test_snips.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/snips.py b/homeassistant/components/snips.py index 34290819106..88a93408056 100644 --- a/homeassistant/components/snips.py +++ b/homeassistant/components/snips.py @@ -131,7 +131,10 @@ async def async_setup(hass, config): slots = {} for slot in request.get('slots', []): slots[slot['slotName']] = {'value': resolve_slot_values(slot)} + slots['{}_raw'.format(slot['slotName'])] = { + 'value': slot['rawValue']} slots['site_id'] = {'value': request.get('siteId')} + slots['session_id'] = {'value': request.get('sessionId')} slots['probability'] = {'value': request['intent']['probability']} try: diff --git a/tests/components/test_snips.py b/tests/components/test_snips.py index baeda2c49a8..bc044999bdd 100644 --- a/tests/components/test_snips.py +++ b/tests/components/test_snips.py @@ -93,6 +93,8 @@ async def test_snips_intent(hass, mqtt_mock): assert result payload = """ { + "siteId": "default", + "sessionId": "1234567890ABCDEF", "input": "turn the lights green", "intent": { "intentName": "Lights", @@ -104,7 +106,8 @@ async def test_snips_intent(hass, mqtt_mock): "value": { "kind": "Custom", "value": "green" - } + }, + "rawValue": "green" } ] } @@ -119,9 +122,12 @@ async def test_snips_intent(hass, mqtt_mock): intent = intents[0] assert intent.platform == 'snips' assert intent.intent_type == 'Lights' + assert intent assert intent.slots == {'light_color': {'value': 'green'}, + 'light_color_raw': {'value': 'green'}, 'probability': {'value': 1}, - 'site_id': {'value': None}} + 'site_id': {'value': 'default'}, + 'session_id': {'value': '1234567890ABCDEF'}} assert intent.text_input == 'turn the lights green' @@ -147,7 +153,8 @@ async def test_snips_service_intent(hass, mqtt_mock): "value": { "kind": "Custom", "value": "kitchen" - } + }, + "rawValue": "green" } ] } @@ -217,7 +224,9 @@ async def test_snips_intent_with_duration(hass, mqtt_mock): assert intent.intent_type == 'SetTimer' assert intent.slots == {'probability': {'value': 1}, 'site_id': {'value': None}, - 'timer_duration': {'value': 300}} + 'session_id': {'value': None}, + 'timer_duration': {'value': 300}, + 'timer_duration_raw': {'value': 'five minutes'}} async def test_intent_speech_response(hass, mqtt_mock): -- GitLab