This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

@@ -4,42 +4,45 @@ import logging
import voluptuous as vol
from homeassistant.helpers import (
intent, template, script, config_validation as cv)
from homeassistant.helpers import intent, template, script, config_validation as cv
DOMAIN = 'intent_script'
DOMAIN = "intent_script"
CONF_INTENTS = 'intents'
CONF_SPEECH = 'speech'
CONF_INTENTS = "intents"
CONF_SPEECH = "speech"
CONF_ACTION = 'action'
CONF_CARD = 'card'
CONF_TYPE = 'type'
CONF_TITLE = 'title'
CONF_CONTENT = 'content'
CONF_TEXT = 'text'
CONF_ASYNC_ACTION = 'async_action'
CONF_ACTION = "action"
CONF_CARD = "card"
CONF_TYPE = "type"
CONF_TITLE = "title"
CONF_CONTENT = "content"
CONF_TEXT = "text"
CONF_ASYNC_ACTION = "async_action"
DEFAULT_CONF_ASYNC_ACTION = False
CONFIG_SCHEMA = vol.Schema({
DOMAIN: {
cv.string: {
vol.Optional(CONF_ACTION): cv.SCRIPT_SCHEMA,
vol.Optional(CONF_ASYNC_ACTION,
default=DEFAULT_CONF_ASYNC_ACTION): cv.boolean,
vol.Optional(CONF_CARD): {
vol.Optional(CONF_TYPE, default='simple'): cv.string,
vol.Required(CONF_TITLE): cv.template,
vol.Required(CONF_CONTENT): cv.template,
},
vol.Optional(CONF_SPEECH): {
vol.Optional(CONF_TYPE, default='plain'): cv.string,
vol.Required(CONF_TEXT): cv.template,
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: {
cv.string: {
vol.Optional(CONF_ACTION): cv.SCRIPT_SCHEMA,
vol.Optional(
CONF_ASYNC_ACTION, default=DEFAULT_CONF_ASYNC_ACTION
): cv.boolean,
vol.Optional(CONF_CARD): {
vol.Optional(CONF_TYPE, default="simple"): cv.string,
vol.Required(CONF_TITLE): cv.template,
vol.Required(CONF_CONTENT): cv.template,
},
vol.Optional(CONF_SPEECH): {
vol.Optional(CONF_TYPE, default="plain"): cv.string,
vol.Required(CONF_TEXT): cv.template,
},
}
}
}
}, extra=vol.ALLOW_EXTRA)
},
extra=vol.ALLOW_EXTRA,
)
_LOGGER = logging.getLogger(__name__)
@@ -52,8 +55,8 @@ async def async_setup(hass, config):
for intent_type, conf in intents.items():
if CONF_ACTION in conf:
conf[CONF_ACTION] = script.Script(
hass, conf[CONF_ACTION],
"Intent Script {}".format(intent_type))
hass, conf[CONF_ACTION], "Intent Script {}".format(intent_type)
)
intent.async_register(hass, ScriptIntentHandler(intent_type, conf))
return True
@@ -73,8 +76,7 @@ class ScriptIntentHandler(intent.IntentHandler):
card = self.config.get(CONF_CARD)
action = self.config.get(CONF_ACTION)
is_async_action = self.config.get(CONF_ASYNC_ACTION)
slots = {key: value['value'] for key, value
in intent_obj.slots.items()}
slots = {key: value["value"] for key, value in intent_obj.slots.items()}
if action is not None:
if is_async_action:
@@ -85,13 +87,15 @@ class ScriptIntentHandler(intent.IntentHandler):
response = intent_obj.create_response()
if speech is not None:
response.async_set_speech(speech[CONF_TEXT].async_render(slots),
speech[CONF_TYPE])
response.async_set_speech(
speech[CONF_TEXT].async_render(slots), speech[CONF_TYPE]
)
if card is not None:
response.async_set_card(
card[CONF_TITLE].async_render(slots),
card[CONF_CONTENT].async_render(slots),
card[CONF_TYPE])
card[CONF_TYPE],
)
return response