EV-20: Car Solar mode, spare sun to the car (charging only)
checks / unit (pull_request) Successful in 57m6s
infra-pin / fresh (pull_request) Successful in 3s

Solar as a second writer next to Manual (carmode.SolarPlan, SolarWriter on
ManualWriter's one write site, safe phase sequence and other-writer watch):
signed spare, Batteries first on the batteries' ratings, the margin, whole
amps rounded down, the 30 s / 1 A rule, start and pause dwells, auto phases,
a one-phase car. Every way out ends at 0 A, retried by EV-04's rule; at
shutdown before the inverters, three tries inside 15 s (D3); start-up and a
returning charger or HA write 0 A first (D2); never over another writer's
hold. The peak guard treats a Solar car as a Manual car (D1 wording). Solar
kWh sensor and card line; select.goodwe_car_sun_first; ev_margin_w,
ev_start_min, ev_pause_min with config, validator, translations, DOCS,
DECISIONS and CHANGELOG.

Checks: test_ev20.py, test_ev20_exits.py, test_ev20_writers.py,
test_ev20_guard.py, test_ev20_long.py, test_ev20_long_car.py,
test_ev20_fuzz.py (harness tools/ev20_sun.py, ev20_kit.py, ev20_day.py);
test_ev03/test_ev04 no longer use Solar as the refused example.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
Claude
2026-11-22 20:31:26 +01:00
parent 885528ab48
commit 226e5a1e8b
35 changed files with 4647 additions and 123 deletions
+68 -7
View File
@@ -1134,7 +1134,7 @@ def month_peak(c, now):
ceiling = pg.ceiling_w or limit_w
real = getattr(c, "_peak_proj_real", None)
if getattr(c, "car_enabled", False) and c.charger.configured() \
and not c.car_cover and c.car_manual() and real is not None \
and not c.car_cover and c.car_controlled() and real is not None \
and getattr(real, "block_start", None) is not None:
# EV-04, decision 1 off: the guard's own projection leaves the car
# out; the period as the meter will bill it does not.
@@ -1374,6 +1374,54 @@ def _car_manual_why(c, key):
return _t("car.why.manual_set", a=a, phases=car_phases_word(c.car_n))
def _car_solar_why(c, key):
"""EV-20: the Why of Solar, from what the writer and its plan did this
cycle. Plan lines: two sentences of at most 12 words."""
w = c.car_solar
p = w.plan
o = getattr(c, "o", {}) or {}
if c.car_over: # D1
return _t("car.why.solar_over", a=f"{c.car_amps_now():.0f}")
if w.hold:
return _t("car.why.solar_other")
if w.zero_owed:
# The way-out 0 A is not taken yet: never "paused".
return _t("car.why.solar_zero_failed" if w.gave_up
else "car.why.solar_zeroing")
if w.gave_up:
return _t("car.why.solar_refused")
if c.shadow:
a, n = w.would if w.would is not None else (0.0, p.n)
if a and a >= 6:
return _t("car.why.manual_would", a=f"{float(a):.0f}",
phases=car_phases_word(n))
return _t("car.why.solar_would")
if not c.auto or not c.car_writing():
return _t("car.why.solar_stopped")
if w.fault in ("error", "stuck"):
return _t("car.why.solar_" + w.fault)
if key == "none":
return _t("car.why.none")
why = p.why
sun = w.sun
if why == "running":
if sun is None or sun.spare_w is None:
return _t("car.why.solar_unknown")
if sun.first == carmode.FIRST_CAR:
return _t("car.why.solar_car",
kw=_kw(max(0.0, sun.spare_w - sun.margin_w)))
return _t("car.why.solar_batt",
kw=_kw(max(0.0, sun.spare_w - sun.room_w - sun.margin_w)))
if why == "hold":
return _t("car.why.solar_hold", s=f"{carmode.solar_option(o, 'ev_pause_min'):.0f}")
if why == "unknown":
return _t("car.why.solar_unknown")
s = f"{carmode.solar_option(o, 'ev_start_min'):.0f}"
if why == "start":
return _t("car.why.solar_start", s=s)
return _t("car.why.solar_paused", s=s)
def car_block(c, now):
"""The Car card for `/status`, or None when no charger is switched on (the
page then draws nothing, as before)."""
@@ -1386,12 +1434,21 @@ def car_block(c, now):
good = c.car.last_good
fresh = configured and c.car.fresh(mono)
today = None
if configured and c.car.today_kwh is not None:
today = _t("car.today", kwh=_kwh(c.car.today_kwh))
mode = getattr(c, "car_mode", "off") if configured else "off"
if configured and c.car.today_kwh is not None:
sun = c.car_sun_kwh() if mode == "solar" else None
today = (_t("car.today_sun", kwh=_kwh(c.car.today_kwh),
sun=_kwh(sun)) if sun is not None
else _t("car.today", kwh=_kwh(c.car.today_kwh)))
why = _car_why(key, c, good)
if mode == "manual" and key in ("charging", "waiting", "none", "full"):
why = _car_manual_why(c, key)
if mode == "solar" and key in ("charging", "waiting", "none", "full",
"fault"):
why = _car_solar_why(c, key)
# EV-20: a car Solar holds at 0 A is waiting for the sun.
if key == "waiting" and c.car_solar.plan.a <= 0.0:
key = "paused"
out = {
"state": key or "wait",
"chip": car_state_word(key),
@@ -1404,11 +1461,14 @@ def car_block(c, now):
else round(float(r.power_w), 1)),
}
if configured:
# EV-04: what the page can set. Off and Manual only (Solar and Night
# are later cards, so they are not offered).
# EV-04: what the page can set. EV-20 adds Solar and where its spare
# sun goes first (Night is a later card, so it is not offered).
clamp = c.car_clamp()
hi = int(clamp) if clamp is not None and clamp >= 6 else 6
out["modes"] = ["off", "manual"]
out["modes"] = list(carmode.MODES)
out["first"] = {"value": getattr(c, "car_first",
carmode.DEFAULT_FIRST),
"choices": list(carmode.FIRSTS)}
out["current"] = {"value": round(float(c.car_a)), "min": 6,
"max": hi}
out["phases"] = {"value": c.car_n,
@@ -1928,12 +1988,13 @@ def _samples() -> list:
words["car"]["big"]]
out += [("plan", _t("car.why." + k, a="10", brand="Alfen", kw="8.6 kW",
pct="20 %", phases=car_phases_word(3),
real=car_phases_word(1)))
real=car_phases_word(1), s="5"))
for k in words["car"]["why"]]
out += [("plan", _t("peak.car", kw="12.1 kW", car="11.0 kW",
cov="8.6 kW")),
("plan", _t("peak.set_by_car", t="19:45"))]
out += [("plan", _t("car.today", kwh="14.2 kWh")),
("plan", _t("car.today_sun", kwh="14.2 kWh", sun="3.1 kWh")),
("plan", "11.0 kW · 16 A · " + _t("car.phase_many", n=3))]
out += [("plan", line_no_trade(k)) for k in
("not_covered", "no_prices", "peak", "not_firm", "not_worth",