diff --git a/goodwe_controller/DECISIONS/EV-05-solar-mode.md b/goodwe_controller/DECISIONS/EV-05-solar-mode.md index 3a3d9ed..db3f0db 100644 --- a/goodwe_controller/DECISIONS/EV-05-solar-mode.md +++ b/goodwe_controller/DECISIONS/EV-05-solar-mode.md @@ -111,6 +111,22 @@ inputs (`car_sun_inputs`) and runs the writer in the same background task. Manual) or setting Manual's current or phases is not the user taking the charger back, so nothing is written over that writer (N10). +## Round 7 (review of b4a222f, brief v6 Expected 11) + +- **Solar keeps watching for another writer while it is not writing** (Stop, + shadow, a safety stop), so `hold` is true for every reader: the exit 0 A, + the shutdown, the peak alarms and Start afterwards (Solar holds off until + Solar is pressed or the read-back matches). +- **The peak alarms stand while Solar is not writing**: `car_solar_can_cut()` + also needs `car_writing()`. The quarter is banked as the car's. +- **A start or restart in Solar with shadow on writes nothing** (owner + 2026-11-18), even with a car already charging under another writer: N10 + wins over the restart 0 A. The not-writing 0 A is owed only when Solar had + the charger before (`had_control`). +- **Once that exit 0 A is taken, nothing more is written**, shutdown + included. A shutdown while Solar is writing still sends its 0 A before the + inverters (T26). + ## Solar kWh Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first, diff --git a/goodwe_controller/app/carmode.py b/goodwe_controller/app/carmode.py index fdaafa7..bf2e075 100644 --- a/goodwe_controller/app/carmode.py +++ b/goodwe_controller/app/carmode.py @@ -665,6 +665,7 @@ class SolarWriter(ManualWriter): self.engaged = False # Solar has run since it was chosen self.reinit = True # start again from 0 A and the start rule self.out = False # not writing (shadow, Stop, safety stop) + self.had_control = False # Solar wrote since it was chosen/started self.zero_for = None # the way out a 0 A is owed for self.zero_ok = False # ... and the charger has taken it self.inflight = None # a current being written, not yet back @@ -768,7 +769,7 @@ class SolarWriter(ManualWriter): def _leave(self) -> None: self.engaged, self.seq, self.would = False, None, None - self.out = False + self.out = self.had_control = False self._zero_done() self.fault = None self.reinit = True @@ -820,14 +821,21 @@ class SolarWriter(ManualWriter): if not writing: # Shadow, Stop, a safety stop, stopping: 0 A until taken, then # nothing. The plan goes on, so the card says what it would set. + # Round 7 (brief v6, Expected 11): only if Solar had the charger + # before; a start or restart in shadow writes nothing. And Solar + # keeps watching for another writer, so `hold` stays true for + # every reader (the exit, the shutdown, the peak alarms). self.seq = None self.out = True - await self._exit_zero("out", drv, cur, now, tracker) + if self.had_control: + await self._exit_zero("out", drv, cur, now, tracker) + self._watch(cur, now) self._plan_step(sun, now, clamp) self.would = (self.amps_out(clamp), self.n_calc) self.reinit = True return self.out = False + self.had_control = True self.would = None fault = ("error" if (r.error or r.state in ("E", "F")) else "stuck" if tracker is not None and tracker.stuck(now) @@ -938,6 +946,11 @@ class SolarWriter(ManualWriter): cur = self.last_a # the reading predates our own write self._clock = self._clock or (lambda: now) self.inflight = None + # Round 7: not writing (shadow, Stop, a safety stop) and the way-out + # 0 A already taken, or Solar never had the charger: nothing more, + # shutdown included (N10). + if self.out and (self.zero_ok or not self.had_control): + return # One try: the add-on is stopping, bounded by `ctl_car.RELEASE_WAIT_S`. if not self.hold and not (cur is not None and cur <= TOL_A): self.zero_at, self.sent_a = now, 0.0 diff --git a/goodwe_controller/app/ctl_car.py b/goodwe_controller/app/ctl_car.py index 2854cc0..6e4f4fd 100644 --- a/goodwe_controller/app/ctl_car.py +++ b/goodwe_controller/app/ctl_car.py @@ -457,10 +457,12 @@ class CarMixin: """EV-05 round 6: can Solar really cut the car now? Not while another writer holds the charger, a write of ours was refused or given up, a way-out 0 A is not taken, the charger shows a fault, or it cannot be - read. Only then may the car be graded out of the peak alarms.""" + read, and not while Solar is not writing (Stop, shadow, a safety stop: + round 7). Only then may the car be graded out of the peak alarms.""" w = getattr(self, "car_solar", None) r = self.car.reading return bool(w is not None and r is not None and r.available + and self.car_writing() # round 7: Stop, shadow, latch and not w.hold and not w.gave_up and w.fail_at is None and w.fault is None and not w.zero_owed) diff --git a/goodwe_controller/test_ev05.py b/goodwe_controller/test_ev05.py index 9b097c8..11cf0c7 100644 --- a/goodwe_controller/test_ev05.py +++ b/goodwe_controller/test_ev05.py @@ -1967,6 +1967,122 @@ check(f"R6 both batteries switched Off: the guard catches the cloud edge with " f"them (wanted {len(want6o)} s), so no cut and no pause ({w6o})", 0 < len(want6o) < 15 and not first_cut(r6o, 900) and 0.0 not in [v for _t, v in w6o]) +# =========================================================================== # +print("\nROUND 7. NOT WRITING: SOLAR WATCHES, THE ALARMS STAND, NOTHING OVER OTHERS") +# =========================================================================== # +OUT7 = (("Stop (shadow_mode auto)", act("auto_toggle", None), + {"shadow_mode": "auto"}), + ("shadow on", lambda p, c: c.o.__setitem__("shadow_mode", "on"), {}), + ("safety stop", lambda p, c: setattr(c.circ_wd, "tripped", True), {})) +# 1. The review's p_out: Solar wrote its one 0 A at 500 s, another writer +# sets 16 A at 600 s, the house steps at 1000 s. As in Off: the alarm, the +# quarter banked, the car never explained away. +for name, trig, opts7 in OUT7: + o7 = dict({"ev_phases": "3", "slew_w": 0}, **opts7) + ev7 = {500: trig, 600: _other16} + r7 = S.drive(house=steps((0, 500.0), (1000, 3000.0)), sun=const(7000.0), + first="car", socs=CUT10, dur=1810, opts=o7, phases=3, + events=dict(ev7)) + r7o = S.drive(house=steps((0, 500.0), (1000, 3000.0)), sun=const(7000.0), + first="car", socs=CUT10, dur=1810, opts=o7, phases=3, + events=dict(ev7), mode="off", sim=SimCharger(setpoint_a=9)) + a7, a7o = first_alarm(r7, 900), first_alarm(r7o, 900) + ex7 = sum(1 for x in r7["trace"] if 900 <= x["t"] < 1800 and x["explains"]) + q7 = {q: g for q, g, _c in quarters(r7, 3400.0)} + check(f"R7 {name}, then another writer at a peak: the alarm stands as in " + f"Off (+2 s) ({a7} vs {a7o}), the quarter ({round(q7.get(900, -1))} " + f"W) is banked ({len(r7['c'].car_peak_q)}), the car is never " + f"explained away ({ex7} cycles), and Solar writes nothing over the " + f"other writer ({after(r7, 600)})", + a7 is not None and a7o is not None and abs(a7 - a7o) <= 2 + and q7.get(900, 0) > 3400.0 and len(r7["c"].car_peak_q) >= 1 + and ex7 == 0 and after(r7, 600) == []) + + +# 2. Shutdown after the exit 0 A was taken, in shadow or Stop, with another +# writer at 16 A since 400 s: nothing is written (T53 (b), T28, N10). +def shut_rec7(rec): + async def f(p, c): + rec["n0"] = len(p.sets) + await c.shutdown() + rec["sets"] = [x for x in p.sets[rec["n0"]:] if x[1] == S.SET] + rec["sp"] = p.ch.setpoint_a + return f + + +for name, trig, opts7 in ( + ("shadow on", lambda p, c: c.o.__setitem__("shadow_mode", "on"), {}), + ("Stop (shadow_mode auto)", act("auto_toggle", None), + {"shadow_mode": "auto"}), + ("Stop (shadow_mode off)", act("auto_toggle", None), + {"shadow_mode": "off"})): + rec7 = {} + r7s = S.drive(house=const(500.0), sun=const(2900.0), first="car", + socs=FULL, dur=601, opts=opts7, events={ + 300: trig, 400: _other16, 600: shut_rec7(rec7)}) + check(f"R7 {name}, another writer at 16 A, then shutdown: no write at " + f"shutdown ({rec7.get('sets')}), the charger stays at 16 A; the only " + f"0 A was the exit's ({after(r7s, 300)})", + rec7.get("sets") == [] and rec7.get("sp") == 16.0 + and [v for _t, v in after(r7s, 300)] == [0.0]) +# Inside the first 30 s, before the watch can call it another writer, each +# clause decides on its own: the alarm (Solar is not writing) and the +# shutdown (the exit 0 A was taken). +o7s = {"ev_phases": "3", "slew_w": 0, "shadow_mode": "auto"} +ev7s = {500: act("auto_toggle", None), 890: _other16} +r7e = S.drive(house=steps((0, 500.0), (895, 3000.0)), sun=const(7000.0), + first="car", socs=CUT10, dur=1810, opts=o7s, phases=3, + events=dict(ev7s)) +r7eo = S.drive(house=steps((0, 500.0), (895, 3000.0)), sun=const(7000.0), + first="car", socs=CUT10, dur=1810, opts=o7s, phases=3, + events=dict(ev7s), mode="off", sim=SimCharger(setpoint_a=0)) +a7e, a7eo = first_alarm(r7e, 895), first_alarm(r7eo, 895) +check(f"R7 Stop, another writer 10 s before the period (no hold yet): the " + f"alarm stands as in Off (+2 s) ({a7e} vs {a7eo})", + a7e is not None and a7eo is not None and abs(a7e - a7eo) <= 2) +rec7e = {} +r7f = S.drive(house=const(500.0), sun=const(2900.0), first="car", socs=FULL, + dur=601, opts={"shadow_mode": "on"}, + events={300: lambda p, c: c.o.__setitem__("shadow_mode", "on"), + 590: _other16, 600: shut_rec7(rec7e)}) +check(f"R7 shadow on, another writer 10 s before the shutdown (no hold yet): " + f"no write at shutdown ({rec7e.get('sets')}), the charger stays at 16 A", + rec7e.get("sets") == [] and rec7e.get("sp") == 16.0) +# 3. Brief v6, Expected 11: a start in Solar with shadow on writes nothing, +# even with a car already charging under another writer. +for name, opts7, ev7 in (("shadow on", {"shadow_mode": "on"}, {}), + ("shipped auto, control stopped", + {"shadow_mode": "auto"}, + {0: lambda p, c: setattr(c, "auto", False)})): + r7t = S.drive(house=const(500.0), sun=const(2900.0), first="car", + socs=FULL, dur=300, setpoint=16, opts=opts7, events=ev7) + check(f"R7 start in Solar with {name}, the car charging at 16 A set by " + f"another writer: nothing is written ({cur(r7t)}), the charger stays " + f"at 16 A, the card says what it would set " + f"({r7t['c'].car_solar.would})", + cur(r7t) == [] and r7t["sim"].setpoint_a == 16.0 + and r7t["c"].car_solar.would is not None) +# 4. The root: Solar keeps watching while it is not writing. Stop at 300 s +# (its 0 A), another writer sets 16 A at 400 s, Start at 600 s: Solar holds +# off, writes nothing over it, and shows the row. +st7 = {} + + +def _rows7(p, c, t): + if t == 620: + st7["rows"] = [x["id"] for x in c.checks()] + + +r7r = solar_exit(act("auto_toggle", None), dur=800, + opts={"shadow_mode": "off"}, + events={400: _other16, 600: act("auto_toggle", None)}, + on_cycle=_rows7) +check(f"R7 Start after a stop during which another writer took the charger: " + f"Solar holds off (writes after 400 s {after(r7r, 400)}, hold " + f"{r7r['c'].car_solar.hold}, row {'charger_other' in st7.get('rows', [])})", + after(r7r, 400) == [] and r7r["c"].car_solar.hold + and "charger_other" in st7.get("rows", []) + and r7r["sim"].setpoint_a == 16.0) print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)") print()