From c664c20165ebeb248b98716cf61e865f274a2dac Mon Sep 17 00:00:00 2001 From: Tod Schmidt Date: Tue, 8 May 2018 11:43:31 -0400 Subject: [PATCH] Snips: Added slot values for siteId and probability (#14315) * Added solt values for siteId and probability * Update snips.py * Update test_snips.py --- homeassistant/components/snips.py | 2 ++ tests/components/test_snips.py | 54 ++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/snips.py b/homeassistant/components/snips.py index 812906e7be9..4f50c6beaaa 100644 --- a/homeassistant/components/snips.py +++ b/homeassistant/components/snips.py @@ -131,6 +131,8 @@ async def async_setup(hass, config): slots = {} for slot in request.get('slots', []): slots[slot['slotName']] = {'value': resolve_slot_values(slot)} + slots['site_id'] = {'value': request.get('siteId')} + slots['probability'] = {'value': request['intent']['probability']} try: intent_response = await intent.async_handle( diff --git a/tests/components/test_snips.py b/tests/components/test_snips.py index 2342e897708..d9238336768 100644 --- a/tests/components/test_snips.py +++ b/tests/components/test_snips.py @@ -118,7 +118,9 @@ async def test_snips_intent(hass, mqtt_mock): intent = intents[0] assert intent.platform == 'snips' assert intent.intent_type == 'Lights' - assert intent.slots == {'light_color': {'value': 'green'}} + assert intent.slots == {'light_color': {'value': 'green'}, + 'probability': {'value': 1}, + 'site_id': {'value': None}} assert intent.text_input == 'turn the lights green' @@ -169,7 +171,9 @@ async def test_snips_intent_with_duration(hass, mqtt_mock): intent = intents[0] assert intent.platform == 'snips' assert intent.intent_type == 'SetTimer' - assert intent.slots == {'timer_duration': {'value': 300}} + assert intent.slots == {'probability': {'value': 1}, + 'site_id': {'value': None}, + 'timer_duration': {'value': 300}} async def test_intent_speech_response(hass, mqtt_mock): @@ -318,11 +322,51 @@ async def test_snips_low_probability(hass, mqtt_mock, caplog): assert 'Intent below probaility threshold 0.49 < 0.5' in caplog.text +async def test_intent_special_slots(hass, mqtt_mock): + """Test intent special slot values via Snips.""" + calls = async_mock_service(hass, 'light', 'turn_on') + result = await async_setup_component(hass, "snips", { + "snips": {}, + }) + assert result + result = await async_setup_component(hass, "intent_script", { + "intent_script": { + "Lights": { + "action": { + "service": "light.turn_on", + "data_template": { + "probability": "{{ probability }}", + "site_id": "{{ site_id }}" + } + } + } + } + }) + assert result + payload = """ + { + "input": "turn the light on", + "intent": { + "intentName": "Lights", + "probability": 0.85 + }, + "siteId": "default", + "slots": [] + } + """ + async_fire_mqtt_message(hass, 'hermes/intent/Lights', payload) + await hass.async_block_till_done() + + assert len(calls) == 1 + assert calls[0].domain == 'light' + assert calls[0].service == 'turn_on' + assert calls[0].data['probability'] == '0.85' + assert calls[0].data['site_id'] == 'default' + + async def test_snips_say(hass, caplog): """Test snips say with invalid config.""" - calls = async_mock_service(hass, 'snips', 'say', - snips.SERVICE_SCHEMA_SAY) - + calls = async_mock_service(hass, 'snips', 'say', snips.SERVICE_SCHEMA_SAY) data = {'text': 'Hello'} await hass.services.async_call('snips', 'say', data) await hass.async_block_till_done()