Snips: (fix) support new intentName format (#11509)

* support new intentName format

* Added tests for new and old format names

* pylint warning fixes
This commit is contained in:
tschmidty69 2018-01-08 16:00:21 -05:00 committed by Paulus Schoutsen
parent 903cda08b1
commit 13effee679
2 changed files with 60 additions and 4 deletions

View File

@ -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)}

View File

@ -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'