Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Snips json schema #8317

Merged
merged 2 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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