EV-03 round 2: a missing car power is unknown, and mode3 E/F has a state
- 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:
@@ -495,8 +495,8 @@ def census_entity(opts: dict) -> str:
|
||||
# --------------------------------------------------------------------------- #
|
||||
# The car's state, kept over time
|
||||
# --------------------------------------------------------------------------- #
|
||||
CHARGING, WAITING, NONE_, FULL, UNREACH, SETUP = (
|
||||
"charging", "waiting", "none", "full", "unreach", "setup")
|
||||
CHARGING, WAITING, NONE_, FULL, UNREACH, SETUP, FAULT = (
|
||||
"charging", "waiting", "none", "full", "unreach", "setup", "fault")
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -559,11 +559,18 @@ class CarTracker:
|
||||
return self.last_ok is not None and now - self.last_ok <= self.stale_s
|
||||
|
||||
def car_w(self, now: float):
|
||||
"""The car's power now, or None when the reading is not fresh."""
|
||||
if not self.fresh(now) or self.reading is None or \
|
||||
not self.reading.available:
|
||||
"""The car's power now, or None (unknown) when the reading is not fresh
|
||||
OR the current reading carries no power. Never the last good figure: a
|
||||
read that says "no power" contradicts it, and absence is never zero. It
|
||||
never raises (telemetry has no foot in the control path)."""
|
||||
r = self.reading
|
||||
if not self.fresh(now) or r is None or not r.available \
|
||||
or r.power_w is None:
|
||||
return None
|
||||
try:
|
||||
return max(0.0, float(r.power_w))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
return max(0.0, float(self.reading.power_w))
|
||||
|
||||
# -- the two-writer detector ----------------------------------------------
|
||||
def _writer(self, r, now_utc):
|
||||
@@ -634,6 +641,8 @@ class CarTracker:
|
||||
r = self.reading
|
||||
if r is None or not r.available:
|
||||
return None if self.last_good is None else self.last_status
|
||||
if r.state in ("E", "F"): # the charger's own error states
|
||||
return FAULT
|
||||
if r.state == "A" or (r.state is None and r.connected is False):
|
||||
return NONE_
|
||||
if r.state in ("B", "C", "D") or r.connected:
|
||||
|
||||
Reference in New Issue
Block a user