Update snips to listen on new mqtt topic and utilize rawValue (#11020)

* Updated snips to listen on new mqtt topic and use rawValue if value not present in slot

* Too late at night

* Trying to make minor changes via web

* Update test_snips.py

* Update __init__.py

* Updated wrong branch cause I'm a monkey
This commit is contained in:
tschmidty69 2017-12-08 12:16:08 -05:00 committed by Paulus Schoutsen
parent 4d6070e33a
commit fed7bd9473
2 changed files with 10 additions and 5 deletions

View File

@ -15,7 +15,7 @@ DEPENDENCIES = ['mqtt']
CONF_INTENTS = 'intents' CONF_INTENTS = 'intents'
CONF_ACTION = 'action' CONF_ACTION = 'action'
INTENT_TOPIC = 'hermes/nlu/intentParsed' INTENT_TOPIC = 'hermes/intent/#'
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -32,7 +32,8 @@ INTENT_SCHEMA = vol.Schema({
vol.Required('slotName'): str, vol.Required('slotName'): str,
vol.Required('value'): { vol.Required('value'): {
vol.Required('kind'): str, vol.Required('kind'): str,
vol.Required('value'): cv.match_all vol.Optional('value'): cv.match_all,
vol.Optional('rawValue'): cv.match_all
} }
}] }]
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
@ -59,8 +60,12 @@ def async_setup(hass, config):
return return
intent_type = request['intent']['intentName'].split('__')[-1] intent_type = request['intent']['intentName'].split('__')[-1]
slots = {slot['slotName']: {'value': slot['value']['value']} slots = {}
for slot in request.get('slots', [])} for slot in request.get('slots', []):
if 'value' in slot['value']:
slots[slot['slotName']] = {'value': slot['value']['value']}
else:
slots[slot['slotName']] = {'value': slot['rawValue']}
try: try:
yield from intent.async_handle( yield from intent.async_handle(

View File

@ -34,7 +34,7 @@ def test_snips_call_action(hass, mqtt_mock):
intents = async_mock_intent(hass, 'Lights') intents = async_mock_intent(hass, 'Lights')
async_fire_mqtt_message(hass, 'hermes/nlu/intentParsed', async_fire_mqtt_message(hass, 'hermes/intent/activateLights',
EXAMPLE_MSG) EXAMPLE_MSG)
yield from hass.async_block_till_done() yield from hass.async_block_till_done()
assert len(intents) == 1 assert len(intents) == 1