EV-71: Solar and Manual keep their own untaken non-zero write as their own
checks / unit (pull_request) Successful in 58m47s
infra-pin / fresh (pull_request) Successful in 2s

A press that lifts nothing no longer clears attempted_a, prior_a, the EV-69
carry or the new kept value; a held read no longer adopts (no taken, carry
untouched, the owed 0 A is written); a refused 0 A no longer loses the
untaken non-zero value. The kept value ends at a fresh own take, a different
non-zero write, a lifting press, a hold or Solar's charger return.

Existing tests edited only as the brief allows: test_ev69.py T12 (press
alone) and T24 setup, test_ev69_fuzz.py N4, N1b user cause, I1, I2.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-12-05 00:22:01 +01:00
parent 278041b25c
commit 0eb332d93f
4 changed files with 714 additions and 22 deletions
+46 -6
View File
@@ -153,13 +153,17 @@ class ManualWriter:
self._ph_diff = False # EV-22: the phases differ from our own
# (Solar only; Manual never sets it)
self._carry = [] # EV-69: the closes an ended sequence tried
self._kept = None # EV-71: an own non-zero write not seen taken
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
"""The user changed the mode or a value: one more write is allowed,
and another writer's hold is lifted. EV-22 (DA1): a change that lifts
a difference inside a phase change ends the change at its 0 A; the
raise check never holds over the value the user's change took."""
raise check never holds over the value the user's change took.
EV-71 (P1): a press that lifts no count and no hold ends nothing of
our own: `attempted_a`, `prior_a`, the carry and the kept value stay."""
lifts = self._other_stands()
if self.seq is not None:
if self._other_stands():
self.seq = None
@@ -172,8 +176,12 @@ class ManualWriter:
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._carry = [] # EV-69: a user change ends the carry
if lifts:
# EV-71 P1: a press that lifts a count or hold ends everything
# (EV-22 DA1); one that lifts nothing ends nothing.
self.attempted_a = self.prior_a = None
self._carry = [] # EV-69: a lifting user change ends the carry
self._kept = None
self._late = None # EV-52: that request is not current now
self._rec_a = None # EV-56 (G2): a raise is logged again
@@ -241,6 +249,7 @@ class ManualWriter:
self.fails, self.blocked = 0, False
self._close_k = 0
if cur is not None:
self._kept_end() # EV-71 (Q6): a take ends it too
self.last_a = cur # adopt what is already set
self._carry = [] # EV-69: an own take ends the carry
# EV-52 (PM Q2): a write taken late is logged once, here.
@@ -300,12 +309,24 @@ class ManualWriter:
try, and (EV-22, C7) every value of the phase change under way: its
0 A and each closing current it tried (also after a user change
cleared `attempted_a`)."""
vals = [x for x in (self.last_a, self.attempted_a, self.prior_a)
if x is not None]
vals = [x for x in (self.last_a, self.attempted_a, self.prior_a,
self._kept) if x is not None] # EV-71: kept
if self.seq is not None:
vals += self.seq.get("own", ())
return vals + self._carry
def _kept_end(self) -> None:
"""EV-71: the kept value ends (a hold over another writer's value, a
fresh take, a lifting press, Solar's return). It is also no longer
`attempted_a` or `prior_a`, where the same untaken value may sit."""
k, self._kept = self._kept, None
if k is not None:
if self.attempted_a is not None \
and abs(self.attempted_a - k) <= TOL_A:
self.attempted_a = None
if self.prior_a is not None and abs(self.prior_a - k) <= TOL_A:
self.prior_a = None
def _carry_ok(self) -> bool:
"""EV-69: may an ended sequence's values be carried? Manual: yes."""
return True
@@ -345,6 +366,7 @@ class ManualWriter:
elif now - self.mismatch_since >= WRITER_S and not self.hold:
self.hold = self.other = True
self._carry = [] # EV-69: never own after a hold
self._kept_end() # EV-71 (OQ1): nor the kept value
if diff:
_LOG.info("Something else changes the charger (read-back "
"%.0f A, the add-on set %.0f A), so the add-on "
@@ -434,13 +456,23 @@ class ManualWriter:
if ok:
self.last_a = a
self.attempted_a = self.prior_a = None
self._kept = None # EV-71 (Q6): a taken write
self._rec_a = None # EV-56 (G2): a taken write
self._log_set(a, was, why, n)
else:
self.attempted_a, self.prior_a = a, was
self._keep(a)
self._late = (a, was, why, n) # logged if it is adopted later
return ok
def _keep(self, a) -> None:
"""EV-71 (Q4-Q6): a non-zero write the charger did not take is kept
own, whatever the next try overwrites in `attempted_a`/`prior_a`. A
0 A never ends it (Q5) and never sets it; another non-zero value
replaces it, the same one keeps it (Q2)."""
if float(a) > TOL_A:
self._kept = float(a)
def _raised(self, err, a, was, now, why, n) -> None:
"""EV-56: a write that raised (an HA call error, a setup error, a bug)
is a try the charger did not take, counted by the caller as a refusal
@@ -448,6 +480,7 @@ class ManualWriter:
ERROR record, with the traceback, comes once per raised value (Q1)."""
self.log.append(("current", a, now, False))
self.attempted_a, self.prior_a = a, was
self._keep(a) # EV-71
self._late = (a, was, why, n) # logged if it is adopted later
if self._rec_a is None:
self._rec_a = float(a)
@@ -528,6 +561,7 @@ class ManualWriter:
# changes something.
self.seq = None
self.last_a = self.attempted_a = self.prior_a = None
self._kept = None # EV-71: the change is given up
if pressed:
# EV-22 (DA1): the user's change came during this change and
# this is the first reading judged after it: the charger is
@@ -1173,6 +1207,7 @@ class SolarWriter(ManualWriter):
_LOG.debug("The peak cut write failed: %s", e)
self.log.append(("current", a, now, False))
self.attempted_a, self.prior_a = a, was
self._keep(a) # EV-71
ok = False
finally:
if zero:
@@ -1287,6 +1322,7 @@ class SolarWriter(ManualWriter):
self._owed(False)
self.taken = True
self.startup_zero = False
self._kept = None # EV-71 (Q6): a fresh take ends it
self.last_a = cur
self.attempted_a = self.prior_a = None
self._carry = [] # EV-69: an own take ends the carry
@@ -1341,7 +1377,10 @@ class SolarWriter(ManualWriter):
await self._write(drv, want, cur, now, tracker,
why=self.sent_why)
return
if not stuck and cur is not None and abs(cur - want) <= TOL_A:
if not stuck and cur is not None and abs(cur - want) <= TOL_A \
and not self.held_step:
# EV-71 (P2): a held read shows the reading from before our write,
# so it takes nothing: the owed 0 A below goes out instead.
self.sent_a = want # it already stands
self._adopt(cur)
return
@@ -1638,6 +1677,7 @@ class SolarWriter(ManualWriter):
self._reset_phases(window=False) # EV-22: start state again
self.last_a = self.attempted_a = self.prior_a = None
self._carry = [] # EV-69: the return ends the carry
self._kept = None # EV-71: and the kept value
self._rec_a = None # EV-56 (G2): logged again
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
stuck = bool(tracker is not None and tracker.stuck(now))