Skip to content

Commit 39691a1

Browse files
kingpanther13claude
andcommitted
refactor(flows): extract the edit-mode submission decision
The caller-intent-before-backfill branches pushed _redeclared_field_submission to C901 12 > 10. Repo policy is extract, never a per-file ignore, and the extracted decision stands on its own: what to submit for an edit-mode field the caller named no key for at THIS step. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012d29UJTiH4Uy2Pm37SBPtr
1 parent 52c590f commit 39691a1

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

src/ha_mcp/tools/config_entry_flow_form.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,36 @@ def _current_value_backfill(field: dict[str, Any]) -> tuple[Any, bool]:
423423
return step_owned, False
424424

425425

426+
def _edit_mode_submission(
427+
field: dict[str, Any],
428+
name: str,
429+
path_prefix: str,
430+
dotted: str,
431+
reuse_state: _ReuseState,
432+
) -> tuple[Any, bool]:
433+
"""Decide an edit-mode field the caller named no key for at THIS step.
434+
435+
The caller's intent outranks the step's stored value for the whole walk.
436+
``begin_step`` clears only ``filled``, so by a later step the caller's key
437+
is gone from ``remaining_config`` and nothing marks the field as theirs —
438+
but ``scoped``/``flat`` still hold what they asked for. Backfilling over
439+
that resubmitted the entry's stored value and undid it: a recorded
440+
``None`` is the clear this mode documents, and a recorded value is the one
441+
the caller asked to write (Patch76 review, issue #2254).
442+
443+
Only a field the caller never named anywhere falls through to the step's
444+
own value.
445+
"""
446+
recorded = reuse_state.recorded_value(path_prefix, name)
447+
if recorded is _MISSING_DEFAULT:
448+
return _current_value_backfill(field)
449+
if recorded is None:
450+
return _NO_SUBMISSION
451+
if not reuse_state.claim_write(dotted):
452+
return _NO_SUBMISSION
453+
return recorded, True
454+
455+
426456
def _redeclared_field_submission(
427457
field: dict[str, Any],
428458
name: str,
@@ -479,21 +509,7 @@ def _redeclared_field_submission(
479509
if not allow_reuse or not field.get("required"):
480510
if not keep_current_values:
481511
return _NO_SUBMISSION
482-
# The caller's intent outranks the step's stored value for the WHOLE
483-
# walk. ``begin_step`` clears only ``filled``, so by a later step the
484-
# caller's key is gone from ``remaining_config`` and nothing here
485-
# marks the field as theirs — but ``scoped``/``flat`` still hold what
486-
# they asked for. Backfilling over that resubmitted the stored value
487-
# and undid it: a recorded ``None`` is the clear this mode documents,
488-
# and a recorded value is the one the caller asked to write.
489-
recorded = reuse_state.recorded_value(path_prefix, name)
490-
if recorded is not _MISSING_DEFAULT:
491-
if recorded is None:
492-
return _NO_SUBMISSION
493-
if not reuse_state.claim_write(dotted):
494-
return _NO_SUBMISSION
495-
return recorded, True
496-
return _current_value_backfill(field)
512+
return _edit_mode_submission(field, name, path_prefix, dotted, reuse_state)
497513
step_owned = _step_owned_submission_value(field)
498514
if step_owned is not _MISSING_DEFAULT:
499515
return step_owned, False

0 commit comments

Comments
 (0)