Skip to content

Commit 10616f9

Browse files
authored
Fix config flow for multiple locks (#49)
1 parent 4113bc7 commit 10616f9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

custom_components/lock_code_manager/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ async def async_update_listener(hass: HomeAssistant, config_entry: ConfigEntry)
406406
entry_title,
407407
lock,
408408
)
409-
coordinator = hass_data[entry_id][COORDINATORS][lock_entity_id]
409+
coordinator = hass_data[entry_id][COORDINATORS][
410+
lock_entity_id
411+
] = hass_data[COORDINATORS][lock_entity_id]
410412
else:
411413
_LOGGER.debug(
412414
"%s (%s): Creating coordinator for lock %s",

custom_components/lock_code_manager/config_flow.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DEFAULT_START,
3232
DOMAIN,
3333
)
34+
from .data import get_entry_data
3435
from .helpers import CODE_SLOT_SCHEMA, CODE_SLOTS_SCHEMA, UI_CODE_SLOT_SCHEMA
3536

3637
_LOGGER = logging.getLogger(__name__)
@@ -64,8 +65,12 @@ def _check_common_slots(
6465
(lock, common_slots, entry.title)
6566
for lock in locks
6667
for entry in hass.config_entries.async_entries(DOMAIN)
67-
if lock in entry.data[CONF_LOCKS]
68-
and (common_slots := sorted(set(entry.data[CONF_SLOTS]) & set(slots_list)))
68+
if lock in get_entry_data(entry, CONF_LOCKS, {})
69+
and (
70+
common_slots := sorted(
71+
set(get_entry_data(entry, CONF_SLOTS, {})) & set(slots_list)
72+
)
73+
)
6974
and not (config_entry and config_entry == entry)
7075
)
7176
except StopIteration:
@@ -231,7 +236,7 @@ async def async_step_reauth(self, user_input: dict[str, Any]):
231236
additional_errors, additional_placeholders = _check_common_slots(
232237
self.hass,
233238
user_input[CONF_LOCKS],
234-
config_entry.data[CONF_SLOTS].keys(),
239+
get_entry_data(config_entry, CONF_SLOTS, {}).keys(),
235240
config_entry,
236241
)
237242
errors.update(additional_errors)
@@ -304,7 +309,7 @@ async def async_step_init(
304309

305310
def _get_default(key: str) -> Any:
306311
"""Get default value."""
307-
return user_input.get(key, self.config_entry.data[key])
312+
return user_input.get(key, get_entry_data(self.config_entry, key, {}))
308313

309314
return self.async_show_form(
310315
step_id="init",

0 commit comments

Comments
 (0)