EV-05 round 8: Off respects the owed-only rule; grade out only a car Solar runs
checks / unit (pull_request) Successful in 26m14s
infra-pin / fresh (pull_request) Successful in 1s

Review of fa11dc3:
- Solar to Off writes no 0 A when Solar never had the charger (shadow or a
  stopped control since the start) or its not-writing 0 A is already taken
  (N10, Expected 11), as the shutdown does since round 7.
- car_solar_can_cut() also needs a car Solar runs: plan.a > 0, its own phase
  change, or its own 0 A inside EV-15's OWN_PAUSE_MAX_S.

Tests: the four p_off shapes (and Manual); p_paused at 1000 s and 890 s and
an own pause older than 85 s, each against an Off twin; the near-end rule
with slow batteries that keep headroom (review p_ne2).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-18 22:17:21 +01:00
co-authored by Claude
parent fa11dc3d85
commit e348a808ff
4 changed files with 121 additions and 8 deletions
@@ -127,6 +127,17 @@ inputs (`car_sun_inputs`) and runs the writer in the same background task.
included. A shutdown while Solar is writing still sends its 0 A before the
inverters (T26).
## Round 8 (review of fa11dc3)
- **Off follows the same owed-only rule as the shutdown**: no 0 A when Solar
never had the charger (shadow or a stopped control since the start), or
when its not-writing 0 A is already taken. Manual writes only as Manual
does (nothing in shadow).
- **Solar grades out only a car it runs**: `car_solar_can_cut()` also needs
`plan.a > 0`, a phase change of its own, or its own 0 A still inside EV-15's
`OWN_PAUSE_MAX_S`. A car another writer starts while Solar waits at 0 A for
sun gets the alarms as in Off.
## Solar kWh
Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first,
+7 -3
View File
@@ -810,9 +810,13 @@ class SolarWriter(ManualWriter):
return
if mode != MANUAL: # Off: 0 A until taken, then nothing
self.seq = None
await self._exit_zero("off", drv, cur, now, tracker)
if self.zero_owed:
return # tried again next cycle (or gave up)
# Round 8: not when Solar never had the charger (shadow or a
# stopped control since the start) or its not-writing 0 A is
# already taken: nothing over another writer (N10).
if not (self.out and (self.zero_ok or not self.had_control)):
await self._exit_zero("off", drv, cur, now, tracker)
if self.zero_owed:
return # tried again next cycle (or gave up)
self._leave() # Manual writes its own current
return
self.engaged = True
+12 -5
View File
@@ -458,13 +458,20 @@ class CarMixin:
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, 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."""
round 7), and not a car Solar is not running (round 8). 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)
if not (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):
return False
# Round 8: Solar cuts only a car it runs (`plan.a > 0`). While paused
# at 0 A a car that draws is someone else's, unless it is Solar's own
# 0 A or phase change still inside EV-15's bound.
return bool(w.plan.a > 0.0 or w.seq is not None
or self._car_solar_pause(self.car_now()))
def _car_giving(self) -> list:
"""EV-05: the batteries the peak guard can draw on now: above their
+91
View File
@@ -2083,6 +2083,97 @@ check(f"R7 Start after a stop during which another writer took the charger: "
after(r7r, 400) == [] and r7r["c"].car_solar.hold
and "charger_other" in st7.get("rows", [])
and r7r["sim"].setpoint_a == 16.0)
# =========================================================================== #
print("\nROUND 8. EVERY MODE CHANGE RESPECTS N10; ONLY A CAR SOLAR RUNS IS GRADED")
# =========================================================================== #
# 1. The review's p_off shapes: Solar never had the charger (shadow on, or
# control stopped, since the start) while another writer has the car at 16 A,
# then Off or Manual; and Solar had it, shadow on (its 0 A taken), another
# writer at 16 A, then Off with and without the hold.
for name, opts8, ev8 in (
("shadow on since the start, then Off", {"shadow_mode": "on"},
{200: act("car_mode", "off")}),
("control stopped since the start, then Off", {"shadow_mode": "auto"},
{0: lambda p, c: setattr(c, "auto", False),
200: act("car_mode", "off")}),
("shadow on since the start, then Manual", {"shadow_mode": "on"},
{200: act("car_mode", "manual")})):
r8 = S.drive(house=const(500.0), sun=const(2900.0), first="car",
socs=FULL, dur=400, setpoint=16, opts=opts8, events=ev8)
check(f"R8 {name}, another writer's car at 16 A: nothing is written "
f"({cur(r8)}), the charger stays at 16 A",
cur(r8) == [] and r8["sim"].setpoint_a == 16.0)
for name, at8 in (("Off 200 s later (the hold is set)", 600),
("Off 10 s later (no hold yet)", 410)):
r8h = S.drive(house=const(500.0), sun=const(2900.0), first="car",
socs=FULL, dur=800, events={
300: lambda p, c: c.o.__setitem__("shadow_mode", "on"),
400: _other16, at8: act("car_mode", "off")})
check(f"R8 Solar had the charger, shadow on (its 0 A taken), another "
f"writer at 16 A, {name}: no second 0 A ({after(r8h, 300)}), the "
f"charger stays at 16 A",
[v for _t, v in after(r8h, 300)] == [0.0]
and r8h["sim"].setpoint_a == 16.0)
# 2. The review's p_paused: Solar writing but paused at 0 A (no sun), another
# writer starts the car at T, the house steps at T+5: alarms as in Off (+2 s).
def paused_vs_off(T, label, extra=None, sun=const(0.0)):
ev = {T: _other16}
ev.update(extra or {})
hp = lambda t, T=T: 3000.0 if t >= T + 5 else 500.0
kw = dict(first="car", socs=CUT10, dur=T + 300,
opts={"ev_phases": "3", "slew_w": 0}, phases=3)
rs = S.drive(house=hp, sun=sun, events=dict(ev),
sim=SimCharger(setpoint_a=0), **kw)
ro = S.drive(house=hp, sun=sun, events=dict(ev), mode="off",
sim=SimCharger(setpoint_a=0), **kw)
a_s, a_o = first_alarm(rs, T), first_alarm(ro, T)
ex = sum(1 for x in rs["trace"] if x["t"] >= T and x["explains"])
check(f"R8 {label}: the alarm as in Off (+2 s) ({a_s} vs {a_o}), the car "
f"never explained away ({ex} cycles)",
a_s is not None and a_o is not None and abs(a_s - a_o) <= 2
and ex == 0)
return rs
paused_vs_off(1000, "Solar paused at 0 A (no sun), another writer starts the "
"car at 1000 s")
paused_vs_off(890, "the same at 890 s (the alarm at the period's start)")
# 3. Solar's own pause, older than OWN_PAUSE_MAX_S: the car ran on sun, the
# sun went at 300 s, hold, then Solar's own 0 A at about 600 s; another writer
# starts the car at 1000 s. The own-pause grace has ended, so the alarm
# stands as in Off.
r8g = paused_vs_off(1000, "Solar's own 0 A pause 400 s old, then another "
"writer starts the car", sun=steps((0, 7000.0),
(300, 0.0)))
_own8 = [t for t, v in cur(r8g) if v == 0.0 and t < 1000]
check(f"R8 (precondition) Solar's own 0 A came well before, more than "
f"{ctl_car.OWN_PAUSE_MAX_S:.0f} s ({_own8})",
_own8 and 1000 - _own8[-1] > ctl_car.OWN_PAUSE_MAX_S)
# 4. The near-end rule: batteries with headroom that answer slowly (20 s, as
# R5b), the house step 100 s before the period's end (review p_ne2): inside
# CUT_NEAR_END_S the cut comes at once, not after the 15 s wait.
def _slow8(p, c):
p.response_s = 20.0
for H8 in (40000.0, 42000.0):
hh8 = lambda t, H8=H8: H8 if t >= 1700 else 500.0
r8n = S.drive(hh8, const(13000.0), first="car", socs=ABLE, dur=1802,
opts={"slew_w": 0}, events={1600: _slow8},
on_cycle=headroom_at(hr8 := {}))
want8 = next((x["t"] for x in r8n["trace"] if x["t"] >= 1700
and (x["want"] or 0) > 0), None)
cut8 = first_cut(r8n, 1700)
head8 = hr8.get(want8, (None,))[0] if want8 is not None else None
check(f"R8 near the period's end ({H8:.0f} W at 1700 s, headroom "
f"{head8}): the cut comes at once (want {want8}, cut "
f"{None if cut8 is None else cut8['t']})",
want8 is not None and cut8 is not None and head8 is True
and cut8["t"] - want8 <= 1)
print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
print()