2017-08-15 22:09:10 -07:00
|
|
|
"""Provide configuration end points for scripts."""
|
2018-09-27 23:13:11 +02:00
|
|
|
from homeassistant.components.script import DOMAIN, SCRIPT_ENTRY_SCHEMA
|
|
|
|
from homeassistant.const import SERVICE_RELOAD
|
2019-10-15 16:15:26 -07:00
|
|
|
from homeassistant.config import SCRIPT_CONFIG_PATH
|
2017-08-15 22:09:10 -07:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
2019-03-20 22:56:46 -07:00
|
|
|
from . import EditKeyBasedConfigView
|
2017-08-15 22:09:10 -07:00
|
|
|
|
|
|
|
|
2018-10-01 08:50:05 +02:00
|
|
|
async def async_setup(hass):
|
2017-08-15 22:09:10 -07:00
|
|
|
"""Set up the script config API."""
|
2019-07-31 12:25:30 -07:00
|
|
|
|
2018-09-27 23:13:11 +02: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 12:25:30 -07:00
|
|
|
hass.http.register_view(
|
|
|
|
EditKeyBasedConfigView(
|
|
|
|
"script",
|
|
|
|
"config",
|
2019-10-15 16:15:26 -07:00
|
|
|
SCRIPT_CONFIG_PATH,
|
2019-07-31 12:25:30 -07:00
|
|
|
cv.slug,
|
|
|
|
SCRIPT_ENTRY_SCHEMA,
|
|
|
|
post_write_hook=hook,
|
|
|
|
)
|
|
|
|
)
|
2017-08-15 22:09:10 -07:00
|
|
|
return True
|