EV-13 review round 2: tie the driver's polls to the cycle reading per phase (D1, D2)
checks / unit (pull_request) Successful in 30m36s
infra-pin / fresh (pull_request) Successful in 1s

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-22 10:45:14 +01:00
parent 57a9f56a64
commit 6cd775788d
+82
View File
@@ -1070,6 +1070,88 @@ tr, first, ever = play(steady({70: dict(a=10.0)}, **zero), "live", pre=zero)
check(f"P4 the read-back moves at +70: stuck at +60 first, as on the base "
f"(first {first}-{TS})", first == TS + 60 and tr.armed_at is None)
# =========================================================================== #
print("\n7b. THE DRIVER'S POLLS ARE THE CYCLE'S READING, PER PHASE (review round 2)")
# =========================================================================== #
# On a frozen Alfen the polls `_took` keeps are all the tracker sees of the
# refusal's window. If `_poll` lists the phases in another order than
# `reading_from_states`, a frozen 1-phase car reads as a change and is never
# flagged. T11/T16/T20 run at 0 W (every phase 0 A) and the S shapes build
# their polls by hand, so these two checks tie the real driver to the cycle.
_clk = {"t": 0.0}
async def _frozen_1ph_3ph(phases):
"""Real AlfenHaDriver on chargersim: a car on `phases` phases at 16 A, the
charger frozen (every state), the write ignored: `_took` times out and its
polls reach `note_write`."""
sim = SimCharger(phases_allowed=phases, setpoint_a=16.0)
sim.car_phases = phases
sim.state, sim.power_w = "C", 16.0 * 230.0 * phases
sim.refuse = "ignore"
sim.freeze()
drv = CH.AlfenHaDriver("number.wallbox_" + CH.SETPOINT_SUFFIX, 16.0)
drv.bind(FakeHa(sim))
drv._clock = lambda: _clk["t"]
async def _sleep(sec):
_clk["t"] += sec
drv._sleep = _sleep
tr = CH.CarTracker()
_clk["t"] = TS - 10
while _clk["t"] <= TS:
tr.observe(await drv.read(), _clk["t"], UTC, DAY)
_clk["t"] += 1.0
_clk["t"] = TS + 0.3
ok = await drv.write_current(10.0)
tr.note_write(TS, 16.0, 10.0, ok, drv.polls)
first = None
while _clk["t"] <= TS + 130:
_clk["t"] += 1.0
tr.observe(await drv.read(), _clk["t"], UTC, DAY)
if first is None and tr.stuck(_clk["t"]):
first = _clk["t"] - TS
return ok, tr, first, len(drv.polls)
for _n in (1, 3):
_ok, _tr, _first, _np = asyncio.run(_frozen_1ph_3ph(_n))
N2.append((f"D1 driver, frozen {_n}-phase car [driver]",
None if _first is None else _first))
check(f"D1 driver on chargersim, frozen charger, {_n}-phase car at 16 A, "
f"write ignored (not ok, {_np} polls): armed at the send, stuck at "
f"+60 (+-1) (armed {_tr.armed_at}, first {_first})",
not _ok and _np >= 2 and _tr.armed_at == TS and _first is not None
and 59 <= _first <= 61.5)
async def _poll_vs_cycle(drop):
"""`_life_vals` of `_poll`'s reading equals that of the cycle's reading,
on the same states, with distinct per-phase currents; `drop` removes a
phase (an entity that does not answer)."""
sim = SimCharger(phases_allowed=3, setpoint_a=16.0)
drv = CH.AlfenHaDriver("number.wallbox_" + CH.SETPOINT_SUFFIX, 16.0)
drv.bind(FakeHa(sim))
st = await drv._states()
for k, v in (("l1", "15.5"), ("l2", "16.5"), ("l3", "17.5")):
st[k] = dict(st[k], state=v) if isinstance(st[k], dict) else st[k]
if drop:
st[drop] = None
cyc = CH.reading_from_states(st)
drv.polls = []
drv._poll(st)
return cyc, drv.polls[0][1]
for _drop in (None, "l1", "l2", "l3"):
_cyc, _pl = asyncio.run(_poll_vs_cycle(_drop))
check(f"D2 `_life_vals` of _poll's reading equals the cycle reading's, "
f"{'all three phases present' if _drop is None else _drop + ' missing'}"
f" ({CH._life_vals(_pl)[2:]} vs {CH._life_vals(_cyc)[2:]})",
CH._life_vals(_pl) == CH._life_vals(_cyc) and _cyc.available
and (_drop is not None or CH._life_vals(_cyc)[2:5] ==
(15.5, 16.5, 17.5)))
# =========================================================================== #
print("\n8. N-IDS")
# =========================================================================== #