Skip to content

Fix config flow for multiple locks #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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