From 533799656e19ae0f6c94c63ad91cb107daf607a4 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 23 Apr 2016 07:10:57 +0200 Subject: [PATCH] Cache script object for Alexa --- homeassistant/components/alexa.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/alexa.py b/homeassistant/components/alexa.py index d6178b4744c..080d7bd1097 100644 --- a/homeassistant/components/alexa.py +++ b/homeassistant/components/alexa.py @@ -26,7 +26,14 @@ CONF_ACTION = 'action' def setup(hass, config): """Activate Alexa component.""" - _CONFIG.update(config[DOMAIN].get(CONF_INTENTS, {})) + intents = config[DOMAIN].get(CONF_INTENTS, {}) + + for name, intent in intents.items(): + if CONF_ACTION in intent: + intent[CONF_ACTION] = script.Script(hass, intent[CONF_ACTION], + "Alexa intent {}".format(name)) + + _CONFIG.update(intents) hass.http.register_path('POST', API_ENDPOINT, _handle_alexa, True) @@ -90,8 +97,7 @@ def _handle_alexa(handler, path_match, data): card['content']) if action is not None: - script.call_from_config(handler.server.hass, action, - response.variables) + action.run(response.variables) handler.write_json(response.as_dict())