From c24770af1ce414f25758e4a39e96634af9056c52 Mon Sep 17 00:00:00 2001 From: bonamin Date: Thu, 22 Oct 2026 18:15:38 +0300 Subject: [PATCH] feat(poller): simulate the five-inverter contract The fake poller now matches the 2026-10-22 data contract: INV1/INV3 send no currents/DC/energy, INV2/INV4 add currents and MPPT1 voltage, INV5 reports via the cloud every 5 min with real daily/lifetime counters and keeps sending 0 W / Standby at night while the others go silent. Status codes are the normalized 8/1. Lets the dashboard be tried against the real mix of missing fields and cadences. Co-Authored-By: Claude Opus 5.5 --- poller/fake_poller.py | 66 +++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/poller/fake_poller.py b/poller/fake_poller.py index 8bdf725..8dddc4f 100644 --- a/poller/fake_poller.py +++ b/poller/fake_poller.py @@ -2,11 +2,15 @@ python fake_poller.py --url http://localhost:8090 --key change-me --backfill-days 30 -Sends what the real poller sends today (AC side, temperature, status code, -unmapped diagnostics; no DC or energy counters). --backfill-days first loads -that many days of history (one reading per 5 minutes), then it posts live -readings every --interval seconds. INV4 runs at half output (as if a string -fuse had blown) so the warnings show up. +Follows the poller data contract of 2026-10-22: five units, three sources. +INV1/INV3 (OEM board) send AC voltages, power, frequency, temperature and +status; INV2/INV4 (SunSpec) add phase currents and MPPT1 voltage; INV5 +(SolarmanPV cloud) adds the real daily/lifetime energy counters, reports +only every 5 min and keeps reporting 0 W / Standby at night while the +others go silent. --backfill-days first loads that many days of history +(one reading per 5 minutes), then it posts live readings every --interval +seconds. INV4 runs at half output (as if a string fuse had blown) so the +warnings show up. """ import argparse @@ -17,8 +21,13 @@ from datetime import datetime, timedelta, timezone from backend_client import BackendClient -INVERTERS = ["INV1", "INV2", "INV4"] +INVERTERS = ["INV1", "INV2", "INV3", "INV4", "INV5"] PEAK_W = 18_000 +CLOUD_EVERY_S = 300 # INV5's cadence +INV5_LIFETIME_START_WH = 41_250_000 + +# INV5's daily counter, accumulated by the simulator +_inv5 = {"day": None, "daily_wh": 0.0, "total_wh": float(INV5_LIFETIME_START_WH), "last": None} def sun_factor(t: datetime) -> float: @@ -30,31 +39,44 @@ def sun_factor(t: datetime) -> float: def reading(inv: str, t: datetime) -> dict | None: f = sun_factor(t) * random.uniform(0.93, 1.0) - if f <= 0.01: - return None # inverter asleep at night, doesn't answer + if inv == "INV5": + if int(t.timestamp()) % CLOUD_EVERY_S >= 60: + return None # cloud value only refreshes every 5 min + elif f <= 0.01: + return None # local units power down at night and don't answer feeding = f > 0.03 w = int(PEAK_W * f * (0.5 if inv == "INV4" else 1.0)) if feeding else 0 - volts = [round(random.uniform(229, 236), 2) for _ in range(3)] - amps = [round(w / 3 / v, 2) for v in volts] - return { + volts = [round(random.uniform(236, 244), 1) for _ in range(3)] + r = { "inverter_id": inv, "timestamp": t.isoformat(timespec="seconds"), "ac_voltage_l1_v": volts[0], "ac_voltage_l2_v": volts[1], "ac_voltage_l3_v": volts[2], - "ac_current_l1_a": amps[0], - "ac_current_l2_a": amps[1], - "ac_current_l3_a": amps[2], "ac_power_total_w": w, "grid_frequency_hz": round(random.uniform(49.95, 50.05), 2), "temperature_c": int(30 + 25 * f), - "status_code": (7 if inv == "INV1" else 8) if feeding else 3, - "status_text": "feeding" if feeding else "standby/not feeding", - "p06d_raw_latched": 21450, - "p052_static_v": 312.5, - "p05a_static_a": 45.0, - "p063_ind0_raw": 1872, + "status_code": 8 if feeding else 1, + "status_text": ("MPP" if feeding else "Standby") if inv != "INV5" else ("Generating" if feeding else "Standby"), } + if inv in ("INV1", "INV3"): + r["raw_status_oem"] = 7 if feeding else 3 + return r + r.update({f"ac_current_l{i + 1}_a": round(w / 3 / v, 2) for i, v in enumerate(volts)}) + r["dc_voltage_mppt1_v"] = round(random.uniform(560, 640), 1) if feeding else 0.0 + if inv in ("INV2", "INV4"): + r["raw_status_sunspec"] = 4 if feeding else 2 + return r + day = (t + timedelta(hours=3)).date() + if _inv5["day"] != day: + _inv5.update(day=day, daily_wh=0.0) + if _inv5["last"] is not None: + wh = w * (t - _inv5["last"]).total_seconds() / 3600 + _inv5["daily_wh"] += wh + _inv5["total_wh"] += wh + _inv5["last"] = t + r.update(daily_energy_wh=int(_inv5["daily_wh"]), total_energy_wh=int(_inv5["total_wh"]), raw_status_cloud=1 if feeding else 0) + return r def main() -> None: @@ -67,7 +89,9 @@ def main() -> None: client = BackendClient(args.url, args.key, spool_path="fake_unsent.jsonl") if args.backfill_days: - t = datetime.now(timezone.utc) - timedelta(days=args.backfill_days) + now = int(time.time()) + # On the 5-min grid, so INV5's cloud readings land in the backfill too + t = datetime.fromtimestamp(now - now % CLOUD_EVERY_S - args.backfill_days * 86400, timezone.utc) batch: list[dict] = [] while t < datetime.now(timezone.utc): batch += [r for inv in INVERTERS if (r := reading(inv, t))]