EV-03: car charger seam, Alfen HA driver, read-only Car card
Read-only: nothing in this change writes to the charger. - app/chargers.py: ChargerDriver, AlfenHaDriver, UnavailableCharger, ChargerReading, CarTracker - options ev_charger/ev_current_entity/ev_max_a/ev_phases (default off), Settings group, validator, census - Car card on Home, unreachable row and notification, two-writer info row, MQTT sensors - car out of the House tile and the house profile - tools/chargersim.py charger model, test_ev03.py Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,9 @@ from . import freshness
|
||||
from . import lateness
|
||||
from . import messages
|
||||
from . import pv as pv_read
|
||||
from . import chargers
|
||||
from .price import brussels, price_option, provider_configured
|
||||
from .hass import OUTAGE
|
||||
from .price_chain import uses_chain
|
||||
from .static_tariff import static_status
|
||||
from .rows import tariff_plan_row
|
||||
@@ -48,6 +50,10 @@ FC_HOLD_KEY = "solar_fc_hold"
|
||||
FORECAST_READ_S = 60.0
|
||||
|
||||
|
||||
# EV-03: the car's energy today, kept so a restart does not lose it.
|
||||
CAR_TODAY_KEY = "car_today"
|
||||
|
||||
|
||||
class InputsMixin:
|
||||
def _readings_late(self, standing_w):
|
||||
"""SAFETY-128: update the answer gate; seconds the late verdict has
|
||||
@@ -102,6 +108,89 @@ class InputsMixin:
|
||||
return "input"
|
||||
|
||||
# -- io ------------------------------------------------------------------
|
||||
# -- EV-03: the car charger, READ ONLY ----------------------------------------
|
||||
@property
|
||||
def car_enabled(self) -> bool:
|
||||
"""`ev_charger` is on, whether or not the charger could be set up."""
|
||||
return chargers.mode_of(self.o) != chargers.OFF
|
||||
|
||||
def car_now(self) -> float:
|
||||
return freshness.monotonic()
|
||||
|
||||
def car_term(self) -> tuple:
|
||||
"""`(car_w, unknown)`: what the House tile and the house profile take
|
||||
out for the car. `(0.0, False)` with no charger, so a site without one
|
||||
is exactly as before. With one, a reading older than `stale_input_s`
|
||||
(the meter's own bound) is UNKNOWN, never the last figure: the tile
|
||||
shows no reading and the profile leaves that moment out."""
|
||||
if not self.charger.configured():
|
||||
return 0.0, False
|
||||
w = self.car.car_w(self.car_now())
|
||||
return (0.0, True) if w is None else (w, False)
|
||||
|
||||
async def _read_charger(self, now_mono: float) -> None:
|
||||
"""One read of the charger, and what the tracker learns from it. It
|
||||
never raises (telemetry has no foot in the control path) and it only
|
||||
reads: nothing here, or anywhere in this card, writes to the charger."""
|
||||
now_utc = datetime.now(timezone.utc)
|
||||
day = brussels(now_utc).date().isoformat()
|
||||
try:
|
||||
if not self._charger_probed:
|
||||
pr = await asyncio.wait_for(self.charger.probe(), 5.0)
|
||||
if OUTAGE.waiting():
|
||||
raise RuntimeError("Home Assistant is not answering")
|
||||
self._charger_probed = True
|
||||
self._judge_probe(pr)
|
||||
if not self.charger.configured():
|
||||
return
|
||||
reading = await asyncio.wait_for(self.charger.read(), 5.0)
|
||||
except Exception as err: # noqa: BLE001
|
||||
_LOG.debug("The charger could not be read: %s", err)
|
||||
reading = chargers.ChargerReading(why="no answer")
|
||||
self.car.observe(reading, now_mono, now_utc, day)
|
||||
if self.car.persist:
|
||||
self.car.persist = False
|
||||
self.store.set(CAR_TODAY_KEY, self.car.dump())
|
||||
|
||||
def _judge_probe(self, pr) -> None:
|
||||
"""A charger whose setpoint, read-back or state entity is missing, or
|
||||
whose limit is above the station limit, is REFUSED: the add-on starts
|
||||
and the Car card says so. Said once."""
|
||||
why = None
|
||||
if not pr.ok:
|
||||
why = "not_found"
|
||||
_LOG.warning("The car charger is not set up, because Home "
|
||||
"Assistant has no entity it needs: CHARGER_NOT_FOUND.")
|
||||
_LOG.debug("Charger entities missing: %s.",
|
||||
", ".join(e for _r, e in pr.missing) or "the name")
|
||||
else:
|
||||
amps = chargers.max_a(self.o)
|
||||
if pr.station_a is not None and amps is not None \
|
||||
and amps > pr.station_a:
|
||||
why = "limit"
|
||||
_LOG.warning("The charger limit is above what the charger "
|
||||
"allows, so the charger is not used: "
|
||||
"CHARGER_LIMIT.")
|
||||
_LOG.debug("ev_max_a %.0f A, station limit %.0f A.", amps,
|
||||
pr.station_a)
|
||||
if why is not None:
|
||||
self.charger_refused = why
|
||||
self.charger = chargers.UnavailableCharger(why, chargers.ALFEN_HA)
|
||||
|
||||
def car_log_edges(self, now_mono: float) -> None:
|
||||
"""One WARNING when the charger goes unreachable, one INFO when it is
|
||||
back. Edge-logged, never every cycle."""
|
||||
down = self.car.unreachable(now_mono)
|
||||
if down and not self._car_down_logged:
|
||||
self._car_down_logged = True
|
||||
_LOG.warning("The car charger does not answer, so the Car card has "
|
||||
"no reading: CHARGER_UNREACHABLE.")
|
||||
_LOG.debug("The charger entities read unavailable, or its login "
|
||||
"is off, for %.0f s.", chargers.UNREACHABLE_S)
|
||||
elif not down and self._car_down_logged and self.car.bad_since is None:
|
||||
self._car_down_logged = False
|
||||
_LOG.info("The car charger answers again.")
|
||||
|
||||
@property
|
||||
def pv_roster(self) -> tuple:
|
||||
"""Every configured PV production entity, or `()` (TEL-11/TEL-12). ONE
|
||||
@@ -209,6 +298,10 @@ class InputsMixin:
|
||||
_reads = [self._read_unit(inv, now_mono) for inv in self.inverters]
|
||||
if self.pv_roster:
|
||||
_reads.append(self._read_pv())
|
||||
# EV-03: the charger, read only, in the same gather. Nothing is added
|
||||
# without a charger, so a site with none runs exactly as before.
|
||||
if self.charger.configured():
|
||||
_reads.append(self._read_charger(now_mono))
|
||||
# OPT-11 P4: the solar forecast, in the same gather (a slow sensor must
|
||||
# not delay control), at most once per FORECAST_READ_S.
|
||||
if self.fc_entity is not None and (
|
||||
|
||||
Reference in New Issue
Block a user