EV-13 review: compare phase currents per phase; test a late read-back
A phase that drops out or comes back shifted the compressed current_a tuple and read as life, so a frozen charger never armed. ChargerReading.phase_a keeps L1/L2/L3 with None for a missing phase and the life test uses it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
@@ -166,6 +166,7 @@ class ChargerReading:
|
||||
# EV-13: when the sample was TAKEN, on the tracker's clock. None: the
|
||||
# caller's `now` (in the cycle that is the read's start, `now_mono`).
|
||||
taken_at: float | None = None
|
||||
phase_a: tuple = () # EV-13: L1, L2, L3 each, None if not read
|
||||
|
||||
|
||||
def _state_obj(obj):
|
||||
@@ -285,6 +286,7 @@ def reading_from_states(states: dict) -> ChargerReading:
|
||||
available=True, state=letter, connected=connected, charging=charging,
|
||||
power_w=power, energy_kwh=_kwh(states.get("energy")),
|
||||
current_a=currents, setpoint_a=_amps(states.get("current")),
|
||||
phase_a=tuple(_amps(states.get(k)) for k in ("l1", "l2", "l3")),
|
||||
allowed_a=_amps(states.get("readback")),
|
||||
phases_allowed=_phases(states.get("phases_read")),
|
||||
station_a=_first(_amps(states.get("station_active")),
|
||||
@@ -544,11 +546,10 @@ class AlfenHaDriver(ChargerDriver):
|
||||
"""EV-13: keep what this wait saw of energy, power and phase currents
|
||||
(never raises: a write does not depend on it)."""
|
||||
try:
|
||||
cur = tuple(a for a in (_amps(st.get(k)) for k in ("l1", "l2", "l3"))
|
||||
if a is not None)
|
||||
self.polls.append((self._clock(), ChargerReading(
|
||||
available=True, power_w=_watts(st.get("power")),
|
||||
energy_kwh=_kwh(st.get("energy")), current_a=cur)))
|
||||
energy_kwh=_kwh(st.get("energy")),
|
||||
phase_a=tuple(_amps(st.get(k)) for k in ("l1", "l2", "l3")))))
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
||||
@@ -656,8 +657,13 @@ CHARGING, WAITING, NONE_, FULL, UNREACH, SETUP, FAULT = (
|
||||
def _life_vals(r) -> tuple:
|
||||
"""EV-13: what shows a charger is alive: energy, power, three phase
|
||||
currents. None is "not read"."""
|
||||
cur = tuple(r.current_a or ())[:3]
|
||||
return (r.energy_kwh, r.power_w) + cur + (None,) * (3 - len(cur))
|
||||
cur = tuple(r.phase_a or ())
|
||||
if len(cur) != 3:
|
||||
# Only `current_a`, which leaves out a phase that is not read: which
|
||||
# phase is which is then known only when all three are there.
|
||||
cur = tuple(r.current_a or ())
|
||||
cur = cur if len(cur) == 3 else (None,) * 3
|
||||
return (r.energy_kwh, r.power_w) + cur
|
||||
|
||||
|
||||
def _alive(vals: tuple, pre: list) -> bool:
|
||||
|
||||
@@ -78,11 +78,13 @@ TOOK_S, STUCK_S = CH.TOOK_S, CH.STUCK_S
|
||||
print("1. S: WHAT COUNTS AS LIFE")
|
||||
# =========================================================================== #
|
||||
def rd(e=1.000, p=11040.0, cur=(16.0, 15.9, 16.0), a=16.0, taken=None,
|
||||
state="C"):
|
||||
state="C", ph=None):
|
||||
"""`cur` is `current_a` (a missing phase is left out of it); `ph` is the
|
||||
per-phase `phase_a` (None for a missing phase) the driver also sets."""
|
||||
return CH.ChargerReading(
|
||||
available=True, state=state, charging=state == "C", power_w=p,
|
||||
energy_kwh=e, current_a=cur, allowed_a=a, setpoint_a=a,
|
||||
phases_allowed=3, taken_at=taken)
|
||||
phases_allowed=3, taken_at=taken, phase_a=ph or ())
|
||||
|
||||
|
||||
def steady(changes=None, start=1, end=130, **base):
|
||||
@@ -174,6 +176,21 @@ life("T9 the step at +9, inside the window", {9: dict(e=1.010)})
|
||||
life("T9 the step exactly at +10 (the edge counts)", {10: dict(e=1.010)})
|
||||
life("T12(a) power None, state C, energy rising", {4: dict(e=1.010)},
|
||||
pre=dict(p=None))
|
||||
# P1/P2 (review): a phase that drops out or comes back is no change: the
|
||||
# others must not shift against another phase's old value
|
||||
armed("P1 L1 present before, absent after, all else frozen",
|
||||
steady(cur=(16.0, 16.1)))
|
||||
armed("P2 L1 absent before, present after (current_a only), all else frozen",
|
||||
steady(), pre=dict(cur=(15.9, 16.0)))
|
||||
armed("P1 per phase: L1 present before, absent after (phase_a)",
|
||||
steady(cur=(16.0, 16.1), ph=(None, 16.0, 16.1)),
|
||||
pre=dict(ph=(15.9, 16.0, 16.1)))
|
||||
armed("P2 per phase: L1 absent before, present after (phase_a)",
|
||||
steady(ph=(15.9, 16.0, 16.1)), pre=dict(cur=(16.0, 16.1),
|
||||
ph=(None, 16.0, 16.1)))
|
||||
life("P5 per phase: L1 absent, L2 really changes (phase_a)",
|
||||
{4: dict(cur=(16.2, 16.1), ph=(None, 16.2, 16.1))},
|
||||
pre=dict(cur=(16.0, 16.1), ph=(None, 16.0, 16.1)))
|
||||
armed("T6 present but unchanged: every sample repeats the pre-write values",
|
||||
steady())
|
||||
armed("T9 the step at +11 is outside the window; armed_at is the send, not "
|
||||
@@ -1007,6 +1024,29 @@ for mode in ("live", "ring"):
|
||||
"window runs on and arms at the send", tr.armed_at == TS
|
||||
and first is not None and TS + 59 <= first <= TS + 61)
|
||||
|
||||
# P4 (review): a refusal with no life, and a read-back that arrives late but
|
||||
# inside TOOK_S. The base arms at the send and the moved read-back disarms it
|
||||
# ("it moved: alive"); the window must do the same, not arm on the new value.
|
||||
zero = dict(p=0.0, cur=(0.0, 0.0, 0.0))
|
||||
tr, first, ever = play(steady({5: dict(a=10.0)}, **zero), "live", pre=zero)
|
||||
check(f"P4 [live]: no life, the read-back moves at +5, after the refusal was "
|
||||
f"noted: armed dated the send and disarmed by the move, never stuck, "
|
||||
f"as on the base ({tr.armed_at}, {first})", first is None
|
||||
and tr.armed_at is None and not tr.stuck_now and pend(tr) is None)
|
||||
tr, first, ever = play(steady({5: dict(a=10.0)}, **zero), "ring", pre=zero)
|
||||
check(f"P4 [ring]: the read-back moved inside the window BEFORE the refusal "
|
||||
f"was noted (the write waited): it still arms, dated the send, and is "
|
||||
f"stuck at +60, as on the base (armed {tr.armed_at}, first {first})",
|
||||
tr.armed_at == TS and first == TS + 60)
|
||||
# ... and the same read-back arriving AFTER the window leaves it stuck until
|
||||
# it moves: 12 s in, the base has been armed since the send, so it disarms then
|
||||
tr, first, ever = play(steady({12: dict(a=10.0)}, **zero), "live", pre=zero)
|
||||
check("P4 the read-back moves at +12 (after the window): disarmed then, "
|
||||
"never stuck", first is None and tr.armed_at is None)
|
||||
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("\n8. N-IDS")
|
||||
# =========================================================================== #
|
||||
|
||||
Reference in New Issue
Block a user