diff --git a/homeassistant/components/snips.py b/homeassistant/components/snips.py index a430c53bbc7..ae387f7ab4c 100644 --- a/homeassistant/components/snips.py +++ b/homeassistant/components/snips.py @@ -61,9 +61,11 @@ def async_setup(hass, config): _LOGGER.error('Intent has invalid schema: %s. %s', err, request) return + if request['intent']['intentName'].startswith('user_'): + intent_type = request['intent']['intentName'].split('__')[-1] + else: + intent_type = request['intent']['intentName'].split(':')[-1] snips_response = None - - intent_type = request['intent']['intentName'].split('__')[-1] slots = {} for slot in request.get('slots', []): slots[slot['slotName']] = {'value': resolve_slot_values(slot)} diff --git a/tests/components/test_snips.py b/tests/components/test_snips.py index b554d4785ad..9ee500bb4c7 100644 --- a/tests/components/test_snips.py +++ b/tests/components/test_snips.py @@ -47,7 +47,7 @@ def test_snips_intent(hass, mqtt_mock): @asyncio.coroutine -def test_snips_intent_with_snips_duration(hass, mqtt_mock): +def test_snips_intent_with_duration(hass, mqtt_mock): """Test intent with Snips duration.""" result = yield from async_setup_component(hass, "snips", { "snips": {}, @@ -176,7 +176,7 @@ def test_snips_unknown_intent(hass, mqtt_mock): payload) yield from hass.async_block_till_done() - assert len(intents) == 0 + assert not intents assert len(events) == 1 assert events[0].data['domain'] == 'mqtt' assert events[0].data['service'] == 'publish' @@ -184,3 +184,57 @@ def test_snips_unknown_intent(hass, mqtt_mock): topic = events[0].data['service_data']['topic'] assert payload['text'] == 'Unknown Intent' assert topic == 'hermes/dialogueManager/endSession' + + +@asyncio.coroutine +def test_snips_intent_user(hass, mqtt_mock): + """Test intentName format user_XXX__intentName.""" + result = yield from async_setup_component(hass, "snips", { + "snips": {}, + }) + assert result + payload = """ + { + "input": "what to do", + "intent": { + "intentName": "user_ABCDEF123__Lights" + }, + "slots": [] + } + """ + intents = async_mock_intent(hass, 'Lights') + async_fire_mqtt_message(hass, 'hermes/intent/user_ABCDEF123__Lights', + payload) + yield from hass.async_block_till_done() + + assert len(intents) == 1 + intent = intents[0] + assert intent.platform == 'snips' + assert intent.intent_type == 'Lights' + + +@asyncio.coroutine +def test_snips_intent_username(hass, mqtt_mock): + """Test intentName format username:intentName.""" + result = yield from async_setup_component(hass, "snips", { + "snips": {}, + }) + assert result + payload = """ + { + "input": "what to do", + "intent": { + "intentName": "username:Lights" + }, + "slots": [] + } + """ + intents = async_mock_intent(hass, 'Lights') + async_fire_mqtt_message(hass, 'hermes/intent/username:Lights', + payload) + yield from hass.async_block_till_done() + + assert len(intents) == 1 + intent = intents[0] + assert intent.platform == 'snips' + assert intent.intent_type == 'Lights'