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
+9
View File
@@ -189,3 +189,12 @@ export function DayBars({ days, series, format, axisFormat, height = 220 }) {
</div>
)
}
export function EnergyFootnote({ estimated }) {
return (
<div className="mt-1 flex justify-between gap-3 text-[11px] text-muted">
<span>{estimated && '≈ Estimated from AC power readings until the energy counters are decoded'}</span>
<span className="shrink-0">axis in kWh</span>
</div>
)
}
+4 -2
View File
@@ -2,6 +2,7 @@ import Icon from './Icon'
export const STATES = {
ok: { label: 'Operating', icon: 'check', tone: 'good' },
standby: { label: 'Standby', icon: 'pause', tone: 'neutral' },
warning: { label: 'Check needed', icon: 'alert', tone: 'warning' },
fault: { label: 'Fault', icon: 'fault', tone: 'critical' },
offline: { label: 'Offline', icon: 'offline', tone: 'critical' },
@@ -20,8 +21,9 @@ const SEVERITY_TONE = { critical: 'critical', warning: 'warning', info: 'neutral
const SEVERITY_ICON = { critical: 'fault', warning: 'alert', info: 'unknown' }
/** Health state pill: always icon + label, never color alone. */
export function StatePill({ state, size = 'md' }) {
const s = STATES[state] ?? STATES.unknown
export function StatePill({ state, feeding, size = 'md' }) {
let s = STATES[state] ?? STATES.unknown
if (state === 'ok' && feeding) s = { ...s, label: 'Feeding' }
const sz = size === 'lg' ? 'text-sm px-3 py-1.5 gap-1.5' : 'text-xs px-2 py-1 gap-1'
return (
<span className={`inline-flex items-center rounded-full font-semibold ${sz} ${TONE[s.tone]}`}>
+6
View File
@@ -18,6 +18,12 @@ const PATHS = {
<path d="m2 2 20 20" />
</>
),
pause: (
<>
<circle cx="12" cy="12" r="10" />
<path d="M10 15V9M14 15V9" />
</>
),
moon: <path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />,
unknown: (
<>
+19 -12
View File
@@ -4,26 +4,28 @@ import { ago, energyParts, num, powerParts } from '../lib/format'
import { IssueList, OnlineDot, StatePill } from './Health'
import Icon from './Icon'
function Stat({ label, value, unit }) {
function Stat({ label, value, unit, unavailable }) {
return (
<div className="min-w-0">
<div className="text-[11px] uppercase tracking-wide text-muted">{label}</div>
<div className="truncate tnum">
<span className="font-semibold">{value}</span>
{unit && <span className="ml-0.5 text-xs text-ink-2">{unit}</span>}
</div>
{unavailable ? (
<div className="text-xs leading-5 text-muted">not available yet</div>
) : (
<div className="truncate tnum">
<span className="font-semibold">{value}</span>
{unit && <span className="ml-0.5 text-xs text-ink-2">{unit}</span>}
</div>
)}
</div>
)
}
export default function InverterCard({ status, ids }) {
const { inverter, health, latest } = status
const { inverter, health, latest, energy_today: energyToday } = status
const r = latest ?? {}
const live = health.online
const [pw, pu] = powerParts(live ? r.ac_power_total_w : null)
// The daily counter only counts if the last reading is from today
const fromToday = r.timestamp && new Date(r.timestamp).toDateString() === new Date().toDateString()
const [today, todayU] = energyParts(fromToday ? r.daily_energy_wh : null)
const [today, todayU] = energyParts(energyToday.wh)
const [life, lifeU] = energyParts(r.total_energy_wh)
const volts = [r.ac_voltage_l1_v, r.ac_voltage_l2_v, r.ac_voltage_l3_v]
@@ -47,7 +49,7 @@ export default function InverterCard({ status, ids }) {
<span className="text-xs text-muted">· {ago(r.timestamp)}</span>
</div>
</div>
<StatePill state={health.state} />
<StatePill state={health.state} feeding={health.feeding} />
</div>
<div className="flex items-baseline gap-1 tnum">
@@ -61,8 +63,13 @@ export default function InverterCard({ status, ids }) {
</div>
<div className="grid grid-cols-3 gap-3 text-sm">
<Stat label="Today" value={today} unit={todayU} />
<Stat label="Lifetime" value={life} unit={lifeU} />
<Stat
label={energyToday.estimated ? 'Today ≈' : 'Today'}
value={today}
unit={todayU}
unavailable={energyToday.wh == null && live}
/>
<Stat label="Lifetime" value={life} unit={lifeU} unavailable={r.total_energy_wh == null} />
<Stat label="Temp" value={live ? num(r.temperature_c) : '—'} unit="°C" />
</div>
+24 -11
View File
@@ -1,6 +1,6 @@
import { useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { DayBars, Legend, TimeLines } from '../components/Charts'
import { DayBars, EnergyFootnote, Legend, TimeLines } from '../components/Charts'
import Comparison from '../components/Comparison'
import { IssueList } from '../components/Health'
import Icon from '../components/Icon'
@@ -25,21 +25,25 @@ function Hero({ summary }) {
</div>
<dl className="mt-4 grid grid-cols-3 gap-3 border-t border-line pt-4 text-sm">
<div>
<dt className="text-xs text-muted">Today</dt>
<dt className="text-xs text-muted">{t.daily_energy_estimated ? 'Today ≈' : 'Today'}</dt>
<dd className="tnum">
<span className="text-lg font-semibold">{today}</span> <span className="text-ink-2">{todayU}</span>
</dd>
</div>
<div>
<dt className="text-xs text-muted">Lifetime</dt>
<dd className="tnum">
<span className="text-lg font-semibold">{life}</span> <span className="text-ink-2">{lifeU}</span>
</dd>
{t.total_energy_wh == null ? (
<dd className="text-xs leading-7 text-muted">not available yet</dd>
) : (
<dd className="tnum">
<span className="text-lg font-semibold">{life}</span> <span className="text-ink-2">{lifeU}</span>
</dd>
)}
</div>
<div>
<dt className="text-xs text-muted">Online</dt>
<dt className="text-xs text-muted">Feeding</dt>
<dd className="tnum">
<span className="text-lg font-semibold">{t.online_count}</span>
<span className="text-lg font-semibold">{t.feeding_count}</span>
<span className="text-ink-2"> / {t.inverter_count}</span>
</dd>
</div>
@@ -114,13 +118,20 @@ function EnergyCard({ ids, names }) {
mode === 'combined'
? [{ key: 'total_wh', name: 'All inverters', color: c.accent }]
: ids.map((id) => ({ key: id, name: names[id] ?? id, color: seriesColor(c, ids, id) }))
const total = data?.days.reduce((s, d) => s + d.total_wh, 0)
const total = data?.days.reduce((s, d) => s + (d.total_wh ?? 0), 0)
const estimated = data?.days.some((d) => d.estimated)
const empty = data && data.days.every((d) => d.total_wh == null)
return (
<section className="card p-4">
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
<div>
<h2 className="text-sm font-semibold">Daily energy · last 30 days</h2>
{data && <div className="text-xs text-muted tnum">{energy(total)} total</div>}
{data && !empty && (
<div className="text-xs text-muted tnum">
{estimated && '≈ '}
{energy(total)} total
</div>
)}
</div>
<Segmented
label="Energy chart mode"
@@ -137,12 +148,14 @@ function EnergyCard({ ids, names }) {
<Legend series={series} />
</div>
)}
{data ? (
{empty ? (
<div className="flex h-56 items-center justify-center text-sm text-muted">No energy data yet</div>
) : data ? (
<DayBars days={data.days} series={series} format={energy} axisFormat={(wh) => num(wh / 1000, 0)} />
) : (
<div className="h-56" />
)}
<div className="mt-1 text-right text-[11px] text-muted">axis in kWh</div>
<EnergyFootnote estimated={estimated} />
</section>
)
}
+45 -20
View File
@@ -1,6 +1,6 @@
import { useMemo, useState } from 'react'
import { Link, useParams } from 'react-router-dom'
import { DayBars, Legend, TimeLines } from '../components/Charts'
import { DayBars, EnergyFootnote, Legend, TimeLines } from '../components/Charts'
import EditInverterDialog from '../components/EditInverterDialog'
import { IssueList, OnlineDot, StatePill } from '../components/Health'
import Icon from '../components/Icon'
@@ -31,14 +31,18 @@ function formatField(field, value) {
return `${num(value, field.decimals)}${field.unit ? ` ${field.unit}` : ''}`
}
function KeyFigure({ label, parts }) {
function KeyFigure({ label, parts, unavailable }) {
return (
<div className="card px-4 py-3">
<div className="text-xs text-muted">{label}</div>
<div className="tnum">
<span className="text-2xl font-semibold tracking-tight">{parts[0]}</span>
<span className="ml-1 text-sm text-ink-2">{parts[1]}</span>
</div>
{unavailable ? (
<div className="text-sm leading-8 text-muted">not available yet</div>
) : (
<div className="tnum">
<span className="text-2xl font-semibold tracking-tight">{parts[0]}</span>
<span className="ml-1 text-sm text-ink-2">{parts[1]}</span>
</div>
)}
</div>
)
}
@@ -54,10 +58,12 @@ function Parameters({ fields, latest, live }) {
</p>
<div className="grid gap-x-8 gap-y-4 sm:grid-cols-2">
{GROUPS.map((g) => {
const items = fields.filter((f) => f.group === g.key)
// Parameters the poller doesn't send (yet) are left out entirely
const items = fields.filter((f) => f.group === g.key && latest?.[f.key] != null)
return (
<div key={g.key}>
<h3 className="mb-1 text-xs font-semibold uppercase tracking-wide text-muted">{g.label}</h3>
{items.length === 0 && <p className="py-1.5 text-sm text-muted">Not available yet</p>}
<dl className="divide-y divide-[var(--border)] text-sm">
{items.map((f) => (
<div key={f.key} className="flex justify-between gap-4 py-1.5">
@@ -94,13 +100,18 @@ function HistoryCharts({ id, fields }) {
const seconds = RANGES[range].seconds
const { data } = usePoll(() => api.history(id, { from: isoAgo(seconds) }), 120_000, `${id}:${range}`)
const points = data?.points ?? []
const hasData = (key) => points.some((p) => p[key] != null)
const powerSeries = [
{ key: 'ac_power_total_w', name: 'AC output', color: c.series[0] },
{ key: 'dc_power_mppt1_w', name: 'DC MPPT1', color: c.series[1] },
{ key: 'dc_power_mppt2_w', name: 'DC MPPT2', color: c.series[2] },
]
const chartable = fields.filter((f) => !f.derived && f.agg === 'avg' && f.key !== 'ac_power_total_w')
const paramField = fields.find((f) => f.key === param) ?? chartable[0]
].filter((s, i) => i === 0 || hasData(s.key))
const hasDc = powerSeries.length > 1
const chartable = fields.filter(
(f) => !f.derived && f.agg === 'avg' && f.key !== 'ac_power_total_w' && (!data || hasData(f.key)),
)
const paramField = chartable.find((f) => f.key === param) ?? chartable[0]
const from = data ? Date.parse(data.from) / 1000 : 0
const to = data ? Date.parse(data.to) / 1000 : 1
@@ -133,8 +144,9 @@ function HistoryCharts({ id, fields }) {
<div className="h-60" />
)}
<p className="mt-2 text-xs text-muted">
MPPT1 and MPPT2 should track each other when both carry similar strings — one dropping
away from the other points at that string.
{hasDc
? 'MPPT1 and MPPT2 should track each other when both carry similar strings — one dropping away from the other points at that string.'
: 'DC input (MPPT) values are not available yet.'}
</p>
</section>
@@ -155,7 +167,9 @@ function HistoryCharts({ id, fields }) {
))}
</select>
</div>
{data && paramField ? (
{data && !paramField ? (
<div className="flex h-52 items-center justify-center text-sm text-muted">No data in this range</div>
) : data && paramField ? (
<TimeLines
points={data.points}
series={[{ key: paramField.key, name: paramField.label, color: c.series[0] }]}
@@ -178,11 +192,20 @@ function YearEnergy({ id }) {
const c = useThemeColors()
const { data } = usePoll(() => api.inverterDaily(id, { days: 365 }), 600_000, id)
const total = data?.days.reduce((s, d) => s + (d.energy_wh ?? 0), 0)
const estimated = data?.days.some((d) => d.estimated)
const empty = data && data.days.every((d) => d.energy_wh == null)
return (
<section className="card p-4">
<h2 className="text-sm font-semibold">Daily energy · last 365 days</h2>
{data && <div className="mb-3 text-xs text-muted tnum">{energy(total)} total</div>}
{data ? (
{data && !empty && (
<div className="mb-3 text-xs text-muted tnum">
{estimated && '≈ '}
{energy(total)} total
</div>
)}
{empty ? (
<div className="flex h-56 items-center justify-center text-sm text-muted">No energy data yet</div>
) : data ? (
<DayBars
days={data.days}
series={[{ key: 'energy_wh', name: 'Energy', color: c.accent }]}
@@ -192,7 +215,7 @@ function YearEnergy({ id }) {
) : (
<div className="h-56" />
)}
<div className="mt-1 text-right text-[11px] text-muted">axis in kWh</div>
<EnergyFootnote estimated={estimated} />
</section>
)
}
@@ -218,7 +241,6 @@ export default function InverterDetail({ summaryPoll }) {
const { inverter, health, latest } = status
const live = health.online
const fromToday = latest?.timestamp && new Date(latest.timestamp).toDateString() === new Date().toDateString()
return (
<div className="space-y-4">
@@ -237,7 +259,7 @@ export default function InverterDetail({ summaryPoll }) {
</div>
</div>
<div className="flex items-center gap-2">
<StatePill state={health.state} size="lg" />
<StatePill state={health.state} feeding={health.feeding} size="lg" />
<button
type="button"
onClick={() => setEditing(true)}
@@ -254,8 +276,11 @@ export default function InverterDetail({ summaryPoll }) {
<div className="grid grid-cols-2 gap-3 md:grid-cols-4">
<KeyFigure label="Power now" parts={powerParts(live ? latest?.ac_power_total_w : null)} />
<KeyFigure label="Today" parts={energyParts(fromToday ? latest?.daily_energy_wh : null)} />
<KeyFigure label="Lifetime" parts={energyParts(latest?.total_energy_wh)} />
<KeyFigure
label={status.energy_today.estimated ? 'Today ≈' : 'Today'}
parts={energyParts(status.energy_today.wh)}
/>
<KeyFigure label="Lifetime" parts={energyParts(latest?.total_energy_wh)} unavailable={latest?.total_energy_wh == null} />
<KeyFigure
label="vs fleet median"
parts={[health.relative_output == null ? '—' : num(health.relative_output * 100, 0), '%']}