feat: unit-aware power sensors + ceil() for max solar self-consumption
test / test (push) Has been cancelled
test / test (push) Has been cancelled
Two related fixes for v0.1.3: 1. _read_power_w() reads each power sensor's unit_of_measurement and converts kW to W. Before this, sensors reporting in kW (Tesla integration's leomobile_charger_power = "1" kW) were treated as raw watts, causing the leftover calculation to undercount by ~1000×. In practice the algorithm sent the EV charge rate that matched "what's exporting NOW" instead of "what's available if EV pulled everything" — leaving ~1 kW of solar exported instead of routed to the car. 2. round() → math.ceil() on the amp computation. Trade-off: up to ~VOLTAGE watts of grid import per tick, in exchange for zero solar export. Maximizes PV self-consumption, accepts small grid cost as rounding noise. Tests added: kW conversion round-trip; ceil rounds up partial amps. All 57 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d73b4ec7a3
commit
7d0be3c70c
@@ -346,6 +346,24 @@ def test_solar_clamps_to_max_amps(base_snapshot: Snapshot) -> None:
|
||||
assert d.desired_amps == 14
|
||||
|
||||
|
||||
def test_solar_ceil_rounds_up_partial_amp(base_snapshot: Snapshot) -> None:
|
||||
"""Partial-amp surplus must round UP (ceil), not nearest, so solar is fully absorbed.
|
||||
|
||||
leftover = 1151 W → 5.004 A. round() would give 5; we want 6, even though it
|
||||
pulls ~229 W from grid on this tick. The trade-off: zero solar export, in
|
||||
exchange for at most ~VOLTAGE watts of grid import per tick.
|
||||
"""
|
||||
s = dataclasses.replace(
|
||||
base_snapshot,
|
||||
net_grid_w=-1151.0,
|
||||
ev_consumption_w=0.0,
|
||||
ev_soc=60.0,
|
||||
target_day_soc=80.0,
|
||||
)
|
||||
d = compute_decision(s)
|
||||
assert d.desired_amps == 6, "expected ceil(5.004) = 6, got round behavior"
|
||||
|
||||
|
||||
def test_negative_ev_consumption_treated_as_zero(base_snapshot: Snapshot) -> None:
|
||||
"""Negative EV consumption (bad sensor) should be ignored, not amplify leftover."""
|
||||
s = dataclasses.replace(
|
||||
|
||||
Reference in New Issue
Block a user