mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(measurement): use quality-aware meter energy for load and PV
Additional fixes Measurement.meter_energy_kwh converts meter energy over the whole period in one read; the 31-day and 10000-interval limits apply to the public energy queries only. Load intervals a meter does not fully cover are NaN and the load adjustment skips them; load_total_kwh returns an empty array for an empty store and keeps full last intervals. The load adjustment compares over the period the load meters report, skips a stale load meter period and says when no load meter is configured. PV calibration, snow feedback and the load adjustment fall back without measurements when a conversion fails, logged as error once per failure streak and consumer. Measurement.keys_first_datetime and keys_last_datetime find each meter's first and last valid reading in bounded scans, keep each meter's newest reading and return stamps in the configured zone. Measurement.keys_common_period derives the common meter period for PV calibration and the load adjustment and names the meter that ends it, also when meters share no period. PV calibration warns once per stale period when a stopped PV meter holds it on old data; snow feedback warns once about a stale feedback meter. Lasting meter conditions (silent, reset, gap, replaced meter, no shared period) are warned once per condition and consumer through one helper and warned again when they recur. A replaced meter whose readings touch the new one is reported; a single reading is not; a meter group waiting for its second reading is an info once. The PV meter resolution is detected from valid readings only (pre-existing), using one shared valid-reading rule in energy.py. Stale meter stamps are compared with compare_datetimes; new meter tests create durations with datetimeutil. The unused legacy Measurement._energy_from_meter_readings is removed; its test scenarios cover meter_energy_kwh. The converter's range error no longer mentions the API's 31-day limit, and its duplicate interval check is gone. Measurement and prediction docs describe the meter coverage rule, even gap spreading and when the load forecast stays unadjusted. Tests reset the warn-once state of the shared measurement store and restore the EMS start they change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2bfb6eafab
commit
f441759dfa
@@ -390,9 +390,39 @@ async def test_stale_meter_readings_are_reported(snow_instance, caplog):
|
||||
await feed_meter("stale", fixture, local("2026-02-20 09:00"))
|
||||
get_ems().set_start_datetime(local("2026-02-20 15:00"))
|
||||
|
||||
await snow_instance._forecast_frame(fixture["openmeteo"])
|
||||
def stale_levels() -> set[str]:
|
||||
return {
|
||||
record.levelname for record in caplog.records if "older than 3 h" in record.getMessage()
|
||||
}
|
||||
|
||||
assert "older than 3 h" in caplog.text
|
||||
with caplog.at_level("DEBUG"):
|
||||
await snow_instance._forecast_frame(fixture["openmeteo"])
|
||||
assert stale_levels() == {"WARNING"}
|
||||
caplog.clear()
|
||||
# Reported once per stale reading, not on every forecast run.
|
||||
await snow_instance._forecast_frame(fixture["openmeteo"])
|
||||
assert stale_levels() == {"DEBUG"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_missing_meter_period_is_warned_once(snow_instance, caplog):
|
||||
"""Without a PV meter period only the meter lookup warns, once, not snow feedback."""
|
||||
fixture = load_fixture()
|
||||
get_measurement()._reported_warnings.clear()
|
||||
snow_instance.config.measurement.pv_production_emr_keys = ["silent"]
|
||||
get_ems().set_start_datetime(local("2026-02-20 15:00"))
|
||||
|
||||
def warnings() -> set[str]:
|
||||
return {r.getMessage() for r in caplog.records if r.levelname == "WARNING"}
|
||||
|
||||
with caplog.at_level("DEBUG"):
|
||||
await snow_instance._forecast_frame(fixture["openmeteo"])
|
||||
(message,) = warnings()
|
||||
assert "'silent'" in message and "no valid readings" in message
|
||||
caplog.clear()
|
||||
# The lasting condition is not warned about again on the next forecast run.
|
||||
await snow_instance._forecast_frame(fixture["openmeteo"])
|
||||
assert warnings() == set()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- calibration
|
||||
|
||||
Reference in New Issue
Block a user