Skip to content

Commit

Permalink
Update snips to listen on new mqtt topic and utilize rawValue (home-a…
Browse files Browse the repository at this point in the history
…ssistant#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
  • Loading branch information
tschmidty69 authored and balloob committed Dec 8, 2017
1 parent 4d6070e commit fed7bd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions homeassistant/components/snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
CONF_INTENTS = 'intents'
CONF_ACTION = 'action'

INTENT_TOPIC = 'hermes/nlu/intentParsed'
INTENT_TOPIC = 'hermes/intent/#'

_LOGGER = logging.getLogger(__name__)

Expand All @@ -32,7 +32,8 @@
vol.Required('slotName'): str,
vol.Required('value'): {
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)
Expand All @@ -59,8 +60,12 @@ def message_received(topic, payload, qos):
return

intent_type = request['intent']['intentName'].split('__')[-1]
slots = {slot['slotName']: {'value': slot['value']['value']}
for slot in request.get('slots', [])}
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:
yield from intent.async_handle(
Expand Down
2 changes: 1 addition & 1 deletion tests/components/test_snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_snips_call_action(hass, mqtt_mock):

intents = async_mock_intent(hass, 'Lights')

async_fire_mqtt_message(hass, 'hermes/nlu/intentParsed',
async_fire_mqtt_message(hass, 'hermes/intent/activateLights',
EXAMPLE_MSG)
yield from hass.async_block_till_done()
assert len(intents) == 1
Expand Down

0 comments on commit fed7bd9

Please sign in to comment.