|
|
@@ -62,9 +62,45 @@ class ZLockSlotsOptionsFlow(OptionsFlow):
|
|
|
async def async_step_init(self, user_input=None) -> ConfigFlowResult:
|
|
|
return self.async_show_menu(
|
|
|
step_id="init",
|
|
|
- menu_options=["add_group", "remove_group", "finish"],
|
|
|
+ menu_options=["manage_locks", "add_group", "remove_group", "finish"],
|
|
|
)
|
|
|
|
|
|
+ async def async_step_manage_locks(self, user_input=None) -> ConfigFlowResult:
|
|
|
+ errors: dict[str, str] = {}
|
|
|
+ current_lock_ids: list[str] = self._entry.data.get(CONF_LOCK_ENTITY_IDS, [])
|
|
|
+
|
|
|
+ if user_input is not None:
|
|
|
+ new_lock_ids: list[str] = user_input.get(CONF_LOCK_ENTITY_IDS, [])
|
|
|
+ if not new_lock_ids:
|
|
|
+ errors[CONF_LOCK_ENTITY_IDS] = "no_locks_selected"
|
|
|
+ else:
|
|
|
+ removed = set(current_lock_ids) - set(new_lock_ids)
|
|
|
+ if removed:
|
|
|
+ self._groups = [
|
|
|
+ g for g in self._groups
|
|
|
+ if not all(lid in removed for lid in g.get(CONF_LOCK_ENTITY_IDS, []))
|
|
|
+ ]
|
|
|
+ for g in self._groups:
|
|
|
+ g[CONF_LOCK_ENTITY_IDS] = [
|
|
|
+ lid for lid in g.get(CONF_LOCK_ENTITY_IDS, []) if lid not in removed
|
|
|
+ ]
|
|
|
+ self._groups = [g for g in self._groups if g.get(CONF_LOCK_ENTITY_IDS)]
|
|
|
+ self.hass.config_entries.async_update_entry(
|
|
|
+ self._entry, data={CONF_LOCK_ENTITY_IDS: new_lock_ids}
|
|
|
+ )
|
|
|
+ return await self.async_step_init()
|
|
|
+
|
|
|
+ schema = vol.Schema({
|
|
|
+ vol.Required(CONF_LOCK_ENTITY_IDS, default=current_lock_ids): selector.EntitySelector(
|
|
|
+ selector.EntitySelectorConfig(
|
|
|
+ domain="lock",
|
|
|
+ integration="zwave_js",
|
|
|
+ multiple=True,
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ })
|
|
|
+ return self.async_show_form(step_id="manage_locks", data_schema=schema, errors=errors)
|
|
|
+
|
|
|
async def async_step_add_group(self, user_input=None) -> ConfigFlowResult:
|
|
|
errors: dict[str, str] = {}
|
|
|
lock_ids: list[str] = self._entry.data[CONF_LOCK_ENTITY_IDS]
|