Skip to content

refactor: make config flow existing-codes confirmation informational only#1103

Merged
raman325 merged 11 commits intomainfrom
fix/config-flow-clear-progress
Apr 29, 2026
Merged

refactor: make config flow existing-codes confirmation informational only#1103
raman325 merged 11 commits intomainfrom
fix/config-flow-clear-progress

Conversation

@raman325
Copy link
Copy Markdown
Owner

@raman325 raman325 commented Apr 28, 2026

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:

  1. Show a confirmation dialog listing slot numbers
  2. Clear codes directly via lock provider API calls (which could take 30s+ per call on Schlage)
  3. The UI would hang with no feedback during clearing

After

The confirmation dialog is now informational only. It shows which specific lock/slot pairs have existing codes:

- lock.front_door: slot 1
- lock.front_door: slot 2
- lock.garage: slot 1

The user acknowledges and proceeds. When the config entry loads, the sync manager reconciles everything — no manual clearing needed.

What was removed

  • All clearing logic from the config flow mixin (_clear_existing_slot, _clear_all_pending_slots, progress step, background task)
  • _lock_instances tracking (was only used for clearing)
  • Progress step and translation strings
  • _clear_then_create_entry → simplified to _create_entry

What was changed

  • _slots_with_existing_codes_find_occupied_lock_slots — now returns (lock_entity_id, slot_num) tuples instead of just slot numbers
  • Confirmation dialog shows per-lock/slot details via {details} placeholder
  • Menu option renamed from "Clear existing codes and continue" to "Continue"

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue:
  • This PR is related to issue:

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
Copilot AI review requested due to automatic review settings April 28, 2026 16:51
@github-actions github-actions Bot added python Pull requests that update Python code bug Something isn't working labels Apr 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.69%. Comparing base (11239c4) to head (aed7e72).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            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              
Flag Coverage Δ
python 97.25% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
custom_components/lock_code_manager/config_flow.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

raman325 and others added 3 commits April 28, 2026 13:02
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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_codes progress 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.

Comment thread tests/test_config_flow.py Outdated
Comment thread custom_components/lock_code_manager/strings.json Outdated
raman325 and others added 4 commits April 28, 2026 19:58
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
@raman325 raman325 changed the title feat: show progress indicator when clearing existing codes refactor: make config flow existing-codes confirmation informational only Apr 29, 2026
@raman325 raman325 requested a review from Copilot April 29, 2026 00:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/test_config_flow.py Outdated
Comment thread tests/test_config_flow.py Outdated
Comment thread tests/test_config_flow.py Outdated
Comment thread custom_components/lock_code_manager/config_flow.py
raman325 and others added 3 commits April 28, 2026 20:42
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
@raman325 raman325 merged commit 6540520 into main Apr 29, 2026
18 checks passed
@raman325 raman325 deleted the fix/config-flow-clear-progress branch April 29, 2026 04:22
raman325 added a commit that referenced this pull request Apr 29, 2026
* origin/main:
  fix: parenthesize multi-exception clause in _get_number_state (#1104)
  refactor: make config flow existing-codes confirmation informational only (#1103)

# Conflicts:
#	custom_components/lock_code_manager/config_flow.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants