EV-03 round 2: a missing car power is unknown, and mode3 E/F has a state
checks / unit (pull_request) Successful in 26m50s
infra-pin / fresh (pull_request) Successful in 2s

- CarTracker.car_w returns None when the current reading carries no power
  (power entity unavailable or in a non-power unit); it can no longer raise
  into the control cycle, /status or the MQTT values.
- mode3 E and F are the card state "fault" (EN and NL).
- chargersim gains fault().

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ev03-dev
2026-11-15 12:02:17 +01:00
co-authored by Claude
parent 984f4335a0
commit 678ea13895
6 changed files with 126 additions and 12 deletions
+96
View File
@@ -944,6 +944,102 @@ check("an absent number goes out as HA's own 'None' payload, and the PV rule "
"(ABSENT_AS_UNKNOWN is one key) is not widened",
mqtt.ABSENT_AS_UNKNOWN == frozenset({"pv"}))
# --------------------------------------------------------------------------- #
print("\n10. ROUND 2: A MISSING POWER READING IS AN UNKNOWN TERM, NEVER AN ERROR")
# --------------------------------------------------------------------------- #
import traceback # noqa: E402
def bad_power(kind):
"""A controller with one good reading, then (inside stale_s) an AVAILABLE
reading whose power is missing: `unavailable`, or in a non-power unit."""
sim_ = SimCharger()
sim_.plug_in()
sim_.set_phases(3)
sim_.set_current(10)
site_ = Site(sim_, grid=7500.0, batt=0.0, pv=500.0)
opts = dict(CAR, pv_forecast_entity="sensor.fc", battery_modes_enabled=True)
c_ = build(opts, site_)
del samples[:]
c_.house_profile = _HP()
asyncio.run(run_cycles(c_, site_, n=8, sim=sim_))
good_w = c_.car.reading.power_w
pw = f"sensor.{sim_.x}_active_power_total_socket_1"
orig = site_._all
def broken():
out = orig()
if kind == "unavailable":
out[pw] = dict(out[pw], state="unavailable")
else:
out[pw] = dict(out[pw], attributes={"unit_of_measurement": "V"})
return out
site_._all = broken
del samples[:]
res = {"good_w": good_w, "err": None}
try:
CLOCK[0] = 1000.0 + 8
asyncio.run(rin(c_, 1008.0)) # 1 s after the good one
res["fresh"] = c_.car.fresh(CLOCK[0])
res["avail"] = c_.car.reading.available and c_.car.reading.power_w is None
res["term"] = c_.car_term()
res["now"] = c_.status_payload()["now"]
res["card"] = c_.status_payload()["car"]
asyncio.run(c_.cycle()) # the trade cycle's profile step
res["sample"] = samples[-1] if samples else "none"
res["vals"] = c_.car_values()
except Exception: # noqa: BLE001
res["err"] = traceback.format_exc().strip().splitlines()[-1]
return res
for kind in ("unavailable", "wrong unit"):
r_ = bad_power(kind)
check(f"{kind}: the reading is available with no power, and still inside "
f"stale_s (the case that raised)", r_["err"] is None
and r_.get("fresh") is True and r_.get("avail") is True)
check(f"{kind}: car_term, /status, the trade cycle and the MQTT values do "
f"not raise ({r_['err']})", r_["err"] is None)
check(f"{kind}: the term is UNKNOWN (never 0 W): House shows no reading and "
f"the profile sample is None", r_["err"] is None
and r_["term"] == (0.0, True) and r_["now"]["house_w"] is None
and r_["sample"] is None)
check(f"{kind}: the card shows no power figure and the MQTT power is the "
f"None payload", r_["err"] is None
and r_["card"]["power_w"] is None
and r_["vals"]["car_power"] == mqtt.PAYLOAD_NONE)
# E and F: the charger's own error states
for letter in ("E", "F"):
rr = CH.ChargerReading(available=True, state=letter, power_w=0.0,
allowed_a=10.0, setpoint_a=10.0)
tk = CH.CarTracker()
tk.observe(rr, 1.0, now_utc(), D)
check(f"mode3 {letter} is the defined state 'fault', not a blank",
tk.status(1.0) == "fault")
sim_f = SimCharger()
sim_f.plug_in()
sim_f.set_current(10)
site_f = Site(sim_f)
c_f = build(CAR, site_f)
asyncio.run(run_cycles(c_f, site_f, n=4, sim=sim_f))
sim_f.fault("E")
sim_f.tick(1)
asyncio.run(rin(c_f, 1010.0))
pf = c_f.status_payload()
check("fault card (EN): chip, big line, Why, amber",
pf["car"]["chip"] == "Charger fault" and pf["car"]["kind"] == "warn"
and pf["car"]["big"] == "The charger reports a fault."
and pf["car"]["why"] == "The charger reports a fault. Check it at the "
"charger itself.")
pfn = c_f.status_payload(lang="nl")
check("fault card (NL)", pfn["car"]["chip"] == "Laadpaal storing"
and pfn["car"]["big"] == "De laadpaal meldt een storing."
and pfn["car"]["why"] == "De laadpaal meldt een storing. Controleer ze "
"aan de laadpaal zelf.")
check("the MQTT state says it too", c_f.car_values()["car_state"]
== "Charger fault")
print()
if fails:
print(f"{len(fails)} FAILED")