EV-04 round 2: race-free another-writer check, refused phase select, undo before the select, clamped restore, energy-corroborated car figure
checks / unit (pull_request) Successful in 21m14s
infra-pin / fresh (pull_request) Successful in 1s

M1 the writer ignores a reading taken before its latest confirmed write.
M2 a refused phase select gives the current back and stops after 3 tries (amber row).
M3 Off, shadow mode or a control/safety stop before the select undoes the change.
M4 the restore on shutdown (and the undo) is clamped.
M5 the car's power reaches the alarm path only while the charger's energy meter agrees with it.
L1 fuzz other-writer branch reachable and shown to run. L2 one wording. L3 Batteries-help-off text.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
glenn schrooyen
2026-11-16 06:51:15 +01:00
co-authored by Claude
parent 0c92239a63
commit 661a3b009a
11 changed files with 493 additions and 68 deletions
+13 -2
View File
@@ -64,6 +64,8 @@ class SimCharger:
self.lag_s = 0.0 # a write shows in the read-back this late
self.refuse = None # None | "ignore" | "error"
self._snap = None # `freeze()`: the readings stop moving
self._frozen_w = None # `freeze_power()`: only the power does
self.no_energy = False # a charger with no energy entity
self.ramp_w_s = RAMP_W_S # how fast the power follows its target
self.stop_delay_s = 0.0 # mode3 stays C this long after 0 A
self._c_hold = 0.0
@@ -183,6 +185,11 @@ class SimCharger:
moment, whatever the charger does after it."""
self._snap = self._build() if on else None
def freeze_power(self, on=True):
"""Only the power sensor sticks, at what it reads now; the energy meter
and the rest go on telling the truth."""
self._frozen_w = self.power_w if on else None
def states(self) -> dict:
return self._snap if self._snap is not None else self._build()
@@ -207,7 +214,8 @@ class SimCharger:
{"A": "Available", "B": "EV Connected",
"C": "Charging Normal"}.get(self.state, "Error")),
st(f"sensor.{x}_active_power_total_socket_1",
f"{self.power_w:.0f}", "W"),
f"{self.power_w if self._frozen_w is None else self._frozen_w:.0f}",
"W"),
st(f"sensor.{x}_meter_reading_socket_1", f"{self.kwh:.2f}",
"kWh"),
st(f"sensor.{x}_current_l1_socket_1", f"{amps[0]:.1f}", "A"),
@@ -226,7 +234,10 @@ class SimCharger:
"state": bad or ("on" if self.login_on else "off"),
"attributes": {"device_class": "connectivity"}}),
]
return dict(rows)
out = dict(rows)
if self.no_energy:
out.pop(f"sensor.{x}_meter_reading_socket_1", None)
return out
class FakeHa: