1 """Provide configuration end points for Scenes."""
3 from __future__
import annotations
9 DOMAIN
as SCENE_DOMAIN,
10 PLATFORM_SCHEMA
as SCENE_PLATFORM_SCHEMA,
17 from .const
import ACTION_DELETE
18 from .view
import EditIdBasedConfigView
20 PLATFORM_SCHEMA = SCENE_PLATFORM_SCHEMA
25 """Set up the Scene config API."""
27 async
def hook(action: str, config_key: str) ->
None:
28 """post_write_hook for Config View that reloads scenes."""
29 if action != ACTION_DELETE:
30 await hass.services.async_call(SCENE_DOMAIN, SERVICE_RELOAD)
33 ent_reg = er.async_get(hass)
35 entity_id = ent_reg.async_get_entity_id(
36 SCENE_DOMAIN, HOMEASSISTANT_DOMAIN, config_key
42 ent_reg.async_remove(entity_id)
44 hass.http.register_view(
50 data_schema=PLATFORM_SCHEMA,
58 """Edit scene config."""
63 data: list[dict[str, Any]],
65 new_value: dict[str, Any],
68 updated_value = {CONF_ID: config_key}
70 for key
in (
"name",
"entities"):
72 updated_value[key] = new_value[key]
76 updated_value.update(new_value)
79 for index, cur_value
in enumerate(data):
82 if CONF_ID
not in cur_value:
83 cur_value[CONF_ID] = uuid.uuid4().hex
85 elif cur_value[CONF_ID] == config_key:
86 data[index] = updated_value
90 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)