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:
2026-10-21 09:43:55 +03:00
co-authored by Claude Opus 5.5
parent 0b0e4b7d6d
commit d01cef991f
15 changed files with 401 additions and 82 deletions
+11 -1
View File
@@ -37,6 +37,9 @@ CREATE TABLE IF NOT EXISTS daily_energy (
total_min_wh INTEGER,
total_max_wh INTEGER,
peak_power_w INTEGER,
-- AC power integrated over time: the fallback while the inverter's
-- own energy counters aren't decoded
integrated_wh REAL,
PRIMARY KEY (inverter_id, day)
) WITHOUT ROWID;
@@ -72,13 +75,20 @@ def get_db() -> Iterator[sqlite3.Connection]:
yield conn
def migrate() -> None:
def migrate() -> bool:
"""Create/upgrade the schema. Returns True when the integrated-energy
column was just added and has to be rebuilt from existing readings."""
with session() as conn:
conn.executescript(SCHEMA)
existing = {r["name"] for r in conn.execute("PRAGMA table_info(readings)")}
for f in FIELDS:
if f.key not in existing:
conn.execute(f"ALTER TABLE readings ADD COLUMN {f.key} {f.sql_type}")
daily_cols = {r["name"] for r in conn.execute("PRAGMA table_info(daily_energy)")}
if "integrated_wh" not in daily_cols:
conn.execute("ALTER TABLE daily_energy ADD COLUMN integrated_wh REAL")
return True
return False
def get_meta(conn: sqlite3.Connection, key: str) -> str | None: