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
+25 -23
View File
@@ -248,7 +248,7 @@ async def part2():
w = World()
out = {}
out["manual"] = await w.act("car_mode", "manual")
out["bad_mode"] = await w.act("car_mode", "solar") # not in this card
out["bad_mode"] = await w.act("car_mode", "bogus") # EV-20 accepts Solar
out["night"] = await w.act("car_mode", "night")
out["a12"] = await w.act("car_current", 12)
out["a5"] = await w.act("car_current", 5)
@@ -266,7 +266,7 @@ w2, o2 = run(part2())
check("Manual is chosen at once, no restart", o2["manual"] == {
"mode": "manual", "current": 6.0, "phases": 1} and w2.c.car_mode == "manual"
or w2.c.car_mode == "manual")
check("Solar and Night are not accepted (EV-05, EV-02)",
check("Night (EV-02) and an unknown mode are not accepted",
"error" in o2["bad_mode"] and "error" in o2["night"]
and w2.c.car_mode == "manual")
check("a current between 6 A and the clamp is accepted and stored",
@@ -307,7 +307,7 @@ check("ev_phases 1: 3 phases cannot be chosen, 1 can",
async def part2c():
out = {}
for start, stored in (("keep", "manual"), ("off", "manual"),
("keep", None), ("keep", "solar")):
("keep", None), ("keep", "night")):
st = _Store()
if stored:
st.data["car_mode"] = stored
@@ -322,7 +322,7 @@ check("ev_mode_start keep: a restart keeps Manual",
check("ev_mode_start off: a restart starts in Off and the store says so",
o2c[("off", "manual")] == ("off", "off"))
check("no stored mode, or one this build does not know, is Off",
o2c[("keep", None)][0] == "off" and o2c[("keep", "solar")][0] == "off")
o2c[("keep", None)][0] == "off" and o2c[("keep", "night")][0] == "off")
# =========================================================================== #
print("\n3. MANUAL WRITES THE CURRENT ONCE PER USER CHANGE")
@@ -1624,13 +1624,14 @@ pl = dict(mqtt.car_payloads((16, (1, 3))))
sel = pl["homeassistant/select/goodwe_ctl_car_mode/config"]
num = pl["homeassistant/number/goodwe_ctl_car_current/config"]
ph = pl["homeassistant/select/goodwe_ctl_car_phases/config"]
check("three entities: select.goodwe_car_mode, number.goodwe_car_current, "
"select.goodwe_car_phases", len(pl) == 3
check("four entities: select.goodwe_car_mode, number.goodwe_car_current, "
"select.goodwe_car_phases and (EV-20) select.goodwe_car_sun_first",
len(pl) == 4
and sel["object_id"] == "goodwe_car_mode"
and num["object_id"] == "goodwe_car_current"
and ph["object_id"] == "goodwe_car_phases")
check("the mode's labels are English and pinned: Off, Manual (Solar and Night "
"are not offered)", sel["options"] == ["Off", "Manual"])
check("the mode's labels are English and pinned: Off, Manual, Solar (EV-20; "
"Night is not offered)", sel["options"] == ["Off", "Manual", "Solar"])
check("the current is 6 A to the clamp, whole amps", num["min"] == 6
and num["max"] == 16 and num["step"] == 1
and num["unit_of_measurement"] == "A")
@@ -1647,7 +1648,7 @@ check("nothing is announced without a charger (and the default announcement "
"is as it was)", mqtt.car_payloads(None) == []
and mqtt.discovery_payloads() == mqtt.discovery_payloads(car=None))
check("the car entities come after every other row",
[t for t, _ in mqtt.discovery_payloads(car=(16, (1, 3)))][-3:]
[t for t, _ in mqtt.discovery_payloads(car=(16, (1, 3)))][-4:]
== [t for t, _ in mqtt.car_payloads((16, (1, 3)))])
cmd = mqtt.parse_car_command
check("a command parses: mode, current, phases",
@@ -1659,8 +1660,8 @@ check("a command parses: mode, current, phases",
== ("car_phases", 3, None))
check("a retained command is dropped",
cmd("goodwe_ctl/car/mode/set", b"Manual", True)[2] == "retained")
check("Solar, Night, junk and a long payload are refused",
cmd("goodwe_ctl/car/mode/set", b"Solar", False)[1] is None
check("Night, an unknown mode, junk and a long payload are refused",
cmd("goodwe_ctl/car/mode/set", b"Bogus", False)[1] is None
and cmd("goodwe_ctl/car/mode/set", b"Night", False)[1] is None
and cmd("goodwe_ctl/car/current/set", b"abc", False)[1] is None
and cmd("goodwe_ctl/car/phases/set", b"2", False)[1] is None
@@ -1678,7 +1679,7 @@ async def ha_story():
out = {"mode": w.c.car_mode, "a": w.c.car_a, "rb": w.sim.readback_a,
"pub": list(w.c.mqtt.values)[-1]}
await w.c.mqtt_command("goodwe_ctl/car/mode/set", b"Off", True) # retained
await w.c.mqtt_command("goodwe_ctl/car/mode/set", b"Solar", False)
await w.c.mqtt_command("goodwe_ctl/car/mode/set", b"Night", False)
await w.c.mqtt_command("goodwe_ctl/car/current/set", b"99", False)
await w.c.mqtt_command("goodwe_ctl/car/phases/set", b"2", False)
await w.step(5)
@@ -1696,8 +1697,8 @@ check("HA commands go through handle_action(): Manual and 13 A are applied "
"and written, and the new state is published",
ha["mode"] == "manual" and ha["a"] == 13.0 and ha["rb"] == 13
and ha["pub"] == {"car_mode": "Manual", "car_current": 13,
"car_phases": "1"})
check("a retained command, Solar, 99 A and 2 phases change nothing",
"car_phases": "1", "car_sun_first": "Batteries"})
check("a retained command, Night, 99 A and 2 phases change nothing",
ha["after"] == ("manual", 13.0, 1))
check("the three states are in the published values",
ha["state"].get("car_mode") == "Manual"
@@ -1718,11 +1719,11 @@ st_ = _S()
car_, retract_ = _main.car_announcement(CAR, st_)
check("with a charger the entities are announced and their topics kept",
car_ == (16.0, (1, 3)) and not retract_ and len(
st_.data["mqtt_car_configs"]) == 3)
st_.data["mqtt_car_configs"]) == 4)
car2, retract2 = _main.car_announcement(BASE, st_)
check("turning the charger off removes exactly those entities",
car2 is None and sorted(retract2) == sorted(st_.data["mqtt_car_configs"])
and len(retract2) == 3)
and len(retract2) == 4)
st2 = _S()
check("a site that never had a charger publishes nothing and its store is "
"not written",
@@ -1752,7 +1753,7 @@ async def web_story():
("manual", {"action": "car_mode", "value": "manual"}),
("a", {"action": "car_current", "value": 12}),
("n", {"action": "car_phases", "value": 3}),
("solar", {"action": "car_mode", "value": "solar"}),
("solar", {"action": "car_mode", "value": "night"}),
("big", {"action": "car_current", "value": 40})):
async with s.post(root + "action", json=body) as r:
out[key] = (r.status, await r.json(content_type=None))
@@ -1771,21 +1772,22 @@ check("POST /action car_mode, car_current and car_phases store and answer",
web["manual"] == (200, {"ok": True, "result": {
"mode": "manual", "current": 6.0, "phases": 1}})
and web["a"][0] == 200 and web["n"][0] == 200)
check("...Solar and 40 A (above the clamp) are a 400 with a plain reason",
check("...Night and 40 A (above the clamp) are a 400 with a plain reason",
web["solar"][0] == 400 and web["solar"][1]["ok"] is False
and web["solar"][1]["error"] == messages.car_refused("value")
and web["big"][0] == 400)
car_s = web["status_en"]["car"]
check("/status gives the page what it needs: the mode, the modes offered (Off "
"and Manual only), the current's range, the phases",
car_s["mode"] == "manual" and car_s["modes"] == ["off", "manual"]
check("/status gives the page what it needs: the mode, the modes offered (Off, "
"Manual and, EV-20, Solar), the current's range, the phases",
car_s["mode"] == "manual"
and car_s["modes"] == ["off", "manual", "solar"]
and car_s["current"] == {"value": 12, "min": 6, "max": 16}
and car_s["phases"] == {"value": 3, "choices": [1, 3]})
check("/status in Dutch has the Dutch Why",
web["status_nl"]["car"]["why"].startswith("U stelde 12 A in"))
check("the page has the controls and no Solar or Night button",
check("the page has the controls and no Night button (EV-20 adds Solar)",
'id="car-manual"' in web["page"] and 'id="car-a"' in web["page"]
and "mode_solar" not in web["page"] and "mode_night" not in web["page"])
and "mode_night" not in web["page"])
check("the page names the Manual strings in both languages",
"Handmatig" in web["page"] and "Manual" in web["page"])