EV-69: an ended phase change's close values stay own (no false CHARGER_OTHER)

A phase change that ends on MAX_TRIES (both writers) or on Solar's EV-60 cap
end now carries every value it tried, its 0 A too, until the first of: an own
take, any own current write, a user change, a hold, Solar's charger return.
A carried take resets fails/gave_up only (GUR). Tests: test_ev69.py (T1-T20,
T23-T25), test_ev69_fuzz.py (T21), tools/ev69_kit.py.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-12-03 23:53:54 +01:00
parent de733f44bf
commit 7d1ed1bbcf
4 changed files with 1112 additions and 1 deletions
+41 -1
View File
@@ -152,6 +152,7 @@ class ManualWriter:
self._close_k = 0 # EV-59: not-taken closes of the value owed
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
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
@@ -172,6 +173,7 @@ class ManualWriter:
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
self._late = None # EV-52: that request is not current now
self._rec_a = None # EV-56 (G2): a raise is logged again
@@ -240,6 +242,7 @@ class ManualWriter:
self._close_k = 0
if cur is not None:
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.
late, self._late = self._late, None
if late is not None and abs(cur - float(late[0])) <= TOL_A:
@@ -301,7 +304,23 @@ class ManualWriter:
if x is not None]
if self.seq is not None:
vals += self.seq.get("own", ())
return vals
return vals + self._carry
def _carry_ok(self) -> bool:
"""EV-69: may an ended sequence's values be carried? Manual: yes."""
return True
def _carry_end(self, q) -> None:
"""EV-69 (OQ1, OQ2): a sequence ended (MAX_TRIES, or Solar's EV-60 cap
end): every value it tried, its 0 A too, stays own on the lifetime of
`attempted_a`/`prior_a`, for a late take of an earlier close. Not when
the end's own value is already taken (`_carry_ok`). It ends at an own
take, any own current write, a user change, a hold, Solar's return."""
self._carry = list(q.get("own", ())) if self._carry_ok() else []
def _carried_take(self) -> None:
"""EV-69 (GUR): the charger shows a carried close. Own; the carry
stays. Manual: nothing changes."""
def _watch(self, cur, now, judge=True) -> None:
"""Is the read-back what we wrote? A difference that stands for
@@ -317,11 +336,15 @@ class ManualWriter:
known = self._own_values()
if known and cur is not None:
diff = not any(abs(cur - k) <= TOL_A for k in known)
if not diff and cur > TOL_A and any(
abs(cur - k) <= TOL_A for k in self._carry):
self._carried_take()
if diff or self._ph_diff:
if self.mismatch_since is None:
self.mismatch_since = now
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
if diff:
_LOG.info("Something else changes the charger (read-back "
"%.0f A, the add-on set %.0f A), so the add-on "
@@ -382,6 +405,7 @@ class ManualWriter:
# EV-56: a raise at shutdown is left to the caller (CHARGER_RESTORE).
strict = kw.pop("strict", False)
self._late = None
self._carry = [] # EV-69: a new own write ends the carry
if self._rec_a is not None and abs(self._rec_a - float(a)) > TOL_A:
self._rec_a = None # EV-56 (G2): another value
tracker.begin_write() # EV-12: the read-back is ours
@@ -512,6 +536,7 @@ class ManualWriter:
self._took_as_is()
return
self.hold = self.other = True
self._carry = []
_LOG.info("Something else raised the charger's current during a "
"phase change, so the phases were not touched.")
return
@@ -588,6 +613,7 @@ class ManualWriter:
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._carry_end(q) # EV-69: the closes tried stay own
self.seq, self.last_a, self.reapply = None, None, True
self._close_end(now)
self.rev_applied = None
@@ -1174,6 +1200,17 @@ class SolarWriter(ManualWriter):
went (`_write`), a cut try in `cut_fails` too, so the sequence's end
adds nothing (Manual's `_close_end` is EV-59's, unchanged)."""
def _carry_ok(self) -> bool:
"""EV-69 (formal Dev note 2): the end's own value (`sent_a`) was
already taken (an `_adopt` earlier in the step): nothing is carried."""
return not self.taken
def _carried_take(self) -> None:
"""EV-69 GUR: a carried take resets `fails` and `gave_up` only, never
`taken` or `last_a`: `sent_a` stays owed, so the clamp value is sent
again at the next RETRY_S step."""
self.fails, self.gave_up = 0, False
def _cut_gate(self, now) -> bool:
"""EV-60 (Q1): the quarter key's cut tries are used up, or the last
refused one is less than RETRY_S old (`_put`'s two gates)."""
@@ -1199,6 +1236,7 @@ class SolarWriter(ManualWriter):
v = inner(q)
if self._cut_try(min(max(float(v), CH.MIN_A), hi)):
if self.cut_fails >= MAX_TRIES:
self._carry_end(q) # EV-69: the closes stay own
self.seq, self.last_a, self.reapply = None, None, True
self.rev_applied = None
self.plan.end_switch(False)
@@ -1251,6 +1289,7 @@ class SolarWriter(ManualWriter):
self.startup_zero = False
self.last_a = cur
self.attempted_a = self.prior_a = None
self._carry = [] # EV-69: an own take ends the carry
self.fails, self.fail_at, self.gave_up = 0, None, False
self.refused_cut = None
if self.sent_cut:
@@ -1598,6 +1637,7 @@ class SolarWriter(ManualWriter):
if not self.hold:
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._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))