EV-16: time the Car Why hold on the control cycle, not on page reads
car_cycle ends with _car_why_tick (display only: control writes, never reads); the Why reads the record. Adds read-gap tests (A, B, cover off/on), a long guard-None test and a lower bound for the hold. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -61,8 +61,8 @@ class CarMixin:
|
||||
self.car_over = False # ... held: the card and row say so
|
||||
self._car_over_since = None
|
||||
self._car_over_gone = None
|
||||
self._car_why_hold = None # EV-16: the held Car Why (display)
|
||||
self._car_over_ep = 0 # EV-16: bumped by control at each start/end of car_over; the hold is valid for one value
|
||||
self._car_why_rec = None # EV-16: [shown over, since, episode]
|
||||
self._car_over_ep = 0 # EV-16: bumped when car_over ends
|
||||
self._car_batt_prev = self._car_batt_prev2 = None
|
||||
self._car_hx_prev = None # EV-19: last cycle's (held, car W)
|
||||
self._car_need_real = self._car_need_excl = False # EV-10 latches
|
||||
@@ -394,16 +394,40 @@ class CarMixin:
|
||||
if self._car_over_since is None:
|
||||
self._car_over_since = mono
|
||||
if mono - self._car_over_since >= OVER_HOLD_S:
|
||||
if not self.car_over:
|
||||
self._car_over_ep += 1 # EV-16: a new episode
|
||||
self.car_over = True
|
||||
else:
|
||||
if self._car_over_gone is None:
|
||||
self._car_over_gone = mono
|
||||
if mono - self._car_over_gone >= OVER_OFF_HOLD_S:
|
||||
self.car_over, self._car_over_since = False, None
|
||||
self._car_over_ep += 1 # EV-16: ends the held Why
|
||||
self._car_over_ep += 1 # EV-16: an episode ends
|
||||
self._car_over_gone = None
|
||||
self._car_why_tick(guard, mono)
|
||||
|
||||
def _car_why_tick(self, guard, mono) -> None:
|
||||
"""EV-16, display only: control writes `_car_why_rec`, never reads it.
|
||||
The Car Why text ("are at" / "give all they can") is held: it changes
|
||||
only when the other state has stood for `OVER_OFF_HOLD_S` of THIS
|
||||
cycle's clock (so reads of /status do not matter). State: floor-limited
|
||||
with the SoC read; a guard of None, or unread SoC, never counts as
|
||||
floor. Cleared when car_over is off or the cover is off."""
|
||||
if not (self.car_over and self.car_cover):
|
||||
self._car_why_rec = None
|
||||
return
|
||||
cand = None if guard is None else bool(
|
||||
getattr(guard, "floor_limited", False)
|
||||
and getattr(guard, "soc", None) is not None)
|
||||
ep = self._car_over_ep
|
||||
r = self._car_why_rec
|
||||
if r is None or r[2] != ep:
|
||||
self._car_why_rec = [bool(cand), None, ep]
|
||||
elif cand is None or cand == r[0]:
|
||||
r[1] = None
|
||||
else:
|
||||
if r[1] is None:
|
||||
r[1] = mono
|
||||
if mono - r[1] >= OVER_OFF_HOLD_S:
|
||||
self._car_why_rec = [cand, None, ep]
|
||||
|
||||
def _car_explains_alarm(self, real_proj, guard, target_w, w) -> bool:
|
||||
"""EV-10: is the alarm's own test true with the car and false without
|
||||
@@ -502,7 +526,7 @@ class CarMixin:
|
||||
# The session is over: that is a real end, with no hold.
|
||||
self.car_over = False
|
||||
self._car_over_since = self._car_over_gone = None
|
||||
self._car_over_ep += 1 # EV-16: ends the held Why
|
||||
self._car_over_ep += 1 # EV-16: an episode ends
|
||||
if s not in (chargers.NONE_, None) and self._car_prev_state in (
|
||||
chargers.NONE_, None):
|
||||
self._car_session += 1
|
||||
|
||||
Reference in New Issue
Block a user