parent
58de661ad5
commit
c30c8df449
2 changed files with 9 additions and 26 deletions
|
@ -32,12 +32,12 @@ CONFIG_SCHEMA = vol.Schema({
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
INTENT_SCHEMA = vol.Schema({
|
INTENT_SCHEMA = vol.Schema({
|
||||||
vol.Required('text'): str,
|
vol.Required('input'): str,
|
||||||
vol.Required('intent'): {
|
vol.Required('intent'): {
|
||||||
vol.Required('intent_name'): str
|
vol.Required('intentName'): str
|
||||||
},
|
},
|
||||||
vol.Optional('slots'): [{
|
vol.Optional('slots'): [{
|
||||||
vol.Required('slot_name'): 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.Required('value'): cv.match_all
|
||||||
|
@ -95,7 +95,7 @@ class IntentHandler(object):
|
||||||
LOGGER.error('Intent has invalid schema: %s. %s', err, response)
|
LOGGER.error('Intent has invalid schema: %s. %s', err, response)
|
||||||
return
|
return
|
||||||
|
|
||||||
intent = response['intent']['intent_name'].split('__')[-1]
|
intent = response['intent']['intentName'].split('__')[-1]
|
||||||
config = self.intents.get(intent)
|
config = self.intents.get(intent)
|
||||||
|
|
||||||
if config is None:
|
if config is None:
|
||||||
|
@ -113,26 +113,9 @@ class IntentHandler(object):
|
||||||
parameters = {}
|
parameters = {}
|
||||||
|
|
||||||
for slot in response.get('slots', []):
|
for slot in response.get('slots', []):
|
||||||
key = slot['slot_name']
|
key = slot['slotName']
|
||||||
value = self.get_value(slot['value'])
|
value = slot['value']['value']
|
||||||
if value is not None:
|
if value is not None:
|
||||||
parameters[key] = value
|
parameters[key] = value
|
||||||
|
|
||||||
return parameters
|
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,14 +6,14 @@ from tests.common import async_fire_mqtt_message, async_mock_service
|
||||||
|
|
||||||
EXAMPLE_MSG = """
|
EXAMPLE_MSG = """
|
||||||
{
|
{
|
||||||
"text": "turn the lights green",
|
"input": "turn the lights green",
|
||||||
"intent": {
|
"intent": {
|
||||||
"intent_name": "Lights",
|
"intentName": "Lights",
|
||||||
"probability": 1
|
"probability": 1
|
||||||
},
|
},
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"slot_name": "light_color",
|
"slotName": "light_color",
|
||||||
"value": {
|
"value": {
|
||||||
"kind": "Custom",
|
"kind": "Custom",
|
||||||
"value": "blue"
|
"value": "blue"
|
||||||
|
|
Loading…
Add table
Reference in a new issue