parent
95c57412ff
commit
2dab239021
|
@ -14,7 +14,7 @@ from homeassistant.util.yaml import load_yaml, dump
|
||||||
|
|
||||||
DOMAIN = 'config'
|
DOMAIN = 'config'
|
||||||
DEPENDENCIES = ['http']
|
DEPENDENCIES = ['http']
|
||||||
SECTIONS = ('core', 'group', 'hassbian', 'automation')
|
SECTIONS = ('core', 'group', 'hassbian', 'automation', 'script')
|
||||||
ON_DEMAND = ('zwave')
|
ON_DEMAND = ('zwave')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -39,13 +39,13 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||||
|
|
||||||
GROUP_NAME_ALL_SCRIPTS = 'all scripts'
|
GROUP_NAME_ALL_SCRIPTS = 'all scripts'
|
||||||
|
|
||||||
_SCRIPT_ENTRY_SCHEMA = vol.Schema({
|
SCRIPT_ENTRY_SCHEMA = vol.Schema({
|
||||||
CONF_ALIAS: cv.string,
|
CONF_ALIAS: cv.string,
|
||||||
vol.Required(CONF_SEQUENCE): cv.SCRIPT_SCHEMA,
|
vol.Required(CONF_SEQUENCE): cv.SCRIPT_SCHEMA,
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.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)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
SCRIPT_SERVICE_SCHEMA = vol.Schema(dict)
|
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)
|
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
|
@bind_hass
|
||||||
def turn_on(hass, entity_id, variables=None):
|
def turn_on(hass, entity_id, variables=None):
|
||||||
"""Turn script on."""
|
"""Turn script on."""
|
||||||
|
@ -88,6 +82,21 @@ def toggle(hass, entity_id):
|
||||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: 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
|
@asyncio.coroutine
|
||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Load the scripts from the configuration."""
|
"""Load the scripts from the configuration."""
|
||||||
|
|
|
@ -108,6 +108,7 @@ tts:
|
||||||
|
|
||||||
group: !include groups.yaml
|
group: !include groups.yaml
|
||||||
automation: !include automations.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)
|
CONFIG_PATH as GROUP_CONFIG_PATH)
|
||||||
from homeassistant.components.config.automation import (
|
from homeassistant.components.config.automation import (
|
||||||
CONFIG_PATH as AUTOMATION_CONFIG_PATH)
|
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)
|
config_path = os.path.join(config_dir, YAML_CONFIG_FILE)
|
||||||
version_path = os.path.join(config_dir, VERSION_FILE)
|
version_path = os.path.join(config_dir, VERSION_FILE)
|
||||||
group_yaml_path = os.path.join(config_dir, GROUP_CONFIG_PATH)
|
group_yaml_path = os.path.join(config_dir, GROUP_CONFIG_PATH)
|
||||||
automation_yaml_path = os.path.join(config_dir, AUTOMATION_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}
|
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:
|
with open(version_path, 'wt') as version_file:
|
||||||
version_file.write(__version__)
|
version_file.write(__version__)
|
||||||
|
|
||||||
with open(group_yaml_path, 'w'):
|
with open(group_yaml_path, 'wt'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(automation_yaml_path, 'wt') as fil:
|
with open(automation_yaml_path, 'wt') as fil:
|
||||||
fil.write('[]')
|
fil.write('[]')
|
||||||
|
|
||||||
|
with open(script_yaml_path, 'wt'):
|
||||||
|
pass
|
||||||
|
|
||||||
return config_path
|
return config_path
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
Loading…
Reference in New Issue