EV-59: Manual gives one value at most MAX_TRIES tries per user change

A refused phase-change close ended its sequence with one `_failed`, so the
same value got 5 tries (3 closes, then 2 on the normal path). Manual now
counts the not-taken closes of the value owed since the last user change
(`_close_k`); at the capped close end `fails` = that count, so `gave_up` and
CHARGER_REFUSED come at the 3rd refused close, and a value changed during the
retries still gets 3 tries. SolarWriter overrides the end hook and is
unchanged (EV-60).

Tests: new test_ev59.py; test_ev56 T5, T5b and the T20 T5 [R] golden,
test_ev28 T15 and the test_ev13 T13 text per the brief rulings.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-12-01 02:40:49 +01:00
parent 1b909fb7bd
commit 009393a5ee
5 changed files with 709 additions and 16 deletions
+19 -1
View File
@@ -149,6 +149,7 @@ class ManualWriter:
self._r = None # the latest reading, for the phase count
self._late = None # (a, was, why, n) of a write not taken
self._rec_a = None # EV-56: the raised value already logged
self._close_k = 0 # EV-59: not-taken closes of the value owed
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
@@ -159,6 +160,7 @@ class ManualWriter:
self.hold = self.other = False
self.mismatch_since = None
self.fails, self.fail_at, self.gave_up = 0, None, False
self._close_k = 0 # EV-59
self.phase_fails, self.phases_gave_up = 0, False
self.attempted_a = self.prior_a = None
self._late = None # EV-52: that request is not current now
@@ -223,6 +225,7 @@ class ManualWriter:
if not (phases_need or cur_need):
self.rev_applied, self.reapply = rev, False
self.fails, self.blocked = 0, False
self._close_k = 0
if cur is not None:
self.last_a = cur # adopt what is already set
# EV-52 (PM Q2): a write taken late is logged once, here.
@@ -249,6 +252,7 @@ class ManualWriter:
self._failed(now)
return
self.fails, self.fail_at = 0, None
self._close_k = 0
if not phases_need:
self.rev_applied, self.reapply = rev, False
@@ -262,6 +266,15 @@ class ManualWriter:
"stops asking until you change it: CHARGER_REFUSED.")
_LOG.debug("The charger refused the current %d times.", self.fails)
def _close_end(self, now) -> None:
"""EV-59: the closing current was refused MAX_TRIES times in this
sequence. The value owed has had `_close_k` not-taken closes since the
last user change: `fails` is that count, so the give-up comes only
when the value has used all its tries; else the normal path gives the
rest."""
self.fails = max(min(self._close_k, MAX_TRIES) - 1, 0)
self._failed(now)
def _watch(self, cur, now) -> None:
"""Is the read-back what we wrote? A difference that stands for
`WRITER_S` is another writer."""
@@ -500,15 +513,17 @@ class ManualWriter:
# still wanted, and one that is in place is adopted.
self.seq, self.rev_applied, self.reapply = None, None, False
self.fails, self.blocked = 0, False
self._close_k = 0
if not q.get("failed"):
self.phase_done_at = self.last_done # EV-15
return
q["failed"] = True # EV-15: a refused write ends it
q["tries"] += 1
self._close_k += 1 # EV-59: read by Manual's end only
if q["tries"] >= MAX_TRIES:
# Left at 0 A is the safe side; the next reading re-applies.
self.seq, self.last_a, self.reapply = None, None, True
self._failed(now)
self._close_end(now)
self.rev_applied = None
return
q["t1"] = now - SETTLE_S + 5.0 # again in 5 s
@@ -1068,6 +1083,9 @@ class SolarWriter(ManualWriter):
or Solar's."""
return "peak cut" if q.get("cut") else "Solar"
def _close_end(self, now) -> None:
self._failed(now) # EV-59: Solar stays as it was (EV-60)
def _failed(self, now) -> None:
if self.sent_cut:
# EV-54 (Q1, F7): a refused cut try counts against the quarter's