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
|
2020-08-21 09:38:25 +00:00
|
|
|
from homeassistant.components.script.config import async_validate_config_item
|
2019-10-15 23:15:26 +00:00
|
|
|
from homeassistant.config import SCRIPT_CONFIG_PATH
|
2019-12-08 16:57:28 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-01-27 07:01:35 +00:00
|
|
|
async def hook(action, config_key):
|
2018-09-27 21:13:11 +00:00
|
|
|
"""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(
|
2020-08-21 09:38:25 +00:00
|
|
|
DOMAIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
"config",
|
2019-10-15 23:15:26 +00:00
|
|
|
SCRIPT_CONFIG_PATH,
|
2019-07-31 19:25:30 +00:00
|
|
|
cv.slug,
|
|
|
|
SCRIPT_ENTRY_SCHEMA,
|
|
|
|
post_write_hook=hook,
|
2020-08-21 09:38:25 +00:00
|
|
|
data_validator=async_validate_config_item,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
|
|
|
)
|
2017-08-16 05:09:10 +00:00
|
|
|
return True
|