diff --git a/goodwe_controller/DECISIONS/EV-54-refused-cut-retry.md b/goodwe_controller/DECISIONS/EV-54-refused-cut-retry.md index 37a9102..4878637 100644 --- a/goodwe_controller/DECISIONS/EV-54-refused-cut-retry.md +++ b/goodwe_controller/DECISIONS/EV-54-refused-cut-retry.md @@ -50,6 +50,13 @@ QC (brief v6); the formal check is reports/EV-54-formal-report.md. (`cut_fails`) is never touched by it. When the cut stops standing in Solar and the value cannot be dropped yet (stuck), that value becomes Solar's own: reason Solar, a fresh `fails` count (QC). +- `fails` counts only refusals of the value now owed (PM, review round 2). + Where a refused cut value stops being owed without a drop (the charger's + return, another value written in its place), `fails` goes to 0 + (`_forget_refused`); `cut_fails` stays. Elsewhere `fails` is already + right: a drop, a taken write or an adopt clear it; a Solar press or a + change into Solar clear it; Off and the quarter roll keep the owed value, + so its count stays (Off's way-out as before). - At a new quarter's wait the cut tick holds the read-back the writer is about to take, not the refused value, so the wait never re-sends it (G1). - No drop over another writer's value (a hold or a difference being watched). diff --git a/goodwe_controller/app/carmode.py b/goodwe_controller/app/carmode.py index d251f17..23bc92a 100644 --- a/goodwe_controller/app/carmode.py +++ b/goodwe_controller/app/carmode.py @@ -912,6 +912,14 @@ class SolarWriter(ManualWriter): change).""" return self.cut_a is not None and float(a) <= self.cut_a + TOL_A + def _forget_refused(self) -> None: + """EV-54 (PM, review r2): a refused cut value is no longer owed and + is not dropped (the charger's return, another value written): its + refusals leave `fails` with it. `cut_fails`, the quarter's cap, stays.""" + if self.refused_cut is not None: + self.refused_cut = None + self.fails = 0 + def drop_ready(self, cur, stuck) -> bool: """EV-54 (drop rule): a cut value the charger did not take, no cut stands any more (lifted, or a new quarter's cut waits), and a known @@ -974,7 +982,7 @@ class SolarWriter(ManualWriter): cut_try = self.sent_cut = self._cut_try(a) if self.refused_cut is not None \ and abs(self.refused_cut - float(a)) > TOL_A: - self.refused_cut = None # EV-54: another value, not that one + self._forget_refused() # EV-54: another value, not that one self.sent_a, self.taken = float(a), False if prev is None or abs(prev - float(a)) > TOL_A: # EV-21 (PM Q1, formal C15): the 2 s grace of a lowering on its @@ -1447,7 +1455,7 @@ class SolarWriter(ManualWriter): if self.fresh_start: self.fresh_start = False self.sent_a, self.taken = None, True # 0 A first (D2) - self.refused_cut = None + self._forget_refused() if self.drop_ready(cur, stuck): # EV-54 (drop rule): the refused cut value is not sent again. self._drop(cur, now) diff --git a/goodwe_controller/test_ev54_drop.py b/goodwe_controller/test_ev54_drop.py index 0cf5c71..888e293 100644 --- a/goodwe_controller/test_ev54_drop.py +++ b/goodwe_controller/test_ev54_drop.py @@ -604,6 +604,95 @@ check(f"T39 (review r1): a new cut value above the refused one, under the " f"read-back, goes out as 'peak cut' ({t39})", t39[0] == [6.0, 7.0] and t39[1] == "peak cut") +# =========================================================================== # +print("\n8. REVIEW ROUND 2: `fails` COUNTS ONLY THE OWED VALUE (T40-T42)") +# =========================================================================== # + + +def away_run(h, s, refuse_end, away=True): + ev = {} + if away: + ev = {1100: lambda p, c: p.ch.go_unavailable(), + 1200: lambda p, c: p.ch.go_unavailable(False)} + return run(house_c((1250, 900.0), h=h), sun_c((1250, 9000.0), s=s), + dur=1800, events=window(ev, 959, refuse_end)) + + +def after_lift(r): + tl = t_lift(r, 1200, 1800) + w = [(t, a, ok) for t, a, ok, _w in writes(r, tl or 1e9, 1800)] + hold = [t for t, _lv, _m in r["w"].lines(HOLD_TEXT)] + gu = [x["t"] for x in rows(r, tl or 1e9, 1800) if x["gave_up"]] + cf = sorted({x["cut_fails"] for x in rows(r, 1081, tl or 1e9)}, key=str) + return tl, w, hold, gu, cf + + +# T40 (PM row a): the charger refuses to 1430: after the return Solar's own +# write gets its own tries; the 2nd, 60 s later, is taken. +for tag, h, s in (("0 A", 3000.0, 0.0), ("6 A", 900.0, 1900.0)): + r = away_run(h, s, 1430) + tl, w, hold, gu, cf = after_lift(r) + pre = [t for t, _a, _ok, _w in writes(r, 1081, tl or 1e9)] + tk = [t for t, _a, ok in w if ok] + check(f"T40 [{tag}] (review r2): away 1100-1200 while capped, refused to " + f"1430: nothing until the lift at {tl} ({pre}); then Solar tries " + f"{w[:3]}: the 1st refused, the 2nd 60 s later, a taken write by " + f"1462 ({tk[:1]}); no gave_up ({gu[:2]}) or hold text ({hold}); " + f"the quarter's cut count unchanged across the return ({cf})", + present(tl) and tl is not None and not pre and len(w) >= 2 + and not w[0][2] and w[1][0] - w[0][0] >= 60 and bool(tk) + and tk[0] <= 1462 and not gu and not hold and cf == [3]) + never54(f"T40 [{tag}]", r) + + +def ok41(res): + tl, w, hold, gu, cf = res + if not (len(w) == 3 and len(hold) == 1 and present(tl) and tl is not None + and bool(gu)): + return False + return (not any(ok for _t, _a, ok in w) and w[0][0] <= tl + 60 + and all(b[0] - a[0] >= 60 for a, b in zip(w, w[1:])) + and abs(hold[0] - w[2][0]) <= 1 and gu[0] >= w[2][0] - 1 + and cf == [3]) + + +# T41 (PM row b): refused to 1600: Solar's own 3 tries 60 s apart, then +# gave_up and the hold text, as in the same run without the away. +for tag, h, s in (("0 A", 3000.0, 0.0), ("6 A", 900.0, 1900.0)): + ra = after_lift(away_run(h, s, 1600, away=True)) + rn = after_lift(away_run(h, s, 1600, away=False)) + check(f"T41 [{tag}] (review r2): refused to 1600: with the away {ra[1]}, " + f"gave_up from {ra[3][:1]}, hold text {ra[2]}; without it {rn[1]}, " + f"gave_up from {rn[3][:1]}, hold text {rn[2]}: 3 tries 60 s apart, " + f"then gave_up, in both", ok41(ra) and ok41(rn)) + + +async def replaced_value(): + """T42 (PM row c): a refused 6 A cut, then the next quarter's 7 A (the + reachable path of T39) replaces it and is refused too: `fails` counts + only the owed 7 A.""" + w = carmode.SolarWriter() + w.engaged, w.sent_a, w.taken, w.last_a = True, 10.0, True, 10.0 + drv, trk = Drv(), Trk() + w.cut_quarter("q1") + w.cut_a, w.cut_on = 6.0, True + await w._put(drv, 6.0, 10.0, 1000.0, trk) + w.cut_quarter("q2") + w.cut_a = 7.0 + await w._put(drv, 7.0, 10.0, 1070.0, trk) + return list(drv.calls), w.fails, w.cut_fails, w.refused_cut + + +try: + t42 = asyncio.run(replaced_value()) +except Exception as e: # noqa: BLE001 + t42 = (["raised " + repr(e)], None, None, None) +check(f"T42 (review r2): 6 A refused, then 7 A written in its place and " + f"refused (calls {t42[0]}): fails {t42[1]} counts only the owed 7 A " + f"(1), the new quarter's cut count {t42[2]} (1), owed {t42[3]}", + t42[0] == [6.0, 7.0] and t42[1] == 1 and t42[2] == 1 + and t42[3] == 7.0) + tb_all = LOG.tracebacks(n_log0) check(f"N13: no traceback in this file's runs ({tb_all[:1]})", not tb_all) if TAKE: