1 """Provide configuration end points for Automations."""
3 from __future__
import annotations
15 from .const
import ACTION_DELETE
16 from .view
import EditIdBasedConfigView
21 """Set up the Automation config API."""
23 async
def hook(action: str, config_key: str) ->
None:
24 """post_write_hook for Config View that reloads automations."""
25 if action != ACTION_DELETE:
26 await hass.services.async_call(
27 AUTOMATION_DOMAIN, SERVICE_RELOAD, {CONF_ID: config_key}
31 ent_reg = er.async_get(hass)
33 entity_id = ent_reg.async_get_entity_id(
34 AUTOMATION_DOMAIN, AUTOMATION_DOMAIN, config_key
40 ent_reg.async_remove(entity_id)
42 hass.http.register_view(
46 AUTOMATION_CONFIG_PATH,
49 data_validator=async_validate_config_item,
56 """Edit automation config."""
61 data: list[dict[str, Any]],
63 new_value: dict[str, Any],
66 updated_value = {CONF_ID: config_key}
80 updated_value[key] = new_value[key]
84 updated_value.update(new_value)
87 for index, cur_value
in enumerate(data):
90 if CONF_ID
not in cur_value:
91 cur_value[CONF_ID] = uuid.uuid4().hex
93 elif cur_value[CONF_ID] == config_key:
94 data[index] = updated_value
98 data.append(updated_value)
None _write_value(self, HomeAssistant hass, list[dict[str, Any]] data, str config_key, dict[str, Any] new_value)
bool async_setup(HomeAssistant hass)