feat: match the verified on-site poller payload
The on-site agent found that the DC (P052/P054/P05A/P05C) and energy (P063) registers are static/frozen and ac_power_total_w is now computed V*I, so the backend and dashboard have to cope with those fields being absent. - Feeding/Standby from status_code (FEEDING_STATUS_CODES, default 7 and 8: INV1's OEM board uses 7). Online but not feeding = Standby; a standby inverter while peers produce is still caught by the underperformance check. Missing error_code stays "no fault". - Daily energy falls back to AC power integrated between readings, flagged estimated (≈ in the UI); out-of-order (spooled) readings recompute the day. Existing databases get the column and a rebuild on startup. - Totals are null instead of 0 when there's no energy data; lifetime shows "not available yet". Parameters the poller doesn't send are hidden on the detail page, DC lines only drawn when DC data exists. - Timestamps more than 5 min in the future are stored at receive time and counted in clamped_future — the example payload carried local Athens time labelled +00:00. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+14
-4
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import secrets
|
||||
import sqlite3
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
@@ -10,6 +11,7 @@ from .config import get_settings
|
||||
from .db import get_db, set_meta
|
||||
from .schemas import IngestResult, Inverter, InverterUpdate, ReadingIn, Summary
|
||||
|
||||
log = logging.getLogger("solar")
|
||||
router = APIRouter(prefix="/api")
|
||||
Db = Annotated[sqlite3.Connection, Depends(get_db)]
|
||||
|
||||
@@ -69,9 +71,11 @@ def post_readings(conn: Db, readings: Annotated[list[ReadingIn], Body(max_length
|
||||
"""Send an empty array when no inverter answered — it still tells the
|
||||
backend the datalogger is alive, which is how a dead inverter is told
|
||||
apart from a dead internet link."""
|
||||
stored, duplicates = store.ingest(conn, readings)
|
||||
stored, duplicates, clamped = store.ingest(conn, readings)
|
||||
set_meta(conn, "last_ingest_at", str(store.now_ts()))
|
||||
return {"received": len(readings), "stored": stored, "duplicates": duplicates}
|
||||
if clamped:
|
||||
log.warning("%d readings had future timestamps (clock/timezone wrong on the poller?)", clamped)
|
||||
return {"received": len(readings), "stored": stored, "duplicates": duplicates, "clamped_future": clamped}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- dashboard
|
||||
@@ -181,14 +185,20 @@ def get_inverter_daily(
|
||||
end: Annotated[date | None, Query(alias="to")] = None,
|
||||
days: Annotated[int, Query(ge=1, le=3660)] = 365,
|
||||
):
|
||||
"""Energy and peak power per local day (default: last 365 days)."""
|
||||
"""Energy and peak power per local day (default: last 365 days).
|
||||
`estimated` days are integrated from AC power, not the inverter's counter."""
|
||||
_inverter_or_404(conn, inverter_id)
|
||||
first, last = _day_range(start, end, days)
|
||||
rows = store.daily_energy(conn, first, last, inverter_id)
|
||||
return {
|
||||
"inverter_id": inverter_id,
|
||||
"days": [
|
||||
{"day": r["day"], "energy_wh": r.get(inverter_id), "peak_power_w": r.get("peak_power_w")}
|
||||
{
|
||||
"day": r["day"],
|
||||
"energy_wh": r.get(inverter_id),
|
||||
"estimated": r["estimated"],
|
||||
"peak_power_w": r.get("peak_power_w"),
|
||||
}
|
||||
for r in rows
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user