EV-05 round 6: grade the car out only while Solar can cut it
Review of 69f5818:
- Solar grades the car out of the peak alarms only while it can really cut
it (not under another writer's hold, a refused or given-up write, an
untaken way-out 0 A, a charger fault, an unreadable charger). Otherwise
the alarms stand as in Off and the quarter is banked as the car's.
- A battery refusing to give counts for nothing at every N (N=1:
Controller.batt_refused); the site safety stops leave none able; a
battery switched Off still counts (the guard draws on it).
- Only pressing Solar lifts Solar's other-writer hold: leaving Solar, or
setting Manual's values, no longer writes over another writer (N10).
Tests: Solar vs Off twins for another writer, a refused cut write and a
refused fault 0 A; N=1 refusing battery against a car-Off twin; N10 on every
exit and on Manual value changes; the able_w cap; batteries switched Off.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,22 @@ inputs (`car_sun_inputs`) and runs the writer in the same background task.
|
||||
it had headroom and the cut waited (review repro: battery A refuses, house to
|
||||
20 950 W, period 3436 W against the twin's 3363 W).
|
||||
|
||||
## Round 6 (review of 69f5818)
|
||||
|
||||
- **Solar grades the car out of the peak alarms only while it can cut it**
|
||||
(`ctl_car.car_solar_can_cut`): 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 cannot be read. Otherwise the normal alarms stand
|
||||
as in Off, and the quarter is banked as the car's (it can set the peak).
|
||||
- **A refusing battery counts for nothing at every N**: at N=1 the refusal is
|
||||
`Controller.batt_refused` (SAFETY-52). The site's own safety stops (circulation,
|
||||
site sign) leave no battery able to give.
|
||||
- **A battery switched Off still counts for the headroom**: the peak guard's
|
||||
floor draws on it, so it can catch a cloud edge.
|
||||
- **Only pressing Solar lifts Solar's other-writer hold.** Leaving Solar (Off,
|
||||
Manual) or setting Manual's current or phases is not the user taking the
|
||||
charger back, so nothing is written over that writer (N10).
|
||||
|
||||
## Solar kWh
|
||||
|
||||
Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first,
|
||||
|
||||
@@ -185,7 +185,12 @@ class CarMixin:
|
||||
self.store.set(carmode.KEY_PHASES, value)
|
||||
self.car_rev += 1
|
||||
self.car_writer.user_changed()
|
||||
self.car_solar.user_changed()
|
||||
if what == "car_mode" and value == carmode.SOLAR:
|
||||
# EV-05 round 6: only pressing Solar lifts Solar's other-writer
|
||||
# hold. Leaving Solar, or setting Manual's current or phases, is
|
||||
# not the user taking the charger back, so nothing is written over
|
||||
# that writer (N10).
|
||||
self.car_solar.user_changed()
|
||||
self.log_event(f"car {what[4:]} set to {value} by operator",
|
||||
hint=messages.hint(what))
|
||||
return {"mode": self.car_mode, "current": self.car_a,
|
||||
@@ -448,17 +453,32 @@ class CarMixin:
|
||||
<= OWN_PAUSE_MAX_S
|
||||
return 0.0 <= mono - wr.phase_done_at <= OWN_PAUSE_TAIL_S
|
||||
|
||||
def car_solar_can_cut(self) -> bool:
|
||||
"""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."""
|
||||
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 not w.hold and not w.gave_up and w.fail_at is None
|
||||
and w.fault is None and not w.zero_owed)
|
||||
|
||||
def _car_giving(self) -> list:
|
||||
"""EV-05: the batteries that can give power now: above their own
|
||||
cut-out level, not refusing to give (SAFETY-73), not under a safety
|
||||
stop, and switched on (battery modes)."""
|
||||
"""EV-05: the batteries the peak guard can draw on now: above their
|
||||
own cut-out level, not refusing to give (SAFETY-73: `inv.refused` at
|
||||
N>=2, `Controller.batt_refused` at N=1), not under a safety stop (the
|
||||
unit's own, the site's, the circulation stop). A battery switched Off
|
||||
in battery modes still counts: the guard's floor uses it (round 6)."""
|
||||
n = len(self.inverters)
|
||||
if self.circ_wd.tripped or (n > 1 and self.site_sign_wd.tripped):
|
||||
return []
|
||||
out = []
|
||||
for inv in self.inverters:
|
||||
soc, floor = inv.soc, inv.bms_soc_floor
|
||||
refused = inv.refused if n > 1 else self.batt_refused
|
||||
if soc is None or floor is None or inv.sign_wd.tripped \
|
||||
or (inv.refused or 0) > 0:
|
||||
continue
|
||||
if self.modes_on and not self.pack_mode(inv).use:
|
||||
or (refused or 0) > 0:
|
||||
continue
|
||||
if float(soc) > float(floor):
|
||||
out.append(inv)
|
||||
@@ -524,9 +544,10 @@ class CarMixin:
|
||||
dt = min(max(mono - last, 0.0), 5.0)
|
||||
if w is not None:
|
||||
q["ws"] += float(w) * dt
|
||||
if not self.car_solar_mode():
|
||||
# EV-05: only a charge you set can be "set by the car";
|
||||
# a Solar charge runs on spare sun and is cut first.
|
||||
if not self.car_solar_mode() or not self.car_solar_can_cut():
|
||||
# EV-05: a Solar charge runs on spare sun and is cut first,
|
||||
# so it is not "set by the car"; one the add-on cannot cut
|
||||
# (round 6: another writer, a refused write, a fault) is.
|
||||
q["ws_b"] = q.get("ws_b", 0.0) + float(w) * dt
|
||||
elif wg is not None:
|
||||
q["ws_p"] = q.get("ws_p", 0.0) + float(wg) * dt
|
||||
@@ -638,7 +659,9 @@ class CarMixin:
|
||||
if self.car_solar_mode():
|
||||
# EV-05: Solar is cut first, so it is never "over"; its own
|
||||
# 0 A must not leave the house's alarm graded with the car.
|
||||
explains = graded
|
||||
# Round 6: only while it really can cut the car. Otherwise
|
||||
# the normal alarms stand, as in Off.
|
||||
explains = graded and self.car_solar_can_cut()
|
||||
elif self.car_cover:
|
||||
explains = over = graded
|
||||
elif w is not None:
|
||||
|
||||
@@ -1808,6 +1808,165 @@ check(f"R5c: floor-limited alone decides (guard (saturated, floor-limited) "
|
||||
s5c is not None and c5c is not None and c5c - s5c <= 1
|
||||
and st5c is not None and st5c[2] == (False, True)
|
||||
and st5c[1] is not None and st5c[1] < 9600.0 - 100.0)
|
||||
# =========================================================================== #
|
||||
print("\nROUND 6. ONLY A CAR SOLAR CAN CUT IS GRADED OUT; REFUSALS AT EVERY N")
|
||||
# =========================================================================== #
|
||||
from app import peakguard as _pg # noqa: E402
|
||||
from app import packmode as _pm # noqa: E402
|
||||
from app.store import unit_key as _uk # noqa: E402
|
||||
|
||||
CUT10 = {"a": 10.0, "b": 10.0}
|
||||
ALARMS6 = ("goodwe_peak_soc_floor", "goodwe_peak_saturated")
|
||||
|
||||
|
||||
def first_alarm(r, t0):
|
||||
return next((t for t, n in r["raised"] if n in ALARMS6 and t >= t0), None)
|
||||
|
||||
|
||||
def solar_vs_off(events, house, label):
|
||||
"""The review's p_silent shape: N=2 at their cut-out, ev_phases 3, sun
|
||||
7 kW. Solar runs at 9 A on 3 phases; the twin is Off with the car at the
|
||||
same 9 A (another writer's setting), so the load is the same."""
|
||||
rs = S.drive(house=house, sun=const(7000.0), first="car", socs=CUT10,
|
||||
dur=1810, opts={"ev_phases": "3", "slew_w": 0}, phases=3,
|
||||
events=dict(events))
|
||||
ro = S.drive(house=house, sun=const(7000.0), first="car", socs=CUT10,
|
||||
dur=1810, opts={"ev_phases": "3", "slew_w": 0}, phases=3,
|
||||
events=dict(events), mode="off", sim=SimCharger(setpoint_a=9))
|
||||
a_s, a_o = first_alarm(rs, 900), first_alarm(ro, 900)
|
||||
qs = {q: g for q, g, _c in quarters(rs, 3400.0)}
|
||||
check(f"R6 {label}: Solar cannot cut the car, so the peak alarm stands as "
|
||||
f"in Off (+2 s) ({a_s} vs {a_o}), the quarter over the aim "
|
||||
f"({round(qs.get(900, -1))} W) is banked as the car's "
|
||||
f"({sorted(rs['c'].car_peak_q)[:2]}), and no explaining "
|
||||
f"({rs['c'].car_explains})",
|
||||
a_o is not None and a_s is not None and abs(a_s - a_o) <= 2
|
||||
and qs.get(900, 0) > 3400.0 and len(rs["c"].car_peak_q) >= 1
|
||||
and not rs["c"].car_explains)
|
||||
return rs, ro
|
||||
|
||||
|
||||
def _other16(p, c):
|
||||
p.ch.set_current(16)
|
||||
|
||||
|
||||
def _refuse_err(p, c):
|
||||
p.ch.refuse = "error"
|
||||
|
||||
|
||||
def _fault_refused(p, c):
|
||||
p.ch.error = "12: Socket fault"
|
||||
p.ch.refuse = "error"
|
||||
|
||||
|
||||
# 1. another writer holds the charger (review repro p_silent "other")
|
||||
solar_vs_off({600: _other16}, steps((0, 500.0), (1000, 3000.0)),
|
||||
"another writer sets 16 A")
|
||||
# 2. a cut write the charger refuses, and 3. a charger fault whose 0 A is
|
||||
# refused: the house goes to 6 kW, so the car must be cut and cannot be
|
||||
solar_vs_off({990: _refuse_err}, steps((0, 500.0), (1000, 6000.0)),
|
||||
"the cut write is refused")
|
||||
solar_vs_off({990: _fault_refused}, steps((0, 500.0), (1000, 6000.0)),
|
||||
"a charger fault whose 0 A is refused")
|
||||
|
||||
|
||||
# N=1: the only battery refuses to give (SAFETY-52 keeps it in
|
||||
# Controller.batt_refused), car 16 A on 1 phase; review repro p_n1, H 16380 W.
|
||||
def _refuse_n1(p, c):
|
||||
if not getattr(p, "_a_held", False):
|
||||
p._a_held = True
|
||||
orig = p.batt_of
|
||||
p.batt_of = lambda u, at, _o=orig: min(_o(u, at), 0.0)
|
||||
c.batt_refused = 1
|
||||
if c.batt_refused_at is None:
|
||||
c.batt_refused_at = p.t
|
||||
|
||||
|
||||
hn1 = steps((0, 500.0), (905, 16380.0))
|
||||
KW1 = dict(first="car", ratings={"a": 5000.0}, socs={"a": 60.0}, dur=1810,
|
||||
opts={"slew_w": 0, "ev_phases": "1"},
|
||||
events={t: _refuse_n1 for t in range(850, 1810)})
|
||||
r6n = S.drive(hn1, const(13000.0), **KW1)
|
||||
r6no = S.drive(hn1, const(13000.0), mode="off", **KW1)
|
||||
q6n = {q: g for q, g, _c in quarters(r6n, 3400.0)}
|
||||
q6no = {q: g for q, g, _c in quarters(r6no, 3400.0)}
|
||||
s6n, c6n = since_cut(r6n, 905)
|
||||
check(f"R6/N4 N=1, the only battery refuses to give: no headroom, the cut "
|
||||
f"comes at once (wants from {s6n}, cut at {c6n}) and the period lands "
|
||||
f"under the aim like the car-Off twin ({round(q6n.get(900, -1))} W vs "
|
||||
f"{round(q6no.get(900, -1))} W)",
|
||||
s6n is not None and c6n is not None and c6n - s6n <= 1
|
||||
and q6n.get(900, 1e9) <= 3400.0 and q6no.get(900, 1e9) <= 3400.0)
|
||||
|
||||
|
||||
# N10 on the way out: another writer holds the charger, then each exit.
|
||||
def _err12(p, c):
|
||||
p.ch.error = "12: Socket fault"
|
||||
|
||||
|
||||
for name, trig, opts6 in (
|
||||
("Stop", act("auto_toggle", None), {"shadow_mode": "off"}),
|
||||
("shadow on", lambda p, c: c.o.__setitem__("shadow_mode", "on"), {}),
|
||||
("safety stop", lambda p, c: setattr(c.circ_wd, "tripped", True), {}),
|
||||
("Off", act("car_mode", "off"), {}),
|
||||
("charger error", _err12, {})):
|
||||
r6h = solar_exit(trig, at=700, dur=900, opts=opts6,
|
||||
events={600: _other16})
|
||||
held = r6h["c"].car_solar.hold
|
||||
check(f"R6/N10 {name} while another writer holds the charger: nothing is "
|
||||
f"written over it ({after(r6h, 600)}, hold {held}, setpoint "
|
||||
f"{r6h['sim'].setpoint_a})",
|
||||
after(r6h, 600) == [] and r6h["sim"].setpoint_a == 16.0)
|
||||
|
||||
|
||||
for name, trig in (("Manual's current set", act("car_current", 12)),
|
||||
("Manual's phases set", act("car_phases", 3))):
|
||||
r6v = solar_exit(trig, at=700, dur=900, events={600: _other16})
|
||||
check(f"R6/N10 {name} while Solar is held by another writer: Solar still "
|
||||
f"writes nothing over it ({after(r6v, 600)}, hold "
|
||||
f"{r6v['c'].car_solar.hold})",
|
||||
after(r6v, 600) == [] and r6v["c"].car_solar.hold
|
||||
and r6v["sim"].setpoint_a == 16.0)
|
||||
|
||||
|
||||
# The guard's `able_w` caps the headroom: a real Controller after a run, two
|
||||
# batteries above their cut-out giving 2500 W each (5000 W of 9600 W), and a
|
||||
# guard that names able_w 4600 W (one battery held at the peak reserve, the
|
||||
# guard not yet floor-limited). In a whole run the guard is floor-limited in
|
||||
# that first cycle, so this clause is pinned on the method itself.
|
||||
c6h = S.drive(house=const(500.0), sun=const(2900.0),
|
||||
first="car", socs=ABLE, dur=5)["c"]
|
||||
for _i in c6h.inverters:
|
||||
_i.batt, _i.refused = 2500.0, 0
|
||||
c6h.batt_refused = 0
|
||||
g6 = _pg.PeakDecision(engaged=True, floor_w=3000.0, ceiling_w=3500.0,
|
||||
ceiling_from="peak_cap_w", able_w=4600.0)
|
||||
g6n = _pg.PeakDecision(engaged=True, floor_w=3000.0, ceiling_w=3500.0,
|
||||
ceiling_from="peak_cap_w", able_w=None)
|
||||
check(f"R6 able_w: 5000 W given of 9600 W is headroom "
|
||||
f"({c6h._car_batt_headroom(g6n)}), but not when the guard can draw on "
|
||||
f"4600 W only ({c6h._car_batt_headroom(g6)})",
|
||||
c6h._car_batt_headroom(g6n) is True and c6h._car_batt_headroom(g6) is False)
|
||||
|
||||
|
||||
# Batteries switched Off still count: the guard draws on them (round 4
|
||||
# review). Both Off, a cloud edge the guard catches: no cut, no pause.
|
||||
def _both_off(p, c):
|
||||
for u in "ab":
|
||||
c.store.data[_uk("inverter-" + u, _pm.USE_KEY)] = False
|
||||
|
||||
|
||||
r6o = S.drive(house=const(500.0), sun=steps((0, 13000.0), (910, 3000.0),
|
||||
(1030, 13000.0)),
|
||||
first="car", socs=ABLE, dur=1150, opts={"slew_w": 0},
|
||||
events={5: _both_off})
|
||||
want6o = [x["t"] for x in r6o["trace"] if x["since"] is not None
|
||||
and 905 <= x["t"] <= 960]
|
||||
w6o = [(t, v) for t, v in cur(r6o) if 900 <= t < 1150]
|
||||
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("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
|
||||
|
||||
print()
|
||||
|
||||
Reference in New Issue
Block a user