EV-03: the charger reader keeps its own power-unit rule
test_pv.py part 6 says only the PV reader's named modules may mention its material, so chargers.py no longer imports pv.py. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,6 @@ from __future__ import annotations
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from . import pv
|
||||
from .hass import BAD_STATES
|
||||
from .solarfc import KWH_PER
|
||||
|
||||
@@ -152,6 +151,22 @@ def _amps(obj):
|
||||
return None
|
||||
|
||||
|
||||
_W_PER = {"mW": 0.001, "W": 1.0, "kW": 1000.0, "MW": 1000000.0}
|
||||
|
||||
|
||||
def _watts(obj):
|
||||
"""Power in W, believed only in a power unit (its own copy of the rule: the
|
||||
PV channel's reader stays out of the charger's, test_pv.py part 6)."""
|
||||
raw, unit, _ = _state_obj(obj)
|
||||
if raw is None or unit not in _W_PER:
|
||||
return None
|
||||
try:
|
||||
v = float(raw) * _W_PER[unit]
|
||||
except ValueError:
|
||||
return None
|
||||
return v if v == v else None
|
||||
|
||||
|
||||
def _kwh(obj):
|
||||
raw, unit, _ = _state_obj(obj)
|
||||
if raw is None or unit not in KWH_PER:
|
||||
@@ -208,7 +223,7 @@ def reading_from_states(states: dict) -> ChargerReading:
|
||||
letter = mode3_letter(txt("state"))
|
||||
disp = txt("display")
|
||||
cls = display_class(disp)
|
||||
power, _w = pv.watts(states.get("power")) if states.get("power") else (None, "")
|
||||
power = _watts(states.get("power"))
|
||||
currents = tuple(a for a in (_amps(states.get(k)) for k in ("l1", "l2", "l3"))
|
||||
if a is not None)
|
||||
if letter is not None:
|
||||
|
||||
Reference in New Issue
Block a user