mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-12-02 18:36:28 +01:00
fix(devices): use the nearest valid measurement of a key
DataSequence.key_to_value took the record nearest in time and returned the key from it, even when that record did not hold the key. Feeders write measurement keys one at a time, seconds apart, and every write creates its own record. A battery temperature written at 10:00:00 and a SoC written at 10:00:01 then gave no temperature for a lookup at 10:01, so battery temperature, SoC factor, charge/discharge power and the inverter temperature fell back to the reference operating point (25 degC, SoC 0.5, 45 degC). Profiles with a temperature or SoC dependent charge limit were evaluated there, e.g. with too high a charge power for a cold battery. key_to_value now returns the nearest value of the key itself: records where the key is None or NaN are skipped, as dropna does for the other key accessors. The search window and its bounds are unchanged; without a window only an exact match counts. Additional changes Developer docs describe key_to_value as the nearest valid value of a key Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
12527597b1
commit
b2c5820925
@@ -1487,6 +1487,22 @@ class TestMeasurementAccess:
|
||||
assert point.charge_power_w == pytest.approx(2500.0)
|
||||
assert point.discharge_power_w is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_keys_written_seconds_apart_are_all_read(self) -> None:
|
||||
"""Every key is read, even when a newer record only holds another key."""
|
||||
from akkudoktoreos.core.coreabc import get_measurement
|
||||
from akkudoktoreos.utils.datetimeutil import to_datetime
|
||||
|
||||
now = to_datetime()
|
||||
measurement = get_measurement()
|
||||
await measurement.update_value(
|
||||
now.subtract(seconds=60), {"battery1-temperature-degc": 3.0}
|
||||
)
|
||||
await measurement.update_value(now.subtract(seconds=59), {"battery1-soc-factor": 0.35})
|
||||
point = await make_settings().measure_operating_point(now)
|
||||
assert point.temperature_degC == pytest.approx(3.0)
|
||||
assert point.soc_factor == pytest.approx(0.35)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_empty_store_yields_reference_point(self):
|
||||
point = await make_settings().measure_operating_point()
|
||||
|
||||
Reference in New Issue
Block a user