mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
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:
parent
903cda08b1
commit
13effee679
@ -61,9 +61,11 @@ def async_setup(hass, config):
|
|||||||
_LOGGER.error('Intent has invalid schema: %s. %s', err, request)
|
_LOGGER.error('Intent has invalid schema: %s. %s', err, request)
|
||||||
return
|
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
|
snips_response = None
|
||||||
|
|
||||||
intent_type = request['intent']['intentName'].split('__')[-1]
|
|
||||||
slots = {}
|
slots = {}
|
||||||
for slot in request.get('slots', []):
|
for slot in request.get('slots', []):
|
||||||
slots[slot['slotName']] = {'value': resolve_slot_values(slot)}
|
slots[slot['slotName']] = {'value': resolve_slot_values(slot)}
|
||||||
|
@ -47,7 +47,7 @@ def test_snips_intent(hass, mqtt_mock):
|
|||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@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."""
|
"""Test intent with Snips duration."""
|
||||||
result = yield from async_setup_component(hass, "snips", {
|
result = yield from async_setup_component(hass, "snips", {
|
||||||
"snips": {},
|
"snips": {},
|
||||||
@ -176,7 +176,7 @@ def test_snips_unknown_intent(hass, mqtt_mock):
|
|||||||
payload)
|
payload)
|
||||||
yield from hass.async_block_till_done()
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(intents) == 0
|
assert not intents
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
assert events[0].data['domain'] == 'mqtt'
|
assert events[0].data['domain'] == 'mqtt'
|
||||||
assert events[0].data['service'] == 'publish'
|
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']
|
topic = events[0].data['service_data']['topic']
|
||||||
assert payload['text'] == 'Unknown Intent'
|
assert payload['text'] == 'Unknown Intent'
|
||||||
assert topic == 'hermes/dialogueManager/endSession'
|
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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user