EV-21 fix round 2 (review): a cut during Solar's own phase change ends it; wait cap in watts
PM R1: a cut due while Solar's own phase change is under way (seq set or plan.switch) is 0 A at once and ends the change at its 0 A; the 15 s wait cap is held in watts and converted with the phases at the write. test_ev21_fix2.py: T34 (iv) red at 5759e9d, T34 (v) 3->1, N6/P27 refused close red with seq_uncapped, N9 standing cap red with stale_drop. test_ev21_fix1.py: C18 now R1; C16 and Q1 accepted as coded (R5).
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import asyncio
|
||||
import copy
|
||||
import dataclasses
|
||||
import logging
|
||||
import math
|
||||
from datetime import timezone
|
||||
|
||||
from . import carmode, chargers, messages, packshare, peakguard
|
||||
@@ -299,7 +300,8 @@ class CarMixin:
|
||||
if key is None or target_w is None or blind \
|
||||
or not self._car_cut_meter_fresh():
|
||||
# N9: nothing sized from a stale projection; what stands stays.
|
||||
w.cut_a = st["cap"] if st["cap"] is not None else st["wait"]
|
||||
w.cut_a = st["cap"] if st["cap"] is not None \
|
||||
else self._car_wait_a(st)
|
||||
return
|
||||
ex = peakguard.excess_w(real_proj, target_w)
|
||||
left = QUARTER_S - float(real_proj.elapsed_s)
|
||||
@@ -319,9 +321,15 @@ class CarMixin:
|
||||
# charge only counts as headroom for the 15 s wait.
|
||||
due = ex > 0.0 and running and (drawing or seq_on)
|
||||
n = self._car_cut_n()
|
||||
# PM R1 (review r1): a cut due while Solar's own phase change is
|
||||
# under way (its 0 A sent, or the plan decided it) ends the change at
|
||||
# its 0 A, at once: never sized on phases the read-back may not show.
|
||||
change_on = w.seq is not None or w.plan.switch
|
||||
if st["cap"] is not None:
|
||||
# A cut stands: deeper only if the excess grows (OQ7); the
|
||||
# restart rule lifts it.
|
||||
if due and change_on and st["cap"] > 0.0:
|
||||
st["cap"] = 0.0
|
||||
if due and ex > st["ex"]:
|
||||
st["ex"] = ex
|
||||
a = carmode.cut_amps(st["car0"], ex, n, st["base"])
|
||||
@@ -355,17 +363,30 @@ class CarMixin:
|
||||
room = self._car_cut_headroom(guard)
|
||||
now_ = (room is None or room <= 0.0 or ex > room
|
||||
or not self.car_cover or left <= CUT_NEAR_END_S)
|
||||
if now_ or mono - st["since"] >= CUT_WAIT_S:
|
||||
a = carmode.cut_amps(st["car0"], st["ex"], n, st["base"])
|
||||
if now_ or change_on or mono - st["since"] >= CUT_WAIT_S:
|
||||
a = 0.0 if change_on else carmode.cut_amps(
|
||||
st["car0"], st["ex"], n, st["base"])
|
||||
st["cap"] = 0.0 if a is None else a
|
||||
st["cuts"] += 1
|
||||
st["wait"], st["at"] = None, mono
|
||||
w.cut_a = st["cap"]
|
||||
return
|
||||
# C4: due and waiting: no raise meanwhile.
|
||||
st["wait"] = w.plan.a if st["wait"] is None \
|
||||
else min(st["wait"], w.plan.a)
|
||||
w.cut_a = st["wait"]
|
||||
# C4: due and waiting: no raise meanwhile. PM R1: held in watts (the
|
||||
# plan's current on its phases), turned into amps with the phases at
|
||||
# the write.
|
||||
p = w.plan
|
||||
now_w = float(p.a) * carmode.VOLTS * (p.n if p.n in (1, 3) else n)
|
||||
st["wait"] = now_w if st["wait"] is None else min(st["wait"], now_w)
|
||||
w.cut_a = self._car_wait_a(st)
|
||||
|
||||
def _car_wait_a(self, st):
|
||||
"""PM R1: the 15 s wait's cap, held in watts, as amps on the phases
|
||||
Solar writes on now (the plan's), rounded down. None: no wait."""
|
||||
if st["wait"] is None:
|
||||
return None
|
||||
n = self.car_solar.plan.n
|
||||
n = n if n in (1, 3) else self._car_cut_n()
|
||||
return float(math.floor(st["wait"] / (carmode.VOLTS * n) + 1e-9))
|
||||
|
||||
@property
|
||||
def car_cover(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user