diff --git a/goodwe_controller/app/carmode.py b/goodwe_controller/app/carmode.py index 2fafabc..653cc5c 100644 --- a/goodwe_controller/app/carmode.py +++ b/goodwe_controller/app/carmode.py @@ -220,6 +220,10 @@ class ManualWriter: self.fails, self.blocked = 0, False if cur is not None: self.last_a = cur # adopt what is already set + # 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: + self._log_set(*late) return if not (need_user or self.reapply): return # a difference nobody asked for: `_watch()` judges diff --git a/goodwe_controller/test_ev52.py b/goodwe_controller/test_ev52.py index 94e35aa..f89b438 100644 --- a/goodwe_controller/test_ev52.py +++ b/goodwe_controller/test_ev52.py @@ -575,6 +575,44 @@ async def t23c(): check("T23/M4: a read-back that shows another value is not an accept: 0 lines", go(t23c()) == []) +# Q2 for Manual: a write taken late logs its line once, at the accept. +r23m = manual(200, events={10: slow}) +w23m = [(round(t), v) for t, v in S.writes(r23m)] +check(f"T23 Manual (Q2): a late read-back (12 s): no line at the write, " + f"exactly 1 line at the accept, a few seconds later ({sets(r23m)}, " + f"write {w23m})", + texts(r23m) == ["Car: set from 10 A to 6 A on 1 phase (Manual)."] + and sets(r23m)[0][0] >= 20 + 10 and len(taken(r23m)) == 0) + + +async def t23m(): + """Three tries not taken: the existing CHARGER_REFUSED warning, no line; + the charger then shows the value: exactly one line, once.""" + w = carmode.ManualWriter() + w.boot = False + drv, tr = Drv(ok=False), tracker() + + async def step(a, now): + await w.step(drv, reading(state="C", allowed_a=a, setpoint_a=a, + phases_allowed=1), mode=carmode.MANUAL, + want_a=6.0, want_phases=1, rev=1, clamp=16.0, now=now, + tracker=tr, writing=True, status="charging") + n0 = LOG.mark() + for k in range(3): + await step(10.0, 100.0 + 70 * k) + mid = [m for lv, m, _x in LOG.rec[n0:] if lv != "DEBUG"] + await step(6.0, 300.0) + await step(6.0, 310.0) # the next read-back: nothing again + return mid, [m for lv, m, _x in LOG.rec[n0:] if lv != "DEBUG"] + + +mid, end = go(t23m()) +check(f"T23 Manual (Q2): three tries not taken give the existing Manual " + f"CHARGER_REFUSED warning and no line; the accept then gives exactly " + f"one line ({mid} -> {end})", + len(mid) == 1 and mid[0].endswith("CHARGER_REFUSED.") + and end[1:] == ["Car: set from 10 A to 6 A on 1 phase (Manual)."]) + # T33: shutdown, the charger refuses all 3 release tries. @@ -720,6 +758,51 @@ check(f"T40: the read-back shows 6 A but the car draws 8 A (1840 W): the line " # =========================================================================== # print("\n8. NOTHING ELSE MOVES (T43-T45, N1, N2, N7, N8, N10, N11)") # =========================================================================== # +# N5: a mode line only for a mode change (and the one at start-up). +chg4 = 1 + 1 # r4: the start, then Off -> Manual +check(f"N5: no mode line without a change: {len(modes(r4))} in r4 (start + " + f"the one change, six more same-mode or refused actions), " + f"{len(modes(r7))} in a 700 s Solar run with no action, " + f"{len(modes(r1))} in r1 (start + Manual, two same-value actions)", + len(modes(r4)) == chg4 and len(modes(r7)) == 1 and len(modes(r1)) == 2 + and len(modes(r30)) == 2) + +# N8: the existing warning and info texts are the base's, word for word. +EXACT = { + "The charger did not take the current, so the add-on stops asking until " + "you change it: CHARGER_REFUSED.", + "The charger did not take the current, so the add-on stops asking until " + "you press Solar: CHARGER_REFUSED.", + "The charger did not take the current, so the add-on tries again in 15 " + "min, then every 30 min: CHARGER_REFUSED.", + "The charger did not take 0 A before the add-on stopped, so the car may " + "still be charging: CHARGER_RELEASE.", + "Software fault: the add-on was about to ask the charger for more than " + "its limit, so nothing was sent: CHARGER_CLAMP.", + "Solar lowered the car for the peak: CAR_CUT.", + "The car kept drawing, so the phases were not changed."} +seen8 = {m for r in ALL for _t, lv, m in r["lines"] if lv != "DEBUG" + and ("CHARGER_" in m or "CAR_CUT" in m or "kept drawing" in m)} +check(f"N8: every CHARGER_* / CAR_CUT / kept-drawing line seen in any run is " + f"one of base's texts, and each of the seven was seen " + f"({sorted(seen8 - EXACT)[:2]}, missing {sorted(EXACT - seen8)[:2]})", + seen8 == EXACT) + +# T44: the existing suites run unedited in CI (checks / unit) and were run +# here (the report lists them). What a unit row can pin: the two existing +# files this ticket had to touch still hold their own assertions and set +# aside ONLY the two new prefixes. +_here = os.path.dirname(os.path.abspath(__file__)) +_t28 = open(os.path.join(_here, "test_ev28.py")).read() +_t51 = open(os.path.join(_here, "test_ev51.py")).read() +check("T44: test_ev28 and test_ev51 keep their pinned rows and filter only " + "'Car: set' and 'Car mode is now'", + 'check(f"T13: a clean change logs nothing at INFO or above' in _t28 + and "CAP.loud(MARK[0]) == []" in _t28 + and "info == BASE_INFO" in _t51 + and _t28.count('("Car: set", "Car mode is now")') == 1 + and _t51.count('("Car: set", "Car mode is now")') == 1) + # Taken on the base build 02166e2 with EV52_GOLDEN=1 (the same scenarios). _CAR1 = ["car current set to 8 by operator", "car current set to 8 by operator", "car mode set to manual by operator", "car current set to 6 by operator",