From 1c7761d2c262f461bea34dd6e7e5c8a886645fb9 Mon Sep 17 00:00:00 2001 From: ems-agent Date: Sun, 29 Nov 2026 02:29:25 +0100 Subject: [PATCH] EV-21 fix round 3 (re-review, tests only): refused-close retry under a cut under 6 A; R1 standing cut test_ev21_fix2.py: N6/P27 (a) writer-level cuts of 3 A and 0 A, no write after the cut and the charger at 0 A; N6/P27 (b) controller level (close refused at 313, house 18 kW at 315: cut 0 A at once, no retry); R1 standing cut unit row on _car_cut_tick. Red with seq_nopause_retry and r1_nostand. No app/ change. Co-Authored-By: Claude --- goodwe_controller/test_ev21_fix2.py | 91 +++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/goodwe_controller/test_ev21_fix2.py b/goodwe_controller/test_ev21_fix2.py index 0b3203e..9481b97 100644 --- a/goodwe_controller/test_ev21_fix2.py +++ b/goodwe_controller/test_ev21_fix2.py @@ -8,8 +8,12 @@ current, the car never draws more than before the cut. - T34 (v), R1: the same for a change from 3 phases to 1. - N6 / P27, R2: a refused closing write retried under a cut that came in - between is never above the cut's cap (the `_seq_want` cap). + between is never above the cut's cap (the `_seq_want` cap); under 6 A + (3 A, 0 A) nothing is written after the cut (fix round 3, row (a)), also + at controller level with the house heading over before the retry (b). - N9: a standing cap survives a cycle with a blind guard or a stale meter. +- R1 standing cut (fix round 3): a standing partial cut goes to 0 A when a + cut is due during Solar's own change. The real Controller on `tools/ev20_sun.py` through `tools/ev21_kit.py`, and for the N6/P27 row the real `SolarWriter` on a stub charger. @@ -26,7 +30,7 @@ HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "tools")) from app import carmode, chargers as CH # noqa: E402 -from ev20_kit import LOG, check, fails, const, step_fn # noqa: E402 +from ev20_kit import LOG, check, fails, const, step_fn, TSim # noqa: E402 from ev21_kit import AIM, after, drive, both, _mode, shape, never # noqa: E402 n_log0 = LOG.mark() @@ -172,14 +176,64 @@ async def refused_close(cap): for _ in range(12): await step(t, cut=cap) t += 1.0 - return refused, [(x[2], x[1]) for x in w.log[n1:] if x[0] == "current"] + return refused, [(x[2], x[1]) for x in w.log[n1:] + if x[0] == "current"], drv.a -refused, later = asyncio.run(refused_close(6.0)) +refused, later, _end = asyncio.run(refused_close(6.0)) check(f"N6/P27: Solar's closing write {refused} is refused; a cut to 6 A " f"comes before its retry: the retry is never above 6 A ({later})", refused is not None and refused[1] > 6.0 and bool(later) and all(a <= 6.0 for _t, a in later)) +# Fix round 3 (re-review Major 1): a cut under 6 A before the retry ends the +# change in the writer (carmode.py, `plan.a < MIN_A` in the change): no +# write after the cut at all, and the charger stays at 0 A. +for cap in (3.0, 0.0): + refused, later, end = asyncio.run(refused_close(cap)) + check(f"N6/P27 (a) [cut {cap:.0f} A]: Solar's closing write {refused} is " + f"refused; the cut comes before its retry: no write after it " + f"({later}), the charger ends at {end} A", + refused is not None and refused[1] > 6.0 and not later + and end == 0.0) + +# (b) The same at controller level (the re-reviewer's row B): Solar 16 A on +# 1 phase, auto, sun 9280 W, both batteries switched off in battery modes. +# Solar's own 1 -> 3 change; its close is refused (a 2 s "error" window); +# the house steps to 18 kW one second after the window, before the retry +# (5 s after the close). Expected: a 0 A cut at once, no retry, no car power +# under the cut. +kw = dict(dur=700, first="car", phases=1, socs={"a": 10.0, "b": 10.0}, + opts={"ev_phases": "auto"}, beside=True) +ev = {0: both(lag(0.0), _mode("ab", False))} +r0 = drive(const(900.0), const(9280.0), **dict(kw, events=ev)) +log0 = r0["c"].car_solar.log +sel = [t for k, a, t, ok in log0 if k == "phases" and a == 3] +close = [(t, a) for k, a, t, ok in log0 if k == "current" and a > 0.0 + and sel and t > sel[0]] +tc = close[0][0] if close else None +if tc is not None: + sim = TSim(setpoint_a=0, windows=[(tc - 1.0, tc + 1.0, "error")]) + r = drive(step_fn((tc + 2, 18000.0), base=900.0), const(9280.0), + **dict(kw, events=ev, sim=sim, dur=tc + 200)) + log = r["c"].car_solar.log + tried = [(t, a, ok) for k, a, t, ok in log if k == "current" + and t >= tc - 1] + retry = [(t, a) for t, a, ok in tried if a > 0.0 and t >= tc + 2] + rows = r["rec"].rows + caps = [(x["t"], x["cap"]) for x in rows if x["t"] >= tc + 2 + and x["cap"] is not None] + car_hi = [(x["t"], x["car"]) for x in rows if x["t"] > tc + 2 + and x["cap"] is not None and (x["car"] or 0) > 50.0] + ok_b = (bool(caps) and caps[0] == (tc + 2, 0.0) and not retry + and not car_hi) +else: + tried, retry, caps, car_hi, ok_b, r = [], [], [], [], False, None +check(f"N6/P27 (b): Solar's change selects at {sel[:1]}, its close at {tc} " + f"is refused, the house is at 18 kW from {tc and tc + 2}: the cut " + f"{caps[:1]} (0 A at once), no non-zero retry after it ({retry[:2]}), " + f"no car power under it ({car_hi[:2]}); writes {tried[:5]}", ok_b) +if r is not None: + never("N6/P27 (b)", r) # =========================================================================== # print("\n3. N9: A STANDING CUT SURVIVES A STALE CYCLE") @@ -201,6 +255,35 @@ check(f"N9: a cut of {cap0} A stands; a cycle with a blind guard gives the " f"writer {a_blind} A, one with a stale meter {a_stale} A: the cap " f"stays", cap0 is not None and a_blind == cap0 and a_stale == cap0) +# =========================================================================== # +print("\n4. PM R1: A STANDING PARTIAL CUT GOES TO 0 A IF A CHANGE IS UNDER WAY") +# =========================================================================== # +# Fix round 3 (re-review Minor): `_car_cut_tick` itself. A partial cut of +# 8 A stands, Solar's plan has decided a phase change (`plan.switch`) and a +# cut is due again (the car draws, the projection is over the aim): the +# standing cap goes to 0 A, which ends the change at its 0 A (R1). +r = shape("C", dur=950) +c = r["c"] +w = c.car_solar +t = c.car_now() +c._car_cut_meter_fresh = lambda: True +left = 900.0 - 300.0 +proj = dataclasses.replace(c._peak_proj_real, elapsed_s=300.0, + projected_w=AIM + 1000.0 * left / 900.0) +st = c._cut = c._cut_fresh(proj.block_start) +st.update(cap=8.0, ex=1e9, car0=6900.0, base=10.0, cuts=1, at=t, since=t) +w.plan.switch = True +c._car_cut_tick(proj, c.peak_guard, AIM, t) +cap_switch = c._cut["cap"] +w.plan.switch = False +st = c._cut = c._cut_fresh(proj.block_start) +st.update(cap=8.0, ex=1e9, car0=6900.0, base=10.0, cuts=1, at=t, since=t) +c._car_cut_tick(proj, c.peak_guard, AIM, t) +cap_plain = c._cut["cap"] +check(f"R1 standing cut: a cut of 8 A stands and a cut is due again; with " + f"Solar's own change decided it becomes {cap_switch} A, without one " + f"it stays {cap_plain} A", cap_switch == 0.0 and cap_plain == 8.0) + tb_ = LOG.tracebacks(n_log0) check(f"N11: no traceback in this file's runs ({tb_[:1]})", not tb_) print(f"\n{'FAILED: ' + str(len(fails)) if fails else 'ALL PASSED'}")