Skip to content

Commit ea0f6a0

Browse files
committed
Fix config flow for multiple locks
1 parent 9ac355d commit ea0f6a0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

custom_components/lock_code_manager/config_flow.py

+9-4
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.data, key, {}))
308313

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

0 commit comments

Comments
 (0)