EV-05 round 6: grade the car out only while Solar can cut it
checks / unit (pull_request) Successful in 25m32s
infra-pin / fresh (pull_request) Successful in 1s

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:
ems-agent
2026-11-18 18:50:37 +01:00
co-authored by Claude
parent 69f58181bc
commit b4a222f9e8
3 changed files with 209 additions and 11 deletions
+34 -11
View File
@@ -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: