Skip to content

Commit

Permalink
Fix config flow for multiple locks (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Mar 5, 2024
1 parent 4113bc7 commit 10616f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion custom_components/lock_code_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ async def async_update_listener(hass: HomeAssistant, config_entry: ConfigEntry)
entry_title,
lock,
)
coordinator = hass_data[entry_id][COORDINATORS][lock_entity_id]
coordinator = hass_data[entry_id][COORDINATORS][
lock_entity_id
] = hass_data[COORDINATORS][lock_entity_id]
else:
_LOGGER.debug(
"%s (%s): Creating coordinator for lock %s",
Expand Down
13 changes: 9 additions & 4 deletions custom_components/lock_code_manager/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DEFAULT_START,
DOMAIN,
)
from .data import get_entry_data
from .helpers import CODE_SLOT_SCHEMA, CODE_SLOTS_SCHEMA, UI_CODE_SLOT_SCHEMA

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,8 +65,12 @@ def _check_common_slots(
(lock, common_slots, entry.title)
for lock in locks
for entry in hass.config_entries.async_entries(DOMAIN)
if lock in entry.data[CONF_LOCKS]
and (common_slots := sorted(set(entry.data[CONF_SLOTS]) & set(slots_list)))
if lock in get_entry_data(entry, CONF_LOCKS, {})
and (
common_slots := sorted(
set(get_entry_data(entry, CONF_SLOTS, {})) & set(slots_list)
)
)
and not (config_entry and config_entry == entry)
)
except StopIteration:
Expand Down Expand Up @@ -231,7 +236,7 @@ async def async_step_reauth(self, user_input: dict[str, Any]):
additional_errors, additional_placeholders = _check_common_slots(
self.hass,
user_input[CONF_LOCKS],
config_entry.data[CONF_SLOTS].keys(),
get_entry_data(config_entry, CONF_SLOTS, {}).keys(),
config_entry,
)
errors.update(additional_errors)
Expand Down Expand Up @@ -304,7 +309,7 @@ async def async_step_init(

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

return self.async_show_form(
step_id="init",
Expand Down

0 comments on commit 10616f9

Please sign in to comment.