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
5.4 KiB
EV-20 — Solar mode: spare sun to the car (charging only)
Part 1 of the split of cancelled EV-05 (owner 2026-11-19). The design is
reports/EV-01-design-report.md sections 2-5 and decision 5; the rules are
EV-20's brief (Expected 1-15, D1-D4). EV-21 (the car cut first for the peak)
and EV-22 (another writer's phase change) are separate cards. This record keeps
what the code had to decide.
Where it lives
app/carmode.py: SolarPlan (pure: the spare, the room, the dwells, the auto
phases) and SolarWriter, a subclass of EV-04's ManualWriter. It writes only
through ManualWriter._write and _advance, so the two write call sites stay
exactly two (test_ev04 / test_ev20 T55). app/ctl_car.py builds the inputs
(car_spare_w, car_room_w), runs the step beside the cycle, the release at
shutdown and today's solar kWh.
One rule for every write (EV-05 review rounds 2-9)
EV-05 needed nine review rounds, mostly on exits and other writers. EV-20 keeps one small set of facts and derives every path from them:
sent_a: the current Solar last decided, recorded BEFORE the write goes out;taken: the charger confirmed it. A write cancelled while it waits is never trusted (round 2, T37).- A value is written when Solar DECIDES a new one. One the charger did not take is tried again after 60 s, three times, then the gave-up row and one CHARGER_REFUSED warning (EV-04's rule; round 2's Critical, T36). A new 0 A gets its own three tries and never waits.
- A read-back that shows what Solar sent confirms it, however late (round 9's second Major, T48).
- A read-back that differs from what Solar sent is never written over:
EV-04's
_watchjudges it, and while the difference stands Solar writes nothing in its running state. After 30 s the hold (amber row, one CHARGER_OTHER warning) stops every write, the way-out 0 A and the shutdown's included (N16; rounds 5-7). Only pressing Solar lifts it. live: Solar's own current may stand on the charger (a non-zero value it sent, or a 0 A not yet confirmed). A way out (Off, Stop, shadow, a safety stop, a charger error or stuck reading, no car, shutdown) writes 0 A only then. So a start in shadow writes nothing, and once the way-out 0 A is confirmed nothing more is written, shutdown included (rounds 6 and 7).- The start-up and a charger (or Home Assistant) that comes back write 0 A first whatever the charger shows, with the read-back references cleared, so its own value is never "another writer" (D2; round 9's first Major, T29, T30, T61).
Choices the brief left open
- Writes over an unexplained read-back stop at once, not after 30 s: the plan goes on, the next decision waits. A way out still writes its 0 A inside those 30 s (T39 (b)): 0 A is the safe side.
- The phases follow the charger. Solar's arithmetic uses the phases the charger reports (1 for a one-phase car); its plan adopts them whenever it is not switching. It selects only by its own dwells (and a start from a pause in auto, on 1 phase), never "back" over a change it did not make (D4: EV-22). A lower current is never blocked by the 10-minute phase gap (round 8, T46).
- An interrupted phase change ends at its 0 A. Manual's restore of the old current stays Manual's.
- Pressing Solar lifts another writer's hold and takes the charger as it is; Solar's own value is then decided and written afresh. Choosing Solar from another mode starts paused: 0 A, then the start rule.
- Stale and unknown. The spare is unknown with a meter older than
stale_input_s(P1's own bound may be longer), readings late past it, a missing or NaN battery or grid figure, or a charging car whose figure is stale, stuck or not corroborated. A paused or idle car counts as 0 W. Unknown holds the current forev_pause_min, then 0 A. A cycle that returns early for missing or late readings still steps Solar (Manual is left as it was). - The guard treats a Solar car exactly as a Manual car (Expected 8): every
alarm-path test that said "Manual" says "Manual or Solar"
(
car_controlled). Solar's own phase change gets EV-15's grace as Manual's; its own 0 A pause gets it from the send, at mostOWN_PAUSE_MAX_S, and only while the read-back still shows that 0 A (round 8's second Major). - D1 wording. The card's Why says "Solar charges the car at {a} A. This
sets the peak."; STYLE.md allows a grey note and a grey row one sentence, so
they say "Solar charges the car at {a} A, which sets the peak."
{a}is the charger's read-back, never Manual's stored current. - D3 at shutdown. In Solar the charger's 0 A goes out before the inverters'
0 W: up to three tries 5 s apart, each waiting 4 s for its read-back
(
write_current(took_s=...)), all insideRELEASE_WAIT_S(15 s, also a wall-clock bound for a charger that hangs). Not taken: one CHARGER_RELEASE warning, the notice Car may still be charging after the inverters are released, and the next start writes 0 A first (D2) and takes the notice down. - A charger error sets 0 A (while owed) with one CHARGER_ERROR warning and the card's Why; the existing grey error row shows it. No new notification.
- Solar kWh is counted per cycle in Solar only:
min(car, max(0, spare - room))Batteries first,min(car, max(0, spare))Car first; never above today's kWh; stored with its day, reset at the day's change. - Rollback. An older build reads a stored
car_mode = solaras Off (start_mode) and writes nothing; no state migration.