diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index 0bc44501e28..9e447c8936a 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -14,7 +14,7 @@ from homeassistant.util.yaml import load_yaml, dump DOMAIN = 'config' DEPENDENCIES = ['http'] -SECTIONS = ('core', 'group', 'hassbian', 'automation') +SECTIONS = ('core', 'group', 'hassbian', 'automation', 'script') ON_DEMAND = ('zwave') diff --git a/homeassistant/components/config/script.py b/homeassistant/components/config/script.py new file mode 100644 index 00000000000..345c8e4a849 --- /dev/null +++ b/homeassistant/components/config/script.py @@ -0,0 +1,19 @@ +"""Provide configuration end points for scripts.""" +import asyncio + +from homeassistant.components.config import EditKeyBasedConfigView +from homeassistant.components.script import SCRIPT_ENTRY_SCHEMA, async_reload +import homeassistant.helpers.config_validation as cv + + +CONFIG_PATH = 'scripts.yaml' + + +@asyncio.coroutine +def async_setup(hass): + """Set up the script config API.""" + hass.http.register_view(EditKeyBasedConfigView( + 'script', 'config', CONFIG_PATH, cv.slug, SCRIPT_ENTRY_SCHEMA, + post_write_hook=async_reload + )) + return True diff --git a/homeassistant/components/script.py b/homeassistant/components/script.py index 62edb11b778..7be8bd8175e 100644 --- a/homeassistant/components/script.py +++ b/homeassistant/components/script.py @@ -39,13 +39,13 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}' GROUP_NAME_ALL_SCRIPTS = 'all scripts' -_SCRIPT_ENTRY_SCHEMA = vol.Schema({ +SCRIPT_ENTRY_SCHEMA = vol.Schema({ CONF_ALIAS: cv.string, vol.Required(CONF_SEQUENCE): cv.SCRIPT_SCHEMA, }) CONFIG_SCHEMA = vol.Schema({ - DOMAIN: vol.Schema({cv.slug: _SCRIPT_ENTRY_SCHEMA}) + DOMAIN: vol.Schema({cv.slug: SCRIPT_ENTRY_SCHEMA}) }, extra=vol.ALLOW_EXTRA) SCRIPT_SERVICE_SCHEMA = vol.Schema(dict) @@ -62,12 +62,6 @@ def is_on(hass, entity_id): return hass.states.is_state(entity_id, STATE_ON) -@bind_hass -def reload(hass): - """Reload script component.""" - hass.services.call(DOMAIN, SERVICE_RELOAD) - - @bind_hass def turn_on(hass, entity_id, variables=None): """Turn script on.""" @@ -88,6 +82,21 @@ def toggle(hass, entity_id): hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id}) +@bind_hass +def reload(hass): + """Reload script component.""" + hass.services.call(DOMAIN, SERVICE_RELOAD) + + +@bind_hass +def async_reload(hass): + """Reload the scripts from config. + + Returns a coroutine object. + """ + return hass.services.async_call(DOMAIN, SERVICE_RELOAD) + + @asyncio.coroutine def async_setup(hass, config): """Load the scripts from the configuration.""" diff --git a/homeassistant/config.py b/homeassistant/config.py index a4b7bce5dc0..c90c4517397 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -108,6 +108,7 @@ tts: group: !include groups.yaml automation: !include automations.yaml +script: !include scripts.yaml """ @@ -173,11 +174,14 @@ def create_default_config(config_dir, detect_location=True): CONFIG_PATH as GROUP_CONFIG_PATH) from homeassistant.components.config.automation import ( CONFIG_PATH as AUTOMATION_CONFIG_PATH) + from homeassistant.components.config.script import ( + CONFIG_PATH as SCRIPT_CONFIG_PATH) config_path = os.path.join(config_dir, YAML_CONFIG_FILE) version_path = os.path.join(config_dir, VERSION_FILE) group_yaml_path = os.path.join(config_dir, GROUP_CONFIG_PATH) automation_yaml_path = os.path.join(config_dir, AUTOMATION_CONFIG_PATH) + script_yaml_path = os.path.join(config_dir, SCRIPT_CONFIG_PATH) info = {attr: default for attr, default, _, _ in DEFAULT_CORE_CONFIG} @@ -216,12 +220,15 @@ def create_default_config(config_dir, detect_location=True): with open(version_path, 'wt') as version_file: version_file.write(__version__) - with open(group_yaml_path, 'w'): + with open(group_yaml_path, 'wt'): pass with open(automation_yaml_path, 'wt') as fil: fil.write('[]') + with open(script_yaml_path, 'wt'): + pass + return config_path except IOError: