2017-08-16 05:09:10 +00:00
|
|
|
"""Provide configuration end points for scripts."""
|
2021-04-27 22:15:38 +00:00
|
|
|
from homeassistant.components.script import DOMAIN
|
|
|
|
from homeassistant.components.script.config import (
|
|
|
|
SCRIPT_ENTITY_SCHEMA,
|
|
|
|
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(
|
2021-04-26 21:38:30 +00:00
|
|
|
EditScriptConfigView(
|
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,
|
2021-04-27 22:15:38 +00:00
|
|
|
SCRIPT_ENTITY_SCHEMA,
|
2019-07-31 19:25:30 +00:00
|
|
|
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
|
2021-04-26 21:38:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditScriptConfigView(EditKeyBasedConfigView):
|
|
|
|
"""Edit script config."""
|
|
|
|
|
|
|
|
def _write_value(self, hass, data, config_key, new_value):
|
|
|
|
"""Set value."""
|
|
|
|
data[config_key] = new_value
|