EV-20 review round 2: one write clock for every non-zero current (C6, N5)
checks / unit (pull_request) Successful in 30m56s
infra-pin / fresh (pull_request) Successful in 2s

ManualWriter._write, the one write_current call, stamps every non-zero
current either writer sends; Solar's 30 s gate reads that stamp (its own and
Manual's), so the step back up after a phase change's closing write waits 30
s on every path. The closing current is fixed once per sequence, retries too.
Rows: every select shape (refused, ignored, late; settle refused three times;
T7 1 -> 3 and T22 3 -> 1) with nevers().

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-23 01:25:06 +01:00
parent 9c82bc816a
commit cd8c393161
3 changed files with 81 additions and 8 deletions
+22 -5
View File
@@ -139,6 +139,7 @@ class ManualWriter:
self.undone = 0 # sequences undone before the select
self.phase_done_at = None # EV-15: our phase change ended well then
self.zero_sent_at = None # EV-15: our 0 A write is out, not yet back
self.nonzero_at = None # EV-20 C6: the latest non-zero write sent
# ------------------------------------------------------------------ user
def user_changed(self) -> None:
@@ -263,6 +264,11 @@ class ManualWriter:
async def _write(self, drv, a, was, now, tracker, **kw) -> bool:
tracker.begin_write() # EV-12: the read-back is ours
if float(a) > TOL_A:
# EV-20 C6, THE ONE WRITE CLOCK: every non-zero current either
# writer sends, whatever path it comes from, is stamped here (the
# one write_current call). Solar's 30 s gate reads this stamp.
self.nonzero_at = now
try:
# EV-20: `kw` is only Solar's shorter read-back wait at shutdown.
ok = await drv.write_current(a, **kw)
@@ -874,7 +880,9 @@ class SolarWriter(ManualWriter):
>= PHASE_GAP_S
def _plan_step(self, sun, now, clamp, n_now, gap_ok) -> None:
self.plan.ext_at = self.other_at
# C6: the write clock, Solar's own latest non-zero write and Manual's.
self.plan.ext_at = max((t for t in (self.nonzero_at, self.other_at)
if t is not None), default=None)
self.plan.step(
now, target_w=sun.target_w, hold=sun.hold, n_now=n_now,
auto=sun.auto and not self.single and not self.phases_gave_up,
@@ -902,6 +910,14 @@ class SolarWriter(ManualWriter):
new phases and for the phases the charger reports, so nothing meant
for 1 phase is ever written on 3 (review round 1, Major 1)."""
def want(q):
if "close_a" in q:
return q["close_a"] # one value per sequence, its retries too
q["close_a"] = a = self._close_a(q, clamp, n_reported)
return a
return want
def _close_a(self, q, clamp, n_reported):
if True:
before = self.plan._before
if q.get("failed") and not q.get("sel") and before is not None:
return before[0] if before[0] >= CH.MIN_A else CH.MIN_A
@@ -912,7 +928,6 @@ class SolarWriter(ManualWriter):
if b is not None:
a = min(a, max(b, CH.MIN_A))
return a
return want
async def _begin_solar(self, drv, r, cur, n, now, tracker) -> None:
"""Step 1 of the safe sequence: 0 A (kept when it already stands).
@@ -1079,10 +1094,12 @@ class SolarWriter(ManualWriter):
# one the plan keeps the current it wrote (the lower one) and
# takes the phases the charger reports from the next cycle.
done = not q.get("failed") or bool(q.get("sel"))
if done and q.get("sel") and self.sent_a is not None \
and self.sent_a >= CH.MIN_A:
self.plan.a = min(self.plan.a, self.sent_a)
self.plan.end_switch(done)
close = q.get("close_a")
if close is not None and close >= CH.MIN_A:
# The sequence ended on this current: the plan's current
# now (its 30 s count is the write clock's, `_write`).
self.plan.a = float(close)
return
self._plan_step(sun, now, clamp, n_now, gap)
want = self.amps_out(clamp)
+1 -3
View File
@@ -379,9 +379,7 @@ class CarMixin:
w = self.car_solar
if self.car_mode == carmode.SOLAR or w.engaged:
# C6: one write clock: Manual's latest non-zero write counts.
w.other_at = max((t for kind, a, t, ok in self.car_writer.log
if kind == "current" and a > carmode.TOL_A),
default=None)
w.other_at = self.car_writer.nonzero_at
sun = None
if self.car_mode == carmode.SOLAR:
sun = getattr(self, "_car_sun_now", None) \
+58
View File
@@ -728,6 +728,64 @@ for how, sim_ in (("settle write refused once",
and rm1["sim"].phases_allowed == 3
and rm1["sim"].setpoint_a == 10.0)
nevers(rm1, f"T19/T33 [{how}]")
# Review round 2 (C6, N5): every select shape, 1 -> 3 (T7) and 3 -> 1 (T22):
# no current meant for fewer phases than the charger has, and never two
# different non-zero currents under 30 s apart (the one write clock).
class PhSim(TSim):
"""The phases select: 'lag' (read-back 12 s late), 'error' (HA refuses
it), 'ignore' (HA says yes, the charger keeps its phases)."""
ph_mode = None
def request_phases(self, n):
if self.ph_mode == "lag":
keep, self.lag_s = self.lag_s, 12.0
try:
return super().request_phases(n)
finally:
self.lag_s = keep
keep, self.refuse = self.refuse, self.ph_mode or self.refuse
try:
return super().request_phases(n)
finally:
self.refuse = keep
def _phsim(windows=(), ph=None):
s_ = PhSim(setpoint_a=0, windows=list(windows))
s_.ph_mode = ph
return s_
sun31 = step_fn((300, 600.0 + 4600.0), (700, 600.0 + 3700.0),
base=600.0 + 3000.0)
for how, shape, sim_, back in (
("select refused", "T7", _phsim(ph="error"), 16.0),
("select ignored", "T7", _phsim(ph="ignore"), 16.0),
("select late", "T7", _phsim(ph="lag"), 10.0),
("settle refused 3 times", "T7", _phsim([(313, 330, "error")]), None),
("normal", "T22", _phsim(), None),
("select refused", "T22", _phsim(ph="error"), None),
("select ignored", "T22", _phsim(ph="ignore"), None),
("select late", "T22", _phsim(ph="lag"), None)):
if shape == "T7":
rs_ = S.drive(const(900.0), const(7900.0), dur=900, sim=sim_,
first="car", socs={"a": 71.0, "b": 100.0})
cap3 = 10.0
else:
rs_ = S.drive(const(600.0), sun31, dur=1500, sim=sim_, first="car",
socs={"a": 19.0, "b": 19.0})
cap3 = 5.0 # 3700 - 600 - 100 W on 3 phases, under 6 A
over = [(x["t"], x["sp"]) for x in rs_["trace"]
if x["ph"] == 3 and x["sp"] > max(cap3, 6.0) and x["t"] > 300]
bad_ = nevers(rs_, f"round 2 [{shape}, {how}]")
end = rs_["trace"][-1]
check(f"round 2 [{shape}, {how}]: no current meant for fewer phases on "
f"the charger's ({over[:3]}); end {end['sp']} A on {end['ph']} "
f"phases ({[(x[0], x[1], x[2]) for x in rs_['sim'].log]})",
not over and not bad_
and (back is None or (end["sp"] == back)))
r19a = std(1800, sun=const(600.0 + 6900.0), opts={"ev_phases": "1"})
check(f"T19: fixed 1 with 6.9 kW for 30 min: no select, 16 A "
f"({cur_writes(r19a)})", selects(r19a) == []