EV-05 round 3: a refused way-out 0 A is tried again; one cut per excess
checks / unit (pull_request) Successful in 24m5s
infra-pin / fresh (pull_request) Successful in 2s

Review of 17a7b29:
- Critical: every way out of Solar (Off, Stop, shadow, safety stop, charger
  error, stuck reading, no car) now owes a 0 A until the charger takes it:
  tried again 60 s apart, 3 times (EV-04's rule), then the gave-up row and
  CHARGER_REFUSED; never over another writer. Shutdown does not trust last_a
  while a write of ours is unconfirmed. The card no longer says paused while
  the 0 A is not taken.
- Major: an excess episode is taken off the car once, measured from the car's
  power when it began, until the car shows it and 15 s more.

Tests: refused-then-accepted 0 A for each exit, a 0 A never taken, shutdown
during a start write's read-back, a cut from 16 A with a slow car; the fuzz
checks refused exits of every kind (N9).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-18 12:15:00 +01:00
co-authored by Claude
parent 17a7b299d2
commit d2504efa82
9 changed files with 338 additions and 58 deletions
+137 -1
View File
@@ -997,7 +997,7 @@ fz = st31.get("fz", 0)
check(f"T31: a stuck reading after a write that moved the setpoint: 0 A once "
f"about 60 s after that write (+10 s read-back), the amber row, no "
f"write until a reading moves, then the start rule ({w31}, frozen at "
f"{fz})", [v for t, v in w31 if t < fz + 400].count(0.0) == 1
f"{fz})", 1 <= [v for t, v in w31 if t < fz + 400].count(0.0) <= 3
and any(v == 0.0 and 60 <= t - w31[0][0] <= 75 for t, v in w31)
and "charger_stuck" in st31.get("rows", [])
and all(t >= fz + 400 + 120 for t, v in w31 if v > 0 and t > fz + 100))
@@ -1554,6 +1554,142 @@ check(f"T52: in Solar the House tile and the house profile still leave the car "
f"out: car_term gives the car's own power ({_c52.car_term()})",
_c52.car_term()[1] is False and _c52.car_term()[0] > 2000)
# =========================================================================== #
print("\nROUND 3. A REFUSED WAY-OUT 0 A IS TRIED AGAIN; ONE CUT PER EXCESS (N9)")
# =========================================================================== #
def refusing(kind):
def f(p, c):
p.ch.refuse = kind
return f
def zlog(r, t0):
"""(second, A, taken) of each current write of the Solar writer."""
return [(round(t), v, ok) for k, v, t, ok in r["c"].car_solar.log
if k == "current" and t >= t0]
def _err(p, c):
p.ch.error = "12: Socket fault"
EXITS3 = (("Stop", act("auto_toggle", None), {"shadow_mode": "off"}),
("Off", act("car_mode", "off"), {}),
("shadow on", lambda p, c: c.o.__setitem__("shadow_mode", "on"),
{}),
("safety stop", lambda p, c: setattr(c.circ_wd, "tripped", True),
{}),
("charger error", _err, {}),
("unplug", lambda p, c: p.ch.unplug(), {}))
for name, trig, opts3 in EXITS3:
for kind in ("error", "ignore"):
r3 = solar_exit(trig, dur=600, opts=opts3, events={
299: refusing(kind), 305: refusing(None)})
z3 = zlog(r3, 299)
taken = [x for x in z3 if x[1] == 0.0 and x[2]]
check(f"R3/N9 {name}, the first 0 A refused ({kind}): tried again "
f"60 s later and taken once, the charger ends at 0 A ({z3})",
z3 and z3[0][1] == 0.0 and z3[0][0] <= 302 and not z3[0][2]
and len(taken) == 1 and taken[0][0] - z3[0][0] >= 60
and taken[0][0] - z3[0][0] <= 75 and len(z3) <= 3
and not [x for x in z3 if x[1] > 0]
and r3["sim"].setpoint_a == 0.0 and r3["sim"].power_w == 0.0)
n_ref3 = LOG.count("WARNING", "CHARGER_REFUSED")
st3 = {}
def _st3(p, c, t):
if t == 599:
st3["rows"] = [x["id"] for x in c.checks()]
st3["why"] = homeview.car_block(c, None)["why"]
r3g = solar_exit(act("auto_toggle", None), dur=600,
opts={"shadow_mode": "off"},
events={299: refusing("error")}, on_cycle=_st3)
z3g = zlog(r3g, 299)
check(f"R3: a 0 A the charger never takes: 3 tries 60 s apart, then the "
f"gave-up row and one warning, and the card does not say paused "
f"({z3g}, {st3.get('why')!r})",
[x[1] for x in z3g] == [0.0, 0.0, 0.0]
and all(b[0] - a[0] >= 60 for a, b in zip(z3g, z3g[1:]))
and "charger_refused" in st3.get("rows", [])
and LOG.count("WARNING", "CHARGER_REFUSED") - n_ref3 == 1
and "paused" not in st3.get("why", "paused")
and r3g["c"].car_solar.gave_up)
r3o = solar_exit(act("car_mode", "off"), dur=600,
events={299: refusing("error")}, on_cycle=_st3)
check(f"R3: the same after Solar to Off: 3 tries, then the gave-up row "
f"({zlog(r3o, 299)})", [x[1] for x in zlog(r3o, 299)] == [0.0] * 3
and "charger_refused" in st3.get("rows", []))
# The shutdown cancels a start write while it waits for its read-back (lag
# 3 s): the 0 A must still go out (the earlier confirmed 0 A says nothing).
rec3 = {}
def _gate3(p, c):
gate = asyncio.Event()
async def sleep(_s):
gate.clear()
await gate.wait()
async def settle():
gate.set()
for _ in range(5):
await asyncio.sleep(0)
c.charger._sleep = sleep
c.car_settle = settle
def _shut3(p, c, t):
w = [x for x in p.wlog if x[1] == "current" and x[2] > 0]
if w and "t" not in rec3:
rec3["t"] = t
rec3["co"] = shutdown_at(rec3)(p, c)
def _kick3(p, c):
return rec3.pop("co", None)
_s3 = SimCharger(setpoint_a=10)
_s3.lag_s = 3.0
r3s = S.drive(dur=140, sim=_s3, on_cycle=_shut3,
events={t: (_gate3 if t == 50 else _kick3)
for t in range(50, 140)},
**RUN10)
s3s = rec3.get("sets", [])
check(f"R3: shutdown while a start write waits for its read-back: the 0 A "
f"still goes out before the inverters' 0 W ({s3s[:3]}, setpoint at the "
f"end {r3s['sim'].setpoint_a})",
any(x[1] == S.SET and x[2] == 0.0 for x in s3s)
and s3s and s3s[0][1] == S.SET and r3s["sim"].setpoint_a == 0.0)
# Major: one excess, one cut, from a car well above 6 A that is slow to show
# it: a 700 W/s ramp (about 4 s), and also a 3 s read-back lag (about 7 s).
# Batteries at the cut-out, so the cut is at once. Later writes in the period
# are the spare rule (the step also takes the sun), not cuts.
for lag in (0.0, 3.0):
_s3c = SimCharger(setpoint_a=0)
_s3c.ramp_w_s = 700.0
r3c = S.drive(sim=_s3c, house=steps((0, 500.0), (910, 7900.0),
(970, 500.0)),
sun=const(13000.0), first="car", socs=CUTOUT, dur=1000,
opts={"slew_w": 0},
events={900: lambda p, c, lag=lag: setattr(p.ch, "lag_s",
lag)})
x3c = first_cut(r3c, 905)
w3c = [(t, v) for t, v in S.writes(r3c) if 905 <= t < 940]
want3c = (None if x3c is None else
math.floor((16 * 690.0 - x3c["cut"]) / 690.0 + 1e-9))
check(f"R3 cut, car 16 A on 3 phases, ramp 700 W/s, read-back lag "
f"{lag:.0f} s:"
f" one excess ({None if x3c is None else round(x3c['cut'])} W) "
f"takes one cut, to {want3c} A, and no more ({w3c})",
x3c is not None and len(w3c) == 1 and w3c[0][1] == want3c
and want3c >= 11)
print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
print()