EV-03 round 3: the power entity is required and reads in W or kW
A charger with no usable power entity is refused as "not set up", like a missing setpoint, read-back or state entity, so House and the house profile behave as with no charger. An entity that is merely unavailable at probe time is still the unreachable path. NL: help text "met rust", chip "Laadpaalstoring". Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -79,11 +79,15 @@ ROLES = {
|
||||
"error": ("sensor", "display_error_number_socket_1"),
|
||||
"login": ("binary_sensor", "https_api_login_status"),
|
||||
}
|
||||
#: a missing one of these refuses the charger (not the add-on)
|
||||
REQUIRED = ("current", "readback", "state")
|
||||
#: a missing one of these refuses the charger (not the add-on). `power` is one
|
||||
#: of them: without it the car's power is unknown for good, House would show no
|
||||
#: reading for ever and the house profile would drop every sample.
|
||||
#: The power entity must also read in W or kW (`POWER_UNITS`).
|
||||
REQUIRED = ("current", "readback", "state", "power")
|
||||
_SETPOINT_RE = re.compile(r"^number\.(?P<x>.+)_" + SETPOINT_SUFFIX + "$")
|
||||
|
||||
_ROLE_ORDER = tuple(ROLES)
|
||||
POWER_UNITS = ("W", "kW")
|
||||
|
||||
|
||||
def census_key(entity) -> str:
|
||||
@@ -151,7 +155,7 @@ def _amps(obj):
|
||||
return None
|
||||
|
||||
|
||||
_W_PER = {"mW": 0.001, "W": 1.0, "kW": 1000.0, "MW": 1000000.0}
|
||||
_W_PER = {"W": 1.0, "kW": 1000.0}
|
||||
|
||||
|
||||
def _watts(obj):
|
||||
@@ -258,6 +262,9 @@ class ChargerProbe:
|
||||
missing: tuple = ()
|
||||
station_a: float | None = None
|
||||
derived: bool = True # False: the setpoint's name does not fit
|
||||
power_unit: str | None = None # the power entity's unit, when it is
|
||||
# reading a number and that unit is not W or kW (an unavailable entity
|
||||
# has no unit to judge: that is the unreachable path, not a refusal)
|
||||
|
||||
@property
|
||||
def required_missing(self) -> tuple:
|
||||
@@ -265,7 +272,8 @@ class ChargerProbe:
|
||||
|
||||
@property
|
||||
def ok(self) -> bool:
|
||||
return self.derived and not self.required_missing
|
||||
return (self.derived and not self.required_missing
|
||||
and self.power_unit is None)
|
||||
|
||||
|
||||
def probe_from(setpoint, exists) -> ChargerProbe:
|
||||
@@ -278,9 +286,18 @@ def probe_from(setpoint, exists) -> ChargerProbe:
|
||||
(found if exists(ents[role]) is not None else missing).append(
|
||||
(role, ents[role]))
|
||||
st = {r: exists(e) for r, e in ents.items()}
|
||||
raw, unit, _ = _state_obj(st.get("power"))
|
||||
bad_unit = None
|
||||
if raw is not None and unit not in POWER_UNITS:
|
||||
try:
|
||||
float(raw)
|
||||
bad_unit = unit or "none"
|
||||
except ValueError:
|
||||
pass
|
||||
return ChargerProbe(str(setpoint), tuple(found), tuple(missing),
|
||||
station_a=_first(_amps(st.get("station_active")),
|
||||
_amps(st.get("station"))))
|
||||
_amps(st.get("station"))),
|
||||
power_unit=bad_unit)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user