EV-05 round 9: one test of control; another writer's phases are a hold
SolarWriter.in_control is the single test of "Solar has the charger": writing, read-back current and phases are Solar's own, no hold, no write refused, given up or owed. Alarm grading, banking, the own-pause grace and the cut use it. A phase change Solar did not make is another writer: nothing written over it, hold after 30 s, no select back after 10 min. While Solar's own switch waits, a lower current is written at once, and the arithmetic uses the phases the car draws on. A car another writer starts inside the own-pause grace is no longer graded out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e348a808ff
commit
c9a95f3c10
@@ -675,6 +675,13 @@ class SolarWriter(ManualWriter):
|
||||
self._one_since = None
|
||||
self.zero_at = None # EV-15: our own latest 0 A, sent then
|
||||
self.sent_a = None # the current we last decided to write
|
||||
# Round 9: the phases Solar knows as its own (None: not yet taken;
|
||||
# both after a select the charger did not confirm), whether the
|
||||
# latest read-back (current and phases) is Solar's own, and the
|
||||
# phases the car draws on while they differ from the plan's.
|
||||
self.ph_known = None
|
||||
self.own_rb = True
|
||||
self.n_draw = None
|
||||
|
||||
# ------------------------------------------------------------------ help
|
||||
def _mark(self, r, now) -> None:
|
||||
@@ -697,18 +704,58 @@ class SolarWriter(ManualWriter):
|
||||
_LOG.info("The car draws one phase while three are allowed, so "
|
||||
"the add-on counts one phase for this charge.")
|
||||
|
||||
def _watch(self, cur, now) -> None:
|
||||
"""As Manual's, and in Solar the hold is a warning: the add-on stops
|
||||
writing until you press the mode or the read-back matches again."""
|
||||
was = self.hold
|
||||
super()._watch(cur, now)
|
||||
if self.hold and not was:
|
||||
def _watch(self, cur, now, ph=None) -> None:
|
||||
"""As Manual's, for the current AND (round 9) the phases: a read-back
|
||||
that is not what Solar set (`own_rb` False) is another writer's, and
|
||||
after `WRITER_S` the hold. In Solar the hold is a warning: the add-on
|
||||
stops writing until you press the mode or the read-back matches."""
|
||||
known = [x for x in (self.last_a, self.attempted_a, self.prior_a)
|
||||
if x is not None]
|
||||
a_known = bool(known) and cur is not None
|
||||
a_bad = a_known and not any(abs(cur - k) <= TOL_A for k in known)
|
||||
p_known = ph in (1, 3) and bool(self.ph_known)
|
||||
p_bad = p_known and ph not in self.ph_known
|
||||
if p_known and not p_bad:
|
||||
self.ph_known = {ph} # a select confirmed late
|
||||
self.own_rb = not (a_bad or p_bad)
|
||||
if self.own_rb:
|
||||
self.mismatch_since = None
|
||||
if self.hold and (a_known or p_known):
|
||||
self.hold = self.other = False
|
||||
return
|
||||
if self.mismatch_since is None:
|
||||
self.mismatch_since = now
|
||||
elif now - self.mismatch_since >= WRITER_S and not self.hold:
|
||||
self.hold = self.other = True
|
||||
if p_bad:
|
||||
_LOG.info("Something else changed the charger's phases, so "
|
||||
"the add-on stops writing to it until you change "
|
||||
"it.")
|
||||
else:
|
||||
_LOG.info("Something else changes the charger (read-back "
|
||||
"%.0f A, the add-on set %.0f A), so the add-on "
|
||||
"stops writing to it until you change it.",
|
||||
cur, known[0])
|
||||
_LOG.warning("Something else changes the charger, so the add-on "
|
||||
"stops writing to it: CHARGER_OTHER.")
|
||||
|
||||
@property
|
||||
def in_control(self) -> bool:
|
||||
"""Round 9, the one test of "Solar has the charger now": it writes,
|
||||
the read-back current and phases are what it set, no other writer's
|
||||
hold, and no write of its own refused, given up or owed. Every place
|
||||
that acts as if Solar can cut the car asks this."""
|
||||
return bool(self.had_control and not self.out and self.own_rb
|
||||
and not self.hold and not self.gave_up
|
||||
and self.fail_at is None and self.attempted_a is None
|
||||
and self.fault is None and not self.zero_owed)
|
||||
|
||||
@property
|
||||
def n_calc(self) -> int:
|
||||
return 1 if self.single else self.plan.n
|
||||
"""The phases the sun arithmetic uses: those the car draws on."""
|
||||
if self.single:
|
||||
return 1
|
||||
return self.n_draw or self.plan.n
|
||||
|
||||
def amps_out(self, clamp) -> float:
|
||||
"""The plan's current, never above the clamp; 0 when under 6 A."""
|
||||
@@ -722,6 +769,10 @@ class SolarWriter(ManualWriter):
|
||||
hold is lifted by pressing the mode)."""
|
||||
super().user_changed()
|
||||
self.sent_a = None
|
||||
# Round 9: Solar takes the charger as it is (current and phases), so
|
||||
# the other writer's value is no longer a difference.
|
||||
self.last_a = None
|
||||
self.ph_known, self.own_rb = None, True
|
||||
|
||||
async def _write(self, drv, a, was, now, tracker) -> bool:
|
||||
self.inflight = a # cleared only when the write returns
|
||||
@@ -774,6 +825,7 @@ class SolarWriter(ManualWriter):
|
||||
self.fault = None
|
||||
self.reinit = True
|
||||
self.sent_a = None
|
||||
self.ph_known, self.own_rb, self.n_draw = None, True, None
|
||||
self.plan.reset(self.plan.n)
|
||||
|
||||
def _plan_step(self, sun, now, clamp) -> None:
|
||||
@@ -803,6 +855,7 @@ class SolarWriter(ManualWriter):
|
||||
if not self.was_available:
|
||||
self.was_available = True
|
||||
self.reinit = True # back: 0 A first, then the rules
|
||||
self.ph_known = None # ... on the phases it came back on
|
||||
cur = r.allowed_a if r.allowed_a is not None else r.setpoint_a
|
||||
if mode != SOLAR:
|
||||
self.would = None
|
||||
@@ -831,9 +884,10 @@ class SolarWriter(ManualWriter):
|
||||
# every reader (the exit, the shutdown, the peak alarms).
|
||||
self.seq = None
|
||||
self.out = True
|
||||
self.n_draw = None
|
||||
if self.had_control:
|
||||
await self._exit_zero("out", drv, cur, now, tracker)
|
||||
self._watch(cur, now)
|
||||
self._watch(cur, now, r.phases_allowed)
|
||||
self._plan_step(sun, now, clamp)
|
||||
self.would = (self.amps_out(clamp), self.n_calc)
|
||||
self.reinit = True
|
||||
@@ -876,13 +930,24 @@ class SolarWriter(ManualWriter):
|
||||
self.sent_a = None
|
||||
n = r.phases_allowed if r.phases_allowed in (1, 3) else self.plan.n
|
||||
self.plan.reset(n)
|
||||
if self.ph_known is None and r.phases_allowed in (1, 3):
|
||||
self.ph_known = {r.phases_allowed} # Solar takes the charger
|
||||
if status == CH.FULL: # the car is full: nothing written
|
||||
self.plan.why = "full"
|
||||
return
|
||||
self.n_draw = None
|
||||
if self.seq is None:
|
||||
self._watch(cur, now)
|
||||
self._watch(cur, now, r.phases_allowed)
|
||||
if self.hold:
|
||||
return
|
||||
if not self.own_rb:
|
||||
# Round 9: another writer's current or phases, not yet held
|
||||
# (`WRITER_S`): the plan goes on, nothing is written over it.
|
||||
self._plan_step(sun, now, clamp)
|
||||
return
|
||||
if r.phases_allowed in (1, 3) and cur is not None \
|
||||
and cur >= CH.MIN_A:
|
||||
self.n_draw = r.phases_allowed # what the car draws on
|
||||
self._plan_step(sun, now, clamp)
|
||||
if self.seq is not None:
|
||||
q = self.seq
|
||||
@@ -892,6 +957,10 @@ class SolarWriter(ManualWriter):
|
||||
pf = self.phase_fails
|
||||
await self._advance(drv, r, cur, now, tracker, self.amps_out(clamp)
|
||||
or CH.MIN_A, clamp, None)
|
||||
if "t1" in q and not q.get("ph_set"):
|
||||
q["ph_set"] = True # the select is out: whose phases
|
||||
self.ph_known = {q["n"]} if self.phase_fails == pf \
|
||||
else {x for x in (q.get("from"), q["n"]) if x in (1, 3)}
|
||||
if self.phase_fails > pf and q.get("from") in (1, 3):
|
||||
self.plan.n = q["from"] # the select was not taken
|
||||
if self.seq is None:
|
||||
@@ -904,13 +973,17 @@ class SolarWriter(ManualWriter):
|
||||
if self.last_switch is not None \
|
||||
and now - self.last_switch < PHASE_GAP_S:
|
||||
self.blocked = True
|
||||
# Round 9: the switch waits, a lower current does not (the
|
||||
# cut, the hold's 6 A; a pause is 0 A and never waits here).
|
||||
if not (cur is not None and cur > want + TOL_A):
|
||||
return
|
||||
else:
|
||||
self.blocked = False
|
||||
self.zero_at, self.sent_a = now, 0.0
|
||||
await self._begin(drv, r, cur, self.plan.n, now, tracker)
|
||||
if self.seq is not None:
|
||||
self.seq["from"] = r.phases_allowed
|
||||
return
|
||||
self.blocked = False
|
||||
self.zero_at, self.sent_a = now, 0.0
|
||||
await self._begin(drv, r, cur, self.plan.n, now, tracker)
|
||||
if self.seq is not None:
|
||||
self.seq["from"] = r.phases_allowed
|
||||
return
|
||||
if self.sent_a is not None and abs(self.sent_a - want) <= TOL_A \
|
||||
and self.fail_at is None:
|
||||
return # nothing new: a read-back that differs is `_watch`'s
|
||||
|
||||
Reference in New Issue
Block a user