EV-20: Car Solar mode, spare sun to the car (charging only)
Solar as a second writer next to Manual (carmode.SolarPlan, SolarWriter on ManualWriter's one write site, safe phase sequence and other-writer watch): signed spare, Batteries first on the batteries' ratings, the margin, whole amps rounded down, the 30 s / 1 A rule, start and pause dwells, auto phases, a one-phase car. Every way out ends at 0 A, retried by EV-04's rule; at shutdown before the inverters, three tries inside 15 s (D3); start-up and a returning charger or HA write 0 A first (D2); never over another writer's hold. The peak guard treats a Solar car as a Manual car (D1 wording). Solar kWh sensor and card line; select.goodwe_car_sun_first; ev_margin_w, ev_start_min, ev_pause_min with config, validator, translations, DOCS, DECISIONS and CHANGELOG. Checks: test_ev20.py, test_ev20_exits.py, test_ev20_writers.py, test_ev20_guard.py, test_ev20_long.py, test_ev20_long_car.py, test_ev20_fuzz.py (harness tools/ev20_sun.py, ev20_kit.py, ev20_day.py); test_ev03/test_ev04 no longer use Solar as the refused example. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
@@ -144,6 +144,8 @@ OPTIONAL_SENSORS = [
|
||||
("car_power", "goodwe_car_power", "Car power", "W", "power", "measurement", "mdi:car-electric"),
|
||||
("car_state", "goodwe_car_state", "Car state", None, None, None, "mdi:ev-station"),
|
||||
("car_today_kwh", "goodwe_car_today_kwh", "Car energy today", "kWh", "energy", "total_increasing", "mdi:ev-station"),
|
||||
# EV-20: what of today's charge came from the sun (Solar mode only).
|
||||
("car_today_solar_kwh", "goodwe_car_today_solar_kwh", "Car solar energy today", "kWh", "energy", "total_increasing", "mdi:solar-power"),
|
||||
]
|
||||
|
||||
# ⚠️ HA's OWN "this sensor has no value" PAYLOAD, and the one place this add-on
|
||||
@@ -200,7 +202,8 @@ def optional_keys(opts: dict) -> tuple:
|
||||
from . import chargers as _ch # EV-03: same reason
|
||||
out = ("pv",) if _pv.entities(opts) else ()
|
||||
if _ch.census_entity(opts):
|
||||
out += ("car_power", "car_state", "car_today_kwh")
|
||||
out += ("car_power", "car_state", "car_today_kwh",
|
||||
"car_today_solar_kwh")
|
||||
return out
|
||||
|
||||
|
||||
@@ -524,25 +527,32 @@ def mode_payloads(units, modes) -> list:
|
||||
# --- EV-04: the car's mode, current and phases, as HA entities ----------------
|
||||
# Announced only with a charger switched on, after every other row. A command
|
||||
# goes through Controller.handle_action(); a retained one is dropped.
|
||||
CAR_MODE_LABELS = {"off": "Off", "manual": "Manual"} # English, pinned
|
||||
CAR_MODE_LABELS = {"off": "Off", "manual": "Manual", # English, pinned
|
||||
"solar": "Solar"} # EV-20
|
||||
# EV-20: where spare sun goes first; mirrors carmode.FIRST_LABELS (this module
|
||||
# imports nothing from the package; test_ev20.py checks the two agree).
|
||||
CAR_FIRST_LABELS = {"batteries": "Batteries", "car": "Car"}
|
||||
CAR_MODES = tuple(CAR_MODE_LABELS)
|
||||
CAR_CONFIGS_KEY = "mqtt_car_configs"
|
||||
CAR_MIN_A = 6
|
||||
_CAR_CMD_RE = re.compile(rf"{BASE}/car/(mode|current|phases)/set")
|
||||
_CAR_CMD_RE = re.compile(rf"{BASE}/car/(mode|current|phases|sun_first)/set")
|
||||
_CAR_CONFIG_RE = re.compile(
|
||||
rf"homeassistant/(select|number)/{BASE}_car_(mode|current|phases)/config")
|
||||
rf"homeassistant/(select|number)/{BASE}_car_(mode|current|phases|sun_first)"
|
||||
rf"/config")
|
||||
# (key, component, name, icon)
|
||||
CAR_ENTITIES = [
|
||||
("mode", "select", "Car mode", "mdi:car-electric"),
|
||||
("current", "number", "Car current", "mdi:current-ac"),
|
||||
("phases", "select", "Car phases", "mdi:sine-wave"),
|
||||
("sun_first", "select", "Car spare sun first", "mdi:solar-power"), # EV-20
|
||||
]
|
||||
|
||||
|
||||
def car_payloads(car) -> list:
|
||||
"""The `(topic, payload)` for `select.goodwe_car_mode`,
|
||||
`number.goodwe_car_current` and `select.goodwe_car_phases`. `car` is
|
||||
`(max_a, phases)`; empty when it is None."""
|
||||
`number.goodwe_car_current`, `select.goodwe_car_phases` and (EV-20)
|
||||
`select.goodwe_car_sun_first`. `car` is `(max_a, phases)`; empty when it
|
||||
is None."""
|
||||
if not car:
|
||||
return []
|
||||
max_a, phases = car
|
||||
@@ -560,6 +570,8 @@ def car_payloads(car) -> list:
|
||||
cfg["options"] = list(CAR_MODE_LABELS.values())
|
||||
elif key == "phases":
|
||||
cfg["options"] = [str(n) for n in phases]
|
||||
elif key == "sun_first":
|
||||
cfg["options"] = list(CAR_FIRST_LABELS.values())
|
||||
else:
|
||||
cfg.update({"min": CAR_MIN_A, "max": int(max_a), "step": 1,
|
||||
"unit_of_measurement": "A", "device_class": "current",
|
||||
@@ -584,7 +596,8 @@ def car_configs(car, stored) -> tuple:
|
||||
|
||||
def parse_car_command(topic, payload, retained):
|
||||
"""`(action, value, reject)` for one message on a car command topic.
|
||||
`action` is `car_mode`, `car_current` or `car_phases`. A value that is
|
||||
`action` is `car_mode`, `car_current`, `car_phases` or (EV-20)
|
||||
`car_sun_first`. A value that is
|
||||
none of the entity's own is None (the action then refuses it)."""
|
||||
m = _CAR_CMD_RE.fullmatch(topic) if isinstance(topic, str) else None
|
||||
if m is None:
|
||||
@@ -607,6 +620,9 @@ def parse_car_command(topic, payload, retained):
|
||||
None)
|
||||
elif key == "phases":
|
||||
value = {"1": 1, "3": 3}.get(text)
|
||||
elif key == "sun_first":
|
||||
value = next((k for k, v in CAR_FIRST_LABELS.items() if v == text),
|
||||
None)
|
||||
else:
|
||||
try:
|
||||
f = float(text)
|
||||
|
||||
Reference in New Issue
Block a user