2017-08-16 05:09:10 +00:00
|
|
|
"""Provide configuration end points for scripts."""
|
2018-09-27 21:13:11 +00:00
|
|
|
from homeassistant.components.script import DOMAIN, SCRIPT_ENTRY_SCHEMA
|
|
|
|
from homeassistant.const import SERVICE_RELOAD
|
2017-08-16 05:09:10 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import EditKeyBasedConfigView
|
2017-08-16 05:09:10 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_PATH = "scripts.yaml"
|
2017-08-16 05:09:10 +00:00
|
|
|
|
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_setup(hass):
|
2017-08-16 05:09:10 +00:00
|
|
|
"""Set up the script config API."""
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2018-09-27 21:13:11 +00:00
|
|
|
async def hook(hass):
|
|
|
|
"""post_write_hook for Config View that reloads scripts."""
|
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.http.register_view(
|
|
|
|
EditKeyBasedConfigView(
|
|
|
|
"script",
|
|
|
|
"config",
|
|
|
|
CONFIG_PATH,
|
|
|
|
cv.slug,
|
|
|
|
SCRIPT_ENTRY_SCHEMA,
|
|
|
|
post_write_hook=hook,
|
|
|
|
)
|
|
|
|
)
|
2017-08-16 05:09:10 +00:00
|
|
|
return True
|