EV-18 review round 2: the contradiction latch touches only the alarm; an unknown energy reading is not a contradiction
- [Critical] The latch set `w = None` before `_car_quarter`, so with cover off the guard's input (`car_exclude`) counted the car as house and the batteries discharged. The latch now changes only the figure graded for the alarm; the car's energy count, the guard's input and the car-over row keep the unlatched `car_alarm_w()`. Cover-off N4 twins (energy gap, T9(c) liar, SoC 60 % and at the reserve) give the same commands as without the latch. - [Major] `corroborated()` is False for an unknown energy reading, so one missing reading latched a correct figure for the quarter. New `CarTracker.contradicted()`: only a meter that answered over a whole window and fell short. R1 (energy entity unknown 1 s at E+200, T2 and T3 shapes): red for that cycle only, explained from the next. - Minors: unit checks that a contradiction in our own pause latches nothing (MF) and that the latch ends with the quarter (MG). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -790,6 +790,17 @@ class CarTracker:
|
||||
return got_wh >= CORR_RATIO * exp_wh - CORR_SLACK_WH
|
||||
return True
|
||||
|
||||
def contradicted(self, now: float) -> bool:
|
||||
"""EV-18: did the energy meter answer over a whole window and fall
|
||||
short (`corroborated` compared and failed)? Not when the energy
|
||||
reading is unknown, the window is empty or still short, or the car is
|
||||
not charging: those are unknown, not contradicted."""
|
||||
r = self.reading
|
||||
if r is None or not r.available or r.charging is not True \
|
||||
or r.energy_kwh is None or not self._hist:
|
||||
return False
|
||||
return not self.corroborated(now)
|
||||
|
||||
def stuck(self, now: float) -> bool:
|
||||
"""Power and read-back unchanged `STUCK_S` after a write that moved the
|
||||
setpoint. Cleared the moment either moves."""
|
||||
|
||||
@@ -238,15 +238,17 @@ class CarMixin:
|
||||
return 0.0 <= mono - wr.phase_done_at <= OWN_PAUSE_TAIL_S
|
||||
|
||||
def _car_contradicted(self, mono) -> bool:
|
||||
"""EV-18 (owner 2026-11-19): does the charger's energy meter
|
||||
contradict a fresh, not stuck figure of a charging car? Then that
|
||||
figure stays untrusted to the quarter's end (`car_cycle`)."""
|
||||
"""EV-18 (owner 2026-11-19): did the charger's energy meter answer
|
||||
and fall short of a fresh, not stuck figure of a charging car
|
||||
(`CarTracker.contradicted`)? Then that figure stays untrusted for the
|
||||
alarm to the quarter's end (`car_cycle`). An unknown energy reading
|
||||
contradicts nothing."""
|
||||
r = getattr(self.car, "reading", None)
|
||||
if r is None or not r.available or r.charging is not True \
|
||||
or not self.car_manual():
|
||||
return False
|
||||
return (self.car.car_w(mono) is not None and not self.car.stuck(mono)
|
||||
and not self.car.corroborated(mono))
|
||||
and self.car.contradicted(mono))
|
||||
|
||||
def _car_idle(self, mono) -> bool:
|
||||
"""EV-18: is the car known to draw nothing? A fresh reading that says
|
||||
@@ -345,18 +347,19 @@ class CarMixin:
|
||||
# car at 0 A and the energy meter cannot corroborate it then, so for
|
||||
# that bounded time its fresh, not stuck figure stands in.
|
||||
own = (w is None or float(w) <= 0.0) and self._car_own_pause(mono)
|
||||
# EV-18: a figure the meter contradicted is not trusted again in
|
||||
# that quarter, not even as the stand-in for our own pause.
|
||||
key = None if real_proj is None else real_proj.block_start
|
||||
if key is not None and not own and self._car_contradicted(mono):
|
||||
self._car_contra_block = key
|
||||
if key is not None and key == self._car_contra_block:
|
||||
w, own = None, False
|
||||
wg = w
|
||||
if w is None and own:
|
||||
wg = self.car.car_w_paused(mono)
|
||||
self._car_quarter(real_proj, w, mono, wg)
|
||||
self._car_session_tick(mono)
|
||||
# EV-18 (owner 2026-11-19): a figure the meter contradicted grades no
|
||||
# alarm again in that quarter, not even as our own pause's stand-in.
|
||||
# The alarm decision only: the car's energy count, the guard's input
|
||||
# (`car_exclude`) and the car-over row keep the figure.
|
||||
key = None if real_proj is None else real_proj.block_start
|
||||
if key is not None and not own and self._car_contradicted(mono):
|
||||
self._car_contra_block = key
|
||||
contra = key is not None and key == self._car_contra_block
|
||||
explains = over = False
|
||||
if real_proj is not None and target_w is not None \
|
||||
and real_proj.block_start is not None:
|
||||
@@ -365,9 +368,11 @@ class CarMixin:
|
||||
# (the house's own need); it and a 0 W figure explain nothing,
|
||||
# but in our own pause (EV-15).
|
||||
idle = wg is None and self._car_idle(mono)
|
||||
graded = self._car_explains_alarm(real_proj, guard, target_w,
|
||||
0.0 if idle else wg)
|
||||
if idle or (w is not None and float(w) <= 0.0 and not own):
|
||||
graded = self._car_explains_alarm(
|
||||
real_proj, guard, target_w,
|
||||
None if contra else 0.0 if idle else wg)
|
||||
if contra or idle or (w is not None and float(w) <= 0.0
|
||||
and not own):
|
||||
graded = False
|
||||
if self.car_cover:
|
||||
explains = over = graded
|
||||
|
||||
Reference in New Issue
Block a user