refactor: make config flow existing-codes confirmation informational only#1103
refactor: make config flow existing-codes confirmation informational only#1103
Conversation
When the config flow detects existing codes on lock slots and the user
confirms clearing, the UI now shows a progress step ("Clearing existing
codes from N slot(s) across M lock(s)...") instead of hanging with no
feedback.
Uses HA's async_show_progress/async_show_progress_done pattern:
clearing runs as a background task, and the flow advances when done.
For fast operations (or in tests with mocked locks), the progress step
is transparent — the flow advances directly to the next step.
Clearing now happens during the progress step rather than being
deferred to entry creation, which is more intuitive — the codes are
gone by the time the user configures slots.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 3eb7b42e909f
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1103 +/- ##
==========================================
- Coverage 95.71% 95.69% -0.02%
==========================================
Files 48 48
Lines 5595 5574 -21
Branches 503 503
==========================================
- Hits 5355 5334 -21
Misses 240 240
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: ccb7e44e9e79
Progress message now shows "Clearing existing codes (2/6)..." with a live counter that updates as each slot×lock clear operation completes. The counter increments after each individual clear call (including failures), giving the user real feedback on long operations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: fc9c80a3ce5d
Cloud-based locks (Schlage) can take 20-30s per API call. Local locks (Z-Wave, ZHA, Matter) are much faster (~1-5s). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 417bb89a63e4
There was a problem hiding this comment.
Pull request overview
Adds a Home Assistant config-flow progress step so users get visual feedback while existing lock codes are being cleared (instead of the UI appearing to hang during long per-lock API calls).
Changes:
- Run existing-code clearing as a background task and expose progress via
async_show_progress/async_show_progress_done. - Add
clearing_codesprogress translations for both config flow and options flow. - Update config-flow UI test expectations to reflect clearing happening before slot configuration.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
custom_components/lock_code_manager/config_flow.py |
Introduces a progress step (existing_codes_clear) backed by a background task and advances the flow after clearing completes. |
custom_components/lock_code_manager/strings.json |
Adds progress-action translation key clearing_codes under both config and options. |
custom_components/lock_code_manager/translations/en.json |
Mirrors the new progress translations in the English translation file. |
tests/test_config_flow.py |
Updates existing-codes confirmation test assertions to match the new clearing timing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Avoids duplicating the slot×lock iteration — the total is computed once at the start of clearing, right next to the loop that uses it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 7a36912a57fc
Replace separate _clear_existing_slot method and double iteration with a single comprehension that builds the (lock_instance, entity_id, slot_num) work list. The loop just iterates it and increments the counter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: baba39fc44a4
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 372839965d29
The config flow no longer clears existing codes from locks. The sync manager already handles all reconciliation when the config entry loads: setting, clearing, or re-setting codes as needed based on the configured state. The confirmation dialog is now informational — it shows which lock/slot pairs have existing codes (e.g. "lock.front_door: slot 1") and warns that they will be overwritten. No clearing happens during the flow. This removes the progress step, background task, clearing logic, and lock_instances tracking from the mixin. The occupied lock/slot pairs are computed once when detecting existing codes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: e57e4b74516d
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…comments - Remove _lock_instances from mixin (dead state after clearing removal) - Simplify _async_get_all_codes to return just codes_by_lock dict - Simplify _scope_codes_to_pairs to drop instances parameter - Update test names and docstrings from "clear" to "continue" - Remove stale clearing assertions and unused lock_instances variables - Fix all test patches to return dict instead of (dict, instances) tuple Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: a5b020dc4b8d
- Remove disconnected mock_clear/mock_lock variables from tests - Fix _maybe_confirm_then_persist docstring: "confirm clear" -> "show confirmation if any exist" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Entire-Checkpoint: d69513d6bdb0
Proposed change
The config flow no longer clears existing codes from locks during setup. The sync manager already handles all reconciliation when the config entry loads — setting, clearing, or re-setting codes as needed.
Before
When the config flow detected existing codes on lock slots, it would:
After
The confirmation dialog is now informational only. It shows which specific lock/slot pairs have existing codes:
The user acknowledges and proceeds. When the config entry loads, the sync manager reconciles everything — no manual clearing needed.
What was removed
_clear_existing_slot,_clear_all_pending_slots, progress step, background task)_lock_instancestracking (was only used for clearing)_clear_then_create_entry→ simplified to_create_entryWhat was changed
_slots_with_existing_codes→_find_occupied_lock_slots— now returns(lock_entity_id, slot_num)tuples instead of just slot numbers{details}placeholderType of change
Additional information