Skip to content

Commit

Permalink
Fix Snips json schema (#8317)
Browse files Browse the repository at this point in the history
* Fix Snips json schema

* Fix test
  • Loading branch information
Adrien Ball authored and pvizeli committed Jul 3, 2017
1 parent afe3dd8 commit 8d940fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
29 changes: 6 additions & 23 deletions homeassistant/components/snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
}, extra=vol.ALLOW_EXTRA)

INTENT_SCHEMA = vol.Schema({
vol.Required('text'): str,
vol.Required('input'): str,
vol.Required('intent'): {
vol.Required('intent_name'): str
vol.Required('intentName'): str
},
vol.Optional('slots'): [{
vol.Required('slot_name'): str,
vol.Required('slotName'): str,
vol.Required('value'): {
vol.Required('kind'): str,
vol.Required('value'): cv.match_all
Expand Down Expand Up @@ -95,7 +95,7 @@ def handle_intent(self, payload):
LOGGER.error('Intent has invalid schema: %s. %s', err, response)
return

intent = response['intent']['intent_name'].split('__')[-1]
intent = response['intent']['intentName'].split('__')[-1]
config = self.intents.get(intent)

if config is None:
Expand All @@ -113,26 +113,9 @@ def parse_slots(self, response):
parameters = {}

for slot in response.get('slots', []):
key = slot['slot_name']
value = self.get_value(slot['value'])
key = slot['slotName']
value = slot['value']['value']
if value is not None:
parameters[key] = value

return parameters

@staticmethod
def get_value(value):
"""Return the value of a given slot."""
kind = value['kind']

if kind == "Custom":
return value["value"]
elif kind == "Builtin":
try:
return value["value"]["value"]
except KeyError:
return None
else:
LOGGER.warning('Received unknown slot type: %s', kind)

return None
6 changes: 3 additions & 3 deletions tests/components/test_snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

EXAMPLE_MSG = """
{
"text": "turn the lights green",
"input": "turn the lights green",
"intent": {
"intent_name": "Lights",
"intentName": "Lights",
"probability": 1
},
"slots": [
{
"slot_name": "light_color",
"slotName": "light_color",
"value": {
"kind": "Custom",
"value": "blue"
Expand Down

0 comments on commit 8d940fb

Please sign in to comment.