feat: solar inverter monitor — FastAPI + SQLite backend, React PWA dashboard
Monitoring for the Refusol 020K inverters. The on-site poller POSTs each 60 s cycle to /api/readings; the dashboard answers first whether every inverter is operating and whether one is producing far less than its peers (string fuse / breaker problems). - Backend: FastAPI + SQLite. Parameters defined once in fields.py (columns auto-added on start); unknown poller keys are kept in `extra` since the parameter map is still being researched. Idempotent ingest, daily energy rollup in site-local days, history downsampling, 2-year retention. - Health: Offline vs Sleeping (sun elevation) vs No data (datalogger silent, detected via empty-batch heartbeats), Fault from error_code, underperformance vs fleet median (per kWp when sizes set), MPPT imbalance. - Frontend: mobile-first React + Tailwind, installable PWA, comparison bars, 24 h power / 30 day energy charts, detail page with all parameters. - Docker: backend + frontend + nginx on one port for NPM, as in bellsystems-cp; deploy-host.sh pulls main and rebuilds. - poller/backend_client.py: stdlib client with offline spool for refusol_poller.py; fake_poller.py simulates the site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
dev-dist/
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
dev-dist/
|
||||
@@ -0,0 +1,18 @@
|
||||
# Stage 1: build
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: serve with nginx
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
COPY nginx.prod.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
@@ -0,0 +1,19 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#f9f9f7" media="(prefers-color-scheme: light)" />
|
||||
<meta name="theme-color" content="#0d0d0d" media="(prefers-color-scheme: dark)" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Solar" />
|
||||
<title>Solar Monitor</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# SPA fallback — all unknown routes serve index.html
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# The service worker and manifest must be re-checked on every load,
|
||||
# otherwise phones keep running an old build.
|
||||
location ~* ^/(sw\.js|workbox-.*\.js|manifest\.webmanifest|index\.html)$ {
|
||||
add_header Cache-Control "no-cache";
|
||||
}
|
||||
|
||||
# Hashed build assets
|
||||
location /assets/ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
Generated
+7169
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.2.5",
|
||||
"react-dom": "^19.2.5",
|
||||
"react-router-dom": "^7.14.1",
|
||||
"recharts": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.1.18",
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"tailwindcss": "^4.1.18",
|
||||
"vite": "^8.0.9",
|
||||
"vite-plugin-pwa": "^1.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#1a1a19"/><g stroke="#f5b324" stroke-width="4" stroke-linecap="round"><path d="M32 8v6M32 50v6M8 32h6M50 32h6M15 15l4.2 4.2M44.8 44.8 49 49M15 49l4.2-4.2M44.8 19.2 49 15"/></g><circle cx="32" cy="32" r="11" fill="#f5b324"/></svg>
|
||||
|
After Width: | Height: | Size: 333 B |
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,72 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link, Route, Routes } from 'react-router-dom'
|
||||
import Icon from './components/Icon'
|
||||
import { useInstallPrompt } from './hooks/useInstallPrompt'
|
||||
import { usePoll } from './hooks/usePoll'
|
||||
import { api } from './lib/api'
|
||||
import { ago } from './lib/format'
|
||||
import Dashboard from './pages/Dashboard'
|
||||
import InverterDetail from './pages/InverterDetail'
|
||||
|
||||
function useTick(ms) {
|
||||
const [, setN] = useState(0)
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setN((n) => n + 1), ms)
|
||||
return () => clearInterval(id)
|
||||
}, [ms])
|
||||
}
|
||||
|
||||
function LiveChip({ summary, error }) {
|
||||
useTick(10_000)
|
||||
if (error && !summary) return null
|
||||
if (!summary) return null
|
||||
const ok = summary.datalogger.online && !error
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 text-xs text-ink-2">
|
||||
<span
|
||||
className={`h-2 w-2 rounded-full ${ok ? 'animate-pulse' : ''}`}
|
||||
style={{ background: ok ? 'var(--good)' : 'var(--critical)' }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{error ? 'Connection lost' : ok ? `Live · ${ago(summary.datalogger.last_ingest_at)}` : 'Datalogger offline'}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
// One summary poll shared by both pages, so navigating is instant
|
||||
const summaryPoll = usePoll(() => api.summary(), 30_000)
|
||||
const install = useInstallPrompt()
|
||||
|
||||
return (
|
||||
<div className="min-h-dvh">
|
||||
<header className="sticky top-0 z-40 border-b border-line bg-page/85 pt-[env(safe-area-inset-top)] backdrop-blur">
|
||||
<div className="mx-auto flex h-14 max-w-6xl items-center justify-between gap-3 px-4">
|
||||
<Link to="/" className="flex items-center gap-2 font-semibold">
|
||||
<img src="/favicon.svg" alt="" className="h-7 w-7" />
|
||||
<span>Solar Monitor</span>
|
||||
</Link>
|
||||
<div className="flex items-center gap-3">
|
||||
<LiveChip summary={summaryPoll.data} error={summaryPoll.error} />
|
||||
{install && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={install}
|
||||
className="inline-flex min-h-8 items-center gap-1 rounded-lg border border-line px-2.5 text-xs font-medium"
|
||||
>
|
||||
<Icon name="download" size={14} /> Install
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main className="mx-auto max-w-6xl px-4 py-4">
|
||||
<Routes>
|
||||
<Route path="/" element={<Dashboard summaryPoll={summaryPoll} />} />
|
||||
<Route path="/inverters/:id" element={<InverterDetail summaryPoll={summaryPoll} />} />
|
||||
<Route path="*" element={<Dashboard summaryPoll={summaryPoll} />} />
|
||||
</Routes>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
import { useMemo } from 'react'
|
||||
import {
|
||||
Bar,
|
||||
BarChart,
|
||||
CartesianGrid,
|
||||
Line,
|
||||
LineChart,
|
||||
ResponsiveContainer,
|
||||
Tooltip,
|
||||
XAxis,
|
||||
YAxis,
|
||||
} from 'recharts'
|
||||
import { useThemeColors } from '../lib/colors'
|
||||
import { dateTimeLabel, dayLabel, timeLabel } from '../lib/format'
|
||||
|
||||
export function Legend({ series }) {
|
||||
if (series.length < 2) return null
|
||||
return (
|
||||
<ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-ink-2">
|
||||
{series.map((s) => (
|
||||
<li key={s.key} className="inline-flex items-center gap-1.5">
|
||||
<span className="h-0.5 w-3 rounded-full" style={{ background: s.color, height: 3 }} />
|
||||
{s.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
function TooltipBox({ title, rows, total }) {
|
||||
return (
|
||||
<div className="card min-w-40 px-3 py-2 text-xs shadow-lg">
|
||||
<div className="mb-1 font-medium text-ink-2">{title}</div>
|
||||
<table className="w-full">
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.key}>
|
||||
<td className="py-0.5 pr-3">
|
||||
<span className="inline-flex items-center gap-1.5 text-ink-2">
|
||||
<span className="inline-block h-2 w-2 rounded-full" style={{ background: r.color }} />
|
||||
{r.name}
|
||||
</span>
|
||||
</td>
|
||||
<td className="tnum py-0.5 text-right font-medium text-ink">{r.value}</td>
|
||||
</tr>
|
||||
))}
|
||||
{total && (
|
||||
<tr className="border-t border-line">
|
||||
<td className="pt-1 pr-3 text-ink-2">Total</td>
|
||||
<td className="tnum pt-1 text-right font-semibold text-ink">{total}</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const axisTick = (c) => ({ fill: c.muted, fontSize: 11 })
|
||||
|
||||
/** Insert an empty point wherever readings stop for more than a couple of
|
||||
* buckets (night, outage), so the line breaks instead of bridging the gap. */
|
||||
function withGaps(points, bucket) {
|
||||
if (!bucket || points.length < 2) return points
|
||||
const out = [points[0]]
|
||||
for (let i = 1; i < points.length; i++) {
|
||||
if (points[i].t - points[i - 1].t > bucket * 2.5) out.push({ t: points[i - 1].t + bucket })
|
||||
out.push(points[i])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* Lines over time. points: [{t: unix seconds, [series.key]: number}]
|
||||
* series: [{key, name, color}]. Gaps (night, outages) stay gaps.
|
||||
*/
|
||||
export function TimeLines({ points, series, from, to, bucket, format, axisFormat, height = 240, showTotal = false }) {
|
||||
const c = useThemeColors()
|
||||
const span = to - from
|
||||
const data = useMemo(() => withGaps(points, bucket), [points, bucket])
|
||||
return (
|
||||
<div style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={data} margin={{ top: 8, right: 8, bottom: 0, left: 0 }}>
|
||||
<CartesianGrid stroke={c.grid} vertical={false} />
|
||||
<XAxis
|
||||
dataKey="t"
|
||||
type="number"
|
||||
domain={[from, to]}
|
||||
scale="time"
|
||||
tickFormatter={(t) => timeLabel(t, span)}
|
||||
tick={axisTick(c)}
|
||||
stroke={c.axis}
|
||||
tickLine={false}
|
||||
minTickGap={28}
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={axisFormat ?? format}
|
||||
tick={axisTick(c)}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
width={48}
|
||||
/>
|
||||
<Tooltip
|
||||
cursor={{ stroke: c.axis, strokeWidth: 1 }}
|
||||
content={({ active, payload, label }) => {
|
||||
if (!active || !payload?.length) return null
|
||||
const rows = series
|
||||
.filter((s) => payload[0].payload[s.key] != null)
|
||||
.map((s) => ({ ...s, value: format(payload[0].payload[s.key]) }))
|
||||
const total = showTotal
|
||||
? format(series.reduce((sum, s) => sum + (payload[0].payload[s.key] ?? 0), 0))
|
||||
: null
|
||||
return <TooltipBox title={dateTimeLabel(label)} rows={rows} total={total} />
|
||||
}}
|
||||
/>
|
||||
{series.map((s) => (
|
||||
<Line
|
||||
key={s.key}
|
||||
dataKey={s.key}
|
||||
name={s.name}
|
||||
stroke={s.color}
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
activeDot={{ r: 4, stroke: c.surface, strokeWidth: 2 }}
|
||||
connectNulls={false}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Bars per day. days: [{day: 'YYYY-MM-DD', [series.key]: number}].
|
||||
* Several series are stacked (the stack height is the day's total).
|
||||
*/
|
||||
export function DayBars({ days, series, format, axisFormat, height = 220 }) {
|
||||
const c = useThemeColors()
|
||||
const last = series.length - 1
|
||||
return (
|
||||
<div style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={days} margin={{ top: 8, right: 8, bottom: 0, left: 0 }} barCategoryGap="18%">
|
||||
<CartesianGrid stroke={c.grid} vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={(d) => dayLabel(d)}
|
||||
tick={axisTick(c)}
|
||||
stroke={c.axis}
|
||||
tickLine={false}
|
||||
minTickGap={24}
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={axisFormat ?? format}
|
||||
tick={axisTick(c)}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
width={48}
|
||||
/>
|
||||
<Tooltip
|
||||
cursor={{ fill: c.grid, opacity: 0.5 }}
|
||||
content={({ active, payload, label }) => {
|
||||
if (!active || !payload?.length) return null
|
||||
const row = payload[0].payload
|
||||
const rows = series.map((s) => ({ ...s, value: format(row[s.key]) }))
|
||||
const total =
|
||||
series.length > 1 ? format(series.reduce((sum, s) => sum + (row[s.key] ?? 0), 0)) : null
|
||||
return <TooltipBox title={dayLabel(label, true)} rows={rows} total={total} />
|
||||
}}
|
||||
/>
|
||||
{series.map((s, i) => (
|
||||
<Bar
|
||||
key={s.key}
|
||||
dataKey={s.key}
|
||||
name={s.name}
|
||||
stackId="day"
|
||||
fill={s.color}
|
||||
stroke={series.length > 1 ? c.surface : undefined}
|
||||
strokeWidth={series.length > 1 ? 1 : 0}
|
||||
radius={i === last ? [3, 3, 0, 0] : 0}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
import { seriesCssVar } from '../lib/colors'
|
||||
import { pct, power } from '../lib/format'
|
||||
import Icon from './Icon'
|
||||
import { STATES } from './Health'
|
||||
|
||||
/**
|
||||
* Side-by-side output of every inverter — the quickest way to spot one
|
||||
* that is producing far less than the others (blown string fuse, tripped
|
||||
* breaker, disconnected string).
|
||||
*/
|
||||
export default function Comparison({ summary, ids }) {
|
||||
const rows = summary.inverters
|
||||
const perKwp = summary.fleet_median_w_per_kwp !== null
|
||||
const value = (st) => {
|
||||
const w = st.health.online ? st.latest?.ac_power_total_w ?? null : null
|
||||
if (w === null) return null
|
||||
return perKwp && st.inverter.capacity_kwp ? w / st.inverter.capacity_kwp : w
|
||||
}
|
||||
const max = Math.max(1, ...rows.map((st) => value(st) ?? 0))
|
||||
|
||||
return (
|
||||
<section className="card p-4">
|
||||
<div className="mb-3 flex items-baseline justify-between gap-2">
|
||||
<h2 className="text-sm font-semibold">Output comparison</h2>
|
||||
<span className="text-xs text-muted">{perKwp ? 'per kWp · vs median' : 'now · vs median'}</span>
|
||||
</div>
|
||||
<ul className="space-y-3">
|
||||
{rows.map((st) => {
|
||||
const v = value(st)
|
||||
const flagged = st.health.issues.some((i) => i.code === 'underperforming')
|
||||
const state = STATES[st.health.state]
|
||||
return (
|
||||
<li key={st.inverter.id}>
|
||||
<Link
|
||||
to={`/inverters/${encodeURIComponent(st.inverter.id)}`}
|
||||
className="group block rounded-lg -mx-1 px-1 py-0.5 hover:bg-surface-2"
|
||||
>
|
||||
<div className="mb-1 flex items-center justify-between gap-2 text-sm">
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<span
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-sm"
|
||||
style={{ background: seriesCssVar(ids, st.inverter.id) }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="truncate font-medium">{st.inverter.name}</span>
|
||||
</span>
|
||||
<span className="flex shrink-0 items-center gap-2 tnum">
|
||||
{v === null ? (
|
||||
<span className="inline-flex items-center gap-1 text-xs text-ink-2">
|
||||
<Icon name={state.icon} size={13} />
|
||||
{state.label}
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="font-semibold">{power(st.latest.ac_power_total_w)}</span>
|
||||
<span
|
||||
className={`inline-flex w-14 items-center justify-end gap-0.5 text-xs ${
|
||||
flagged ? 'font-semibold text-warn' : 'text-muted'
|
||||
}`}
|
||||
>
|
||||
{flagged && <Icon name="alert" size={12} strokeWidth={2.5} />}
|
||||
{pct(st.health.relative_output)}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-2.5 overflow-hidden rounded-full bg-surface-2">
|
||||
<div
|
||||
className="h-full rounded-full transition-[width] duration-500"
|
||||
style={{
|
||||
width: `${v === null ? 0 : Math.max(1, (v / max) * 100)}%`,
|
||||
background: seriesCssVar(ids, st.inverter.id),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useState } from 'react'
|
||||
import { api } from '../lib/api'
|
||||
import Icon from './Icon'
|
||||
|
||||
const KEY_STORAGE = 'solar.apiKey'
|
||||
|
||||
function storedKey() {
|
||||
try {
|
||||
return localStorage.getItem(KEY_STORAGE) ?? ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function Field({ label, hint, children }) {
|
||||
return (
|
||||
<label className="block">
|
||||
<span className="text-xs font-medium text-ink-2">{label}</span>
|
||||
{children}
|
||||
{hint && <span className="mt-1 block text-xs text-muted">{hint}</span>}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
const input =
|
||||
'mt-1 block w-full min-h-10 rounded-lg border border-line bg-surface-2 px-3 text-base text-ink outline-none focus:border-[var(--accent)]'
|
||||
|
||||
export default function EditInverterDialog({ inverter, onClose, onSaved }) {
|
||||
const [form, setForm] = useState({
|
||||
name: inverter.name ?? '',
|
||||
capacity_kwp: inverter.capacity_kwp ?? '',
|
||||
mppt_count: inverter.mppt_count ?? 2,
|
||||
sort_order: inverter.sort_order ?? 0,
|
||||
notes: inverter.notes ?? '',
|
||||
})
|
||||
const [apiKey, setApiKey] = useState(storedKey)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const set = (k) => (e) => setForm((f) => ({ ...f, [k]: e.target.value }))
|
||||
|
||||
async function save(e) {
|
||||
e.preventDefault()
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
const body = {
|
||||
name: form.name.trim() || inverter.id,
|
||||
capacity_kwp: form.capacity_kwp === '' ? null : Number(form.capacity_kwp),
|
||||
mppt_count: Number(form.mppt_count),
|
||||
sort_order: Number(form.sort_order) || 0,
|
||||
notes: form.notes.trim() || null,
|
||||
}
|
||||
const saved = await api.updateInverter(inverter.id, body, apiKey)
|
||||
try {
|
||||
localStorage.setItem(KEY_STORAGE, apiKey)
|
||||
} catch {
|
||||
/* storage unavailable — key just isn't remembered */
|
||||
}
|
||||
onSaved(saved)
|
||||
} catch (err) {
|
||||
setError(err.status === 401 ? 'Wrong API key' : err.message)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-end justify-center bg-black/50 sm:items-center sm:p-4"
|
||||
onClick={onClose}
|
||||
>
|
||||
<form
|
||||
onSubmit={save}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="card max-h-[92dvh] w-full max-w-md overflow-y-auto rounded-b-none p-5 pb-[max(1.25rem,env(safe-area-inset-bottom))] sm:rounded-b-[14px]"
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h2 className="font-semibold">Inverter settings</h2>
|
||||
<button type="button" onClick={onClose} className="-m-2 p-2 text-ink-2" aria-label="Close">
|
||||
<Icon name="close" size={20} />
|
||||
</button>
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
<Field label="Display name" hint={`ID sent by the poller: ${inverter.id}`}>
|
||||
<input className={input} value={form.name} onChange={set('name')} maxLength={100} />
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label="Array size (kWp)">
|
||||
<input
|
||||
className={input}
|
||||
type="number"
|
||||
inputMode="decimal"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={form.capacity_kwp}
|
||||
onChange={set('capacity_kwp')}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="MPPT inputs used">
|
||||
<select className={input} value={form.mppt_count} onChange={set('mppt_count')}>
|
||||
<option value={1}>1</option>
|
||||
<option value={2}>2</option>
|
||||
</select>
|
||||
</Field>
|
||||
</div>
|
||||
<p className="-mt-2 text-xs text-muted">
|
||||
Set the array size on every inverter to compare output per kWp — needed when the arrays
|
||||
differ. With one MPPT input in use, the string-imbalance check is skipped.
|
||||
</p>
|
||||
<Field label="Sort order">
|
||||
<input className={input} type="number" inputMode="numeric" value={form.sort_order} onChange={set('sort_order')} />
|
||||
</Field>
|
||||
<Field label="Notes">
|
||||
<textarea className={`${input} min-h-20 py-2`} value={form.notes} onChange={set('notes')} />
|
||||
</Field>
|
||||
<Field label="API key">
|
||||
<input
|
||||
className={input}
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
{error && <p className="text-sm text-crit">{error}</p>}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="min-h-11 w-full rounded-lg bg-ink font-semibold text-page disabled:opacity-60"
|
||||
>
|
||||
{saving ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import Icon from './Icon'
|
||||
|
||||
export const STATES = {
|
||||
ok: { label: 'Operating', icon: 'check', tone: 'good' },
|
||||
warning: { label: 'Check needed', icon: 'alert', tone: 'warning' },
|
||||
fault: { label: 'Fault', icon: 'fault', tone: 'critical' },
|
||||
offline: { label: 'Offline', icon: 'offline', tone: 'critical' },
|
||||
sleeping: { label: 'Sleeping', icon: 'moon', tone: 'neutral' },
|
||||
unknown: { label: 'No data', icon: 'unknown', tone: 'neutral' },
|
||||
}
|
||||
|
||||
const TONE = {
|
||||
good: 'bg-[var(--good-wash)] text-good',
|
||||
warning: 'bg-[var(--warning-wash)] text-warn',
|
||||
critical: 'bg-[var(--critical-wash)] text-crit',
|
||||
neutral: 'bg-surface-2 text-ink-2',
|
||||
}
|
||||
|
||||
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
|
||||
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]}`}>
|
||||
<Icon name={s.icon} size={size === 'lg' ? 16 : 13} strokeWidth={2.5} />
|
||||
{s.label}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/** Online = a reading within the last 5 minutes. */
|
||||
export function OnlineDot({ online }) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 text-xs text-ink-2">
|
||||
<span
|
||||
className="h-2 w-2 rounded-full"
|
||||
style={{ background: online ? 'var(--good)' : 'var(--muted)' }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{online ? 'Online' : 'Offline'}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export function IssueList({ issues, compact = false }) {
|
||||
if (!issues?.length) return null
|
||||
return (
|
||||
<ul className={compact ? 'space-y-1' : 'space-y-2'}>
|
||||
{issues.map((issue) => {
|
||||
const tone = SEVERITY_TONE[issue.severity]
|
||||
return (
|
||||
<li
|
||||
key={issue.code}
|
||||
className={`flex items-start gap-2 rounded-lg ${compact ? 'px-2 py-1.5 text-xs' : 'px-3 py-2 text-sm'} ${TONE[tone]}`}
|
||||
>
|
||||
<Icon name={SEVERITY_ICON[issue.severity]} size={compact ? 14 : 16} className="mt-px" />
|
||||
<span className="text-ink">{issue.message}</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
const PATHS = {
|
||||
check: <path d="M20 6 9 17l-5-5" />,
|
||||
alert: (
|
||||
<>
|
||||
<path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z" />
|
||||
<path d="M12 9v4M12 17h.01" />
|
||||
</>
|
||||
),
|
||||
fault: (
|
||||
<>
|
||||
<path d="M7.9 2h8.2L22 7.9v8.2L16.1 22H7.9L2 16.1V7.9Z" />
|
||||
<path d="m15 9-6 6M9 9l6 6" />
|
||||
</>
|
||||
),
|
||||
offline: (
|
||||
<>
|
||||
<path d="M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8a15 15 0 0 0-11.3-3.8M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.6-1.3" />
|
||||
<path d="m2 2 20 20" />
|
||||
</>
|
||||
),
|
||||
moon: <path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />,
|
||||
unknown: (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3M12 17h.01" />
|
||||
</>
|
||||
),
|
||||
sun: (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M6.3 17.7l-1.4 1.4M19.1 4.9l-1.4 1.4" />
|
||||
</>
|
||||
),
|
||||
back: <path d="m15 18-6-6 6-6" />,
|
||||
chevron: <path d="m9 18 6-6-6-6" />,
|
||||
edit: (
|
||||
<>
|
||||
<path d="M12 20h9" />
|
||||
<path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" />
|
||||
</>
|
||||
),
|
||||
download: (
|
||||
<>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||
<path d="m7 10 5 5 5-5M12 15V3" />
|
||||
</>
|
||||
),
|
||||
close: <path d="M18 6 6 18M6 6l12 12" />,
|
||||
link: (
|
||||
<>
|
||||
<path d="M5 12.55a11 11 0 0 1 14.08 0M1.42 9a16 16 0 0 1 21.16 0M8.53 16.11a6 6 0 0 1 6.95 0M12 20h.01" />
|
||||
</>
|
||||
),
|
||||
}
|
||||
|
||||
export default function Icon({ name, size = 16, className = '', strokeWidth = 2 }) {
|
||||
return (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={strokeWidth}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className={`shrink-0 ${className}`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{PATHS[name]}
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
import { seriesCssVar } from '../lib/colors'
|
||||
import { ago, energyParts, num, powerParts } from '../lib/format'
|
||||
import { IssueList, OnlineDot, StatePill } from './Health'
|
||||
import Icon from './Icon'
|
||||
|
||||
function Stat({ label, value, unit }) {
|
||||
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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function InverterCard({ status, ids }) {
|
||||
const { inverter, health, latest } = 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 [life, lifeU] = energyParts(r.total_energy_wh)
|
||||
const volts = [r.ac_voltage_l1_v, r.ac_voltage_l2_v, r.ac_voltage_l3_v]
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={`/inverters/${encodeURIComponent(inverter.id)}`}
|
||||
className="card group flex flex-col gap-3 p-4 transition-colors hover:border-[var(--axis)]"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-sm"
|
||||
style={{ background: seriesCssVar(ids, inverter.id) }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<h3 className="truncate font-semibold">{inverter.name}</h3>
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-2">
|
||||
<OnlineDot online={live} />
|
||||
<span className="text-xs text-muted">· {ago(r.timestamp)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<StatePill state={health.state} />
|
||||
</div>
|
||||
|
||||
<div className="flex items-baseline gap-1 tnum">
|
||||
<span className="text-3xl font-semibold tracking-tight">{pw}</span>
|
||||
<span className="text-sm text-ink-2">{pu}</span>
|
||||
{inverter.capacity_kwp && live && r.ac_power_total_w != null && (
|
||||
<span className="ml-auto text-xs text-muted">
|
||||
{num(r.ac_power_total_w / inverter.capacity_kwp, 0)} W/kWp
|
||||
</span>
|
||||
)}
|
||||
</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="Temp" value={live ? num(r.temperature_c) : '—'} unit="°C" />
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between rounded-lg bg-surface-2 px-3 py-2 text-xs tnum">
|
||||
<span className="text-muted">AC</span>
|
||||
{volts.map((v, i) => (
|
||||
<span key={i}>
|
||||
<span className="text-muted">L{i + 1} </span>
|
||||
<span className="font-medium">{live ? num(v, 0) : '—'}</span>
|
||||
<span className="text-muted"> V</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{health.issues.length > 0 && <IssueList issues={health.issues} compact />}
|
||||
|
||||
<span className="mt-auto inline-flex items-center gap-1 self-end text-xs text-muted group-hover:text-ink-2">
|
||||
Details <Icon name="chevron" size={12} />
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
export default function Segmented({ options, value, onChange, label }) {
|
||||
return (
|
||||
<div role="radiogroup" aria-label={label} className="inline-flex rounded-lg bg-surface-2 p-0.5 text-xs">
|
||||
{options.map((o) => {
|
||||
const active = o.value === value
|
||||
return (
|
||||
<button
|
||||
key={o.value}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={active}
|
||||
onClick={() => onChange(o.value)}
|
||||
className={`min-h-8 rounded-md px-3 font-medium transition-colors ${
|
||||
active ? 'bg-surface text-ink shadow-sm' : 'text-ink-2 hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
{o.label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
/** Chrome / Edge / Android "install app" prompt, when the browser offers one.
|
||||
* Returns a function that shows it, or null. (iOS: Share → Add to Home Screen.) */
|
||||
export function useInstallPrompt() {
|
||||
const [event, setEvent] = useState(null)
|
||||
useEffect(() => {
|
||||
const onPrompt = (e) => {
|
||||
e.preventDefault()
|
||||
setEvent(e)
|
||||
}
|
||||
const onInstalled = () => setEvent(null)
|
||||
window.addEventListener('beforeinstallprompt', onPrompt)
|
||||
window.addEventListener('appinstalled', onInstalled)
|
||||
return () => {
|
||||
window.removeEventListener('beforeinstallprompt', onPrompt)
|
||||
window.removeEventListener('appinstalled', onInstalled)
|
||||
}
|
||||
}, [])
|
||||
if (!event) return null
|
||||
return async () => {
|
||||
event.prompt()
|
||||
await event.userChoice
|
||||
setEvent(null)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
/** Calls `fetcher` now, every `intervalMs`, and whenever the app comes back to
|
||||
* the foreground (phones suspend timers). Starts over when `key` changes. */
|
||||
export function usePoll(fetcher, intervalMs, key = '') {
|
||||
const [data, setData] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const fetcherRef = useRef(fetcher)
|
||||
fetcherRef.current = fetcher
|
||||
|
||||
const run = useCallback(async () => {
|
||||
try {
|
||||
setData(await fetcherRef.current())
|
||||
setError(null)
|
||||
} catch (e) {
|
||||
setError(e)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true)
|
||||
run()
|
||||
const id = setInterval(() => {
|
||||
if (document.visibilityState === 'visible') run()
|
||||
}, intervalMs)
|
||||
const onVisible = () => document.visibilityState === 'visible' && run()
|
||||
document.addEventListener('visibilitychange', onVisible)
|
||||
return () => {
|
||||
clearInterval(id)
|
||||
document.removeEventListener('visibilitychange', onVisible)
|
||||
}
|
||||
}, [run, intervalMs, key])
|
||||
|
||||
return { data, error, loading, refresh: run }
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Tokens: light by default, dark from the OS setting. Series colors are the
|
||||
validated categorical order (one hue per inverter, fixed by position);
|
||||
status colors are reserved for health and always paired with icon + text. */
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--page: #f9f9f7;
|
||||
--surface: #fcfcfb;
|
||||
--surface-2: #f0efec;
|
||||
--ink: #0b0b0b;
|
||||
--ink-2: #52514e;
|
||||
--muted: #898781;
|
||||
--grid: #e1e0d9;
|
||||
--axis: #c3c2b7;
|
||||
--border: rgba(11, 11, 11, 0.1);
|
||||
--accent: #b77400;
|
||||
|
||||
--series-1: #2a78d6;
|
||||
--series-2: #eb6834;
|
||||
--series-3: #1baf7a;
|
||||
--series-4: #eda100;
|
||||
--series-5: #e87ba4;
|
||||
--series-6: #008300;
|
||||
--series-7: #6250d6;
|
||||
--series-8: #e34948;
|
||||
|
||||
--good: #0ca30c;
|
||||
--good-ink: #006300;
|
||||
--warning: #fab219;
|
||||
--warning-ink: #8a5a00;
|
||||
--critical: #d03b3b;
|
||||
--critical-ink: #b42828;
|
||||
--good-wash: rgba(12, 163, 12, 0.1);
|
||||
--warning-wash: rgba(250, 178, 25, 0.16);
|
||||
--critical-wash: rgba(208, 59, 59, 0.1);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--page: #0d0d0d;
|
||||
--surface: #1a1a19;
|
||||
--surface-2: #232322;
|
||||
--ink: #f0efec;
|
||||
--ink-2: #c3c2b7;
|
||||
--muted: #898781;
|
||||
--grid: #2c2c2a;
|
||||
--axis: #383835;
|
||||
--border: rgba(255, 255, 255, 0.1);
|
||||
--accent: #f5b324;
|
||||
|
||||
--series-1: #3987e5;
|
||||
--series-2: #d95926;
|
||||
--series-3: #199e70;
|
||||
--series-4: #c98500;
|
||||
--series-5: #d55181;
|
||||
--series-6: #008300;
|
||||
--series-7: #9085e9;
|
||||
--series-8: #e66767;
|
||||
|
||||
--good-ink: #0ca30c;
|
||||
--warning-ink: #fab219;
|
||||
--critical-ink: #e66767;
|
||||
--good-wash: rgba(12, 163, 12, 0.14);
|
||||
--warning-wash: rgba(250, 178, 25, 0.12);
|
||||
--critical-wash: rgba(208, 59, 59, 0.18);
|
||||
}
|
||||
}
|
||||
|
||||
@theme {
|
||||
--color-page: var(--page);
|
||||
--color-surface: var(--surface);
|
||||
--color-surface-2: var(--surface-2);
|
||||
--color-ink: var(--ink);
|
||||
--color-ink-2: var(--ink-2);
|
||||
--color-muted: var(--muted);
|
||||
--color-line: var(--border);
|
||||
--color-accent: var(--accent);
|
||||
--color-good: var(--good-ink);
|
||||
--color-warn: var(--warning-ink);
|
||||
--color-crit: var(--critical-ink);
|
||||
--font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
background: var(--page);
|
||||
color: var(--ink);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100dvh;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
.tnum {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
/* recharts: keep focus outlines off the svg wrapper on tap */
|
||||
.recharts-wrapper:focus,
|
||||
.recharts-surface:focus {
|
||||
outline: none;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
async function request(path, { method = 'GET', body, apiKey } = {}) {
|
||||
const headers = {}
|
||||
if (body !== undefined) headers['Content-Type'] = 'application/json'
|
||||
if (apiKey) headers['X-API-Key'] = apiKey
|
||||
const res = await fetch(`/api${path}`, {
|
||||
method,
|
||||
headers,
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
})
|
||||
if (!res.ok) {
|
||||
let detail = res.statusText
|
||||
try {
|
||||
const data = await res.json()
|
||||
detail = typeof data.detail === 'string' ? data.detail : JSON.stringify(data.detail)
|
||||
} catch {
|
||||
/* non-JSON error body */
|
||||
}
|
||||
const err = new Error(detail || `HTTP ${res.status}`)
|
||||
err.status = res.status
|
||||
throw err
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
function qs(params = {}) {
|
||||
const q = new URLSearchParams()
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v === undefined || v === null) continue
|
||||
for (const item of [].concat(v)) q.append(k, item)
|
||||
}
|
||||
const s = q.toString()
|
||||
return s ? `?${s}` : ''
|
||||
}
|
||||
|
||||
const inv = (id) => `/inverters/${encodeURIComponent(id)}`
|
||||
|
||||
export const api = {
|
||||
summary: () => request('/summary'),
|
||||
fields: () => request('/meta/fields'),
|
||||
power: (params) => request(`/power${qs(params)}`),
|
||||
dailyEnergy: (params) => request(`/energy/daily${qs(params)}`),
|
||||
inverter: (id) => request(inv(id)),
|
||||
history: (id, params) => request(`${inv(id)}/history${qs(params)}`),
|
||||
inverterDaily: (id, params) => request(`${inv(id)}/daily${qs(params)}`),
|
||||
updateInverter: (id, body, apiKey) => request(inv(id), { method: 'PATCH', body, apiKey }),
|
||||
}
|
||||
|
||||
export function isoAgo(seconds) {
|
||||
return new Date(Date.now() - seconds * 1000).toISOString()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
const SLOTS = 8
|
||||
|
||||
function read() {
|
||||
const cs = getComputedStyle(document.documentElement)
|
||||
const v = (name) => cs.getPropertyValue(name).trim()
|
||||
return {
|
||||
series: Array.from({ length: SLOTS }, (_, i) => v(`--series-${i + 1}`)),
|
||||
ink: v('--ink'),
|
||||
ink2: v('--ink-2'),
|
||||
muted: v('--muted'),
|
||||
grid: v('--grid'),
|
||||
axis: v('--axis'),
|
||||
surface: v('--surface'),
|
||||
accent: v('--accent'),
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolved token colors for the SVG charts; updates when the OS theme flips. */
|
||||
export function useThemeColors() {
|
||||
const [colors, setColors] = useState(read)
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
const onChange = () => setColors(read())
|
||||
mq.addEventListener('change', onChange)
|
||||
return () => mq.removeEventListener('change', onChange)
|
||||
}, [])
|
||||
return colors
|
||||
}
|
||||
|
||||
/** Color for an inverter = its position in the full, stably sorted inverter
|
||||
* list, so a color always follows the same inverter on every chart. */
|
||||
export function seriesColor(colors, ids, id) {
|
||||
const i = Math.max(0, ids.indexOf(id))
|
||||
return colors.series[i % SLOTS]
|
||||
}
|
||||
|
||||
export function seriesCssVar(ids, id) {
|
||||
const i = Math.max(0, ids.indexOf(id))
|
||||
return `var(--series-${(i % SLOTS) + 1})`
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
const nf = (digits) =>
|
||||
new Intl.NumberFormat(undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits })
|
||||
|
||||
export function num(v, digits = 0) {
|
||||
return v === null || v === undefined || Number.isNaN(v) ? '—' : nf(digits).format(v)
|
||||
}
|
||||
|
||||
/** Power with an auto unit: 950 W, 12.4 kW, 1.20 MW. Returns [value, unit]. */
|
||||
export function powerParts(w) {
|
||||
if (w === null || w === undefined) return ['—', 'W']
|
||||
const a = Math.abs(w)
|
||||
if (a >= 1e6) return [num(w / 1e6, 2), 'MW']
|
||||
if (a >= 1000) return [num(w / 1000, a >= 1e5 ? 0 : 1), 'kW']
|
||||
return [num(w, 0), 'W']
|
||||
}
|
||||
|
||||
export function power(w) {
|
||||
const [v, u] = powerParts(w)
|
||||
return `${v} ${u}`
|
||||
}
|
||||
|
||||
/** Energy with an auto unit: 850 Wh, 42.3 kWh, 123.4 MWh. Returns [value, unit]. */
|
||||
export function energyParts(wh) {
|
||||
if (wh === null || wh === undefined) return ['—', 'kWh']
|
||||
const a = Math.abs(wh)
|
||||
if (a >= 1e6) return [num(wh / 1e6, a >= 1e8 ? 0 : 1), 'MWh']
|
||||
if (a >= 1000) return [num(wh / 1000, a >= 1e5 ? 0 : 1), 'kWh']
|
||||
return [num(wh, 0), 'Wh']
|
||||
}
|
||||
|
||||
export function energy(wh) {
|
||||
const [v, u] = energyParts(wh)
|
||||
return `${v} ${u}`
|
||||
}
|
||||
|
||||
export function ago(iso) {
|
||||
if (!iso) return 'never'
|
||||
const s = Math.max(0, Math.round((Date.now() - new Date(iso).getTime()) / 1000))
|
||||
if (s < 60) return `${s} s ago`
|
||||
if (s < 3600) return `${Math.floor(s / 60)} min ago`
|
||||
if (s < 86400) return `${Math.floor(s / 3600)} h ago`
|
||||
return `${Math.floor(s / 86400)} d ago`
|
||||
}
|
||||
|
||||
export function pct(ratio) {
|
||||
return ratio === null || ratio === undefined ? '—' : `${Math.round(ratio * 100)}%`
|
||||
}
|
||||
|
||||
export function timeLabel(unix, spanSeconds) {
|
||||
const d = new Date(unix * 1000)
|
||||
if (spanSeconds <= 2 * 86400) return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||
return d.toLocaleDateString([], { weekday: 'short', day: 'numeric' })
|
||||
}
|
||||
|
||||
export function dateTimeLabel(unix) {
|
||||
return new Date(unix * 1000).toLocaleString([], {
|
||||
weekday: 'short',
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
})
|
||||
}
|
||||
|
||||
export function dayLabel(isoDay, long = false) {
|
||||
const d = new Date(`${isoDay}T12:00:00`)
|
||||
return long
|
||||
? d.toLocaleDateString([], { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' })
|
||||
: d.toLocaleDateString([], { day: 'numeric', month: 'short' })
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import App from './App'
|
||||
import './index.css'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
<StrictMode>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,205 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { DayBars, Legend, TimeLines } from '../components/Charts'
|
||||
import Comparison from '../components/Comparison'
|
||||
import { IssueList } from '../components/Health'
|
||||
import Icon from '../components/Icon'
|
||||
import InverterCard from '../components/InverterCard'
|
||||
import Segmented from '../components/Segmented'
|
||||
import { usePoll } from '../hooks/usePoll'
|
||||
import { api } from '../lib/api'
|
||||
import { seriesColor, useThemeColors } from '../lib/colors'
|
||||
import { energy, energyParts, num, power, powerParts } from '../lib/format'
|
||||
|
||||
function Hero({ summary }) {
|
||||
const t = summary.totals
|
||||
const [pw, pu] = powerParts(t.ac_power_w)
|
||||
const [today, todayU] = energyParts(t.daily_energy_wh)
|
||||
const [life, lifeU] = energyParts(t.total_energy_wh)
|
||||
return (
|
||||
<section className="card p-5">
|
||||
<div className="text-xs font-medium uppercase tracking-wide text-muted">Producing now</div>
|
||||
<div className="mt-1 flex items-baseline gap-2 tnum">
|
||||
<span className="text-5xl font-semibold tracking-tight sm:text-6xl">{pw}</span>
|
||||
<span className="text-xl text-ink-2">{pu}</span>
|
||||
</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>
|
||||
<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>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-xs text-muted">Online</dt>
|
||||
<dd className="tnum">
|
||||
<span className="text-lg font-semibold">{t.online_count}</span>
|
||||
<span className="text-ink-2"> / {t.inverter_count}</span>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function Alerts({ summary }) {
|
||||
const items = summary.inverters.flatMap((st) =>
|
||||
st.health.issues
|
||||
.filter((i) => i.severity !== 'info')
|
||||
.map((i) => ({ ...i, code: `${st.inverter.id}:${i.code}`, message: `${st.inverter.name}: ${i.message}` })),
|
||||
)
|
||||
if (!items.length) return null
|
||||
return (
|
||||
<section aria-label="Problems">
|
||||
<IssueList issues={items} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function DataloggerBanner({ summary }) {
|
||||
if (summary.datalogger.online) return null
|
||||
return (
|
||||
<div className="flex items-start gap-2 rounded-xl bg-[var(--critical-wash)] px-4 py-3 text-sm">
|
||||
<Icon name="offline" size={18} className="mt-px text-crit" />
|
||||
<div>
|
||||
<div className="font-semibold">Site datalogger is not reporting</div>
|
||||
<div className="text-ink-2">
|
||||
Last data {summary.datalogger.last_ingest_at ? new Date(summary.datalogger.last_ingest_at).toLocaleString() : 'never'}.
|
||||
Check the on-site laptop and its internet connection — inverter states below are unknown.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function PowerCard({ ids, names }) {
|
||||
const c = useThemeColors()
|
||||
const { data } = usePoll(() => api.power(), 60_000)
|
||||
const series = ids.map((id) => ({ key: id, name: names[id] ?? id, color: seriesColor(c, ids, id) }))
|
||||
return (
|
||||
<section className="card p-4">
|
||||
<div className="mb-3 flex flex-wrap items-baseline justify-between gap-2">
|
||||
<h2 className="text-sm font-semibold">Power · last 24 h</h2>
|
||||
<Legend series={series} />
|
||||
</div>
|
||||
{data ? (
|
||||
<TimeLines
|
||||
points={data.points}
|
||||
series={series}
|
||||
from={Date.parse(data.from) / 1000}
|
||||
to={Date.parse(data.to) / 1000}
|
||||
bucket={data.bucket}
|
||||
format={power}
|
||||
axisFormat={(w) => num(w / 1000, 0) + ' kW'}
|
||||
showTotal
|
||||
/>
|
||||
) : (
|
||||
<div className="h-60" />
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function EnergyCard({ ids, names }) {
|
||||
const c = useThemeColors()
|
||||
const [mode, setMode] = useState('combined')
|
||||
const { data } = usePoll(() => api.dailyEnergy({ days: 30 }), 300_000)
|
||||
const series =
|
||||
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)
|
||||
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>}
|
||||
</div>
|
||||
<Segmented
|
||||
label="Energy chart mode"
|
||||
value={mode}
|
||||
onChange={setMode}
|
||||
options={[
|
||||
{ value: 'combined', label: 'Combined' },
|
||||
{ value: 'split', label: 'Per inverter' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
{mode === 'split' && (
|
||||
<div className="mb-2">
|
||||
<Legend series={series} />
|
||||
</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>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Dashboard({ summaryPoll }) {
|
||||
const { data: summary, error } = summaryPoll
|
||||
const ids = useMemo(() => summary?.inverters.map((s) => s.inverter.id) ?? [], [summary])
|
||||
const names = useMemo(
|
||||
() => Object.fromEntries(summary?.inverters.map((s) => [s.inverter.id, s.inverter.name]) ?? []),
|
||||
[summary],
|
||||
)
|
||||
|
||||
if (!summary) {
|
||||
return (
|
||||
<div className="py-24 text-center text-sm text-ink-2">
|
||||
{error ? `Can't reach the server: ${error.message}` : 'Loading…'}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!summary.inverters.length) {
|
||||
return (
|
||||
<div className="card mx-auto max-w-md p-6 text-center text-sm text-ink-2">
|
||||
<Icon name="sun" size={28} className="mx-auto mb-2 text-accent" />
|
||||
No inverter has reported yet. Readings appear here as soon as the on-site poller posts to{' '}
|
||||
<code className="text-ink">/api/readings</code>.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<DataloggerBanner summary={summary} />
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,5fr)_minmax(0,7fr)]">
|
||||
<div className="space-y-4">
|
||||
<Hero summary={summary} />
|
||||
<Alerts summary={summary} />
|
||||
<Comparison summary={summary} ids={ids} />
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
<PowerCard ids={ids} names={names} />
|
||||
<EnergyCard ids={ids} names={names} />
|
||||
</div>
|
||||
</div>
|
||||
<section>
|
||||
<h2 className="mb-2 px-1 text-sm font-semibold text-ink-2">Inverters</h2>
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{summary.inverters.map((st) => (
|
||||
<InverterCard key={st.inverter.id} status={st} ids={ids} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
<p className="pb-4 text-center text-xs text-muted">
|
||||
<Link to="/api/docs" reloadDocument className="underline-offset-2 hover:underline">
|
||||
API documentation
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
import { DayBars, Legend, TimeLines } from '../components/Charts'
|
||||
import EditInverterDialog from '../components/EditInverterDialog'
|
||||
import { IssueList, OnlineDot, StatePill } from '../components/Health'
|
||||
import Icon from '../components/Icon'
|
||||
import Segmented from '../components/Segmented'
|
||||
import { usePoll } from '../hooks/usePoll'
|
||||
import { api, isoAgo } from '../lib/api'
|
||||
import { useThemeColors } from '../lib/colors'
|
||||
import { ago, energy, energyParts, num, power, powerParts } from '../lib/format'
|
||||
|
||||
const RANGES = {
|
||||
'24h': { label: '24 h', seconds: 86400 },
|
||||
'7d': { label: '7 days', seconds: 7 * 86400 },
|
||||
'30d': { label: '30 days', seconds: 30 * 86400 },
|
||||
}
|
||||
|
||||
const GROUPS = [
|
||||
{ key: 'ac', label: 'AC output' },
|
||||
{ key: 'dc', label: 'DC input' },
|
||||
{ key: 'energy', label: 'Energy' },
|
||||
{ key: 'device', label: 'Device' },
|
||||
]
|
||||
|
||||
function formatField(field, value) {
|
||||
if (value === null || value === undefined) return '—'
|
||||
if (field.unit === 'Wh') return energy(value)
|
||||
if (field.unit === 'W') return power(value)
|
||||
if (typeof value !== 'number') return String(value)
|
||||
return `${num(value, field.decimals)}${field.unit ? ` ${field.unit}` : ''}`
|
||||
}
|
||||
|
||||
function KeyFigure({ label, parts }) {
|
||||
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>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Parameters({ fields, latest, live }) {
|
||||
const extra = Object.entries(latest?.extra ?? {})
|
||||
return (
|
||||
<section className="card p-4">
|
||||
<h2 className="mb-1 text-sm font-semibold">All parameters</h2>
|
||||
<p className="mb-3 text-xs text-muted">
|
||||
{latest ? `Last reading ${new Date(latest.timestamp).toLocaleString()}` : 'No readings yet'}
|
||||
{latest && !live && ' — values are from the last time it reported'}
|
||||
</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)
|
||||
return (
|
||||
<div key={g.key}>
|
||||
<h3 className="mb-1 text-xs font-semibold uppercase tracking-wide text-muted">{g.label}</h3>
|
||||
<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">
|
||||
<dt className="text-ink-2">{f.label}</dt>
|
||||
<dd className="tnum font-medium">{formatField(f, latest?.[f.key])}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{extra.length > 0 && (
|
||||
<div>
|
||||
<h3 className="mb-1 text-xs font-semibold uppercase tracking-wide text-muted">Other (unmapped)</h3>
|
||||
<dl className="divide-y divide-[var(--border)] text-sm">
|
||||
{extra.map(([k, v]) => (
|
||||
<div key={k} className="flex justify-between gap-4 py-1.5">
|
||||
<dt className="font-mono text-xs text-ink-2">{k}</dt>
|
||||
<dd className="tnum font-medium">{typeof v === 'object' ? JSON.stringify(v) : String(v)}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function HistoryCharts({ id, fields }) {
|
||||
const c = useThemeColors()
|
||||
const [range, setRange] = useState('7d')
|
||||
const [param, setParam] = useState('temperature_c')
|
||||
const seconds = RANGES[range].seconds
|
||||
const { data } = usePoll(() => api.history(id, { from: isoAgo(seconds) }), 120_000, `${id}:${range}`)
|
||||
|
||||
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]
|
||||
const from = data ? Date.parse(data.from) / 1000 : 0
|
||||
const to = data ? Date.parse(data.to) / 1000 : 1
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className="card p-4">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="text-sm font-semibold">Power</h2>
|
||||
<Segmented
|
||||
label="History range"
|
||||
value={range}
|
||||
onChange={setRange}
|
||||
options={Object.entries(RANGES).map(([value, r]) => ({ value, label: r.label }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-2">
|
||||
<Legend series={powerSeries} />
|
||||
</div>
|
||||
{data ? (
|
||||
<TimeLines
|
||||
points={data.points}
|
||||
series={powerSeries}
|
||||
from={from}
|
||||
to={to}
|
||||
bucket={data.bucket}
|
||||
format={power}
|
||||
axisFormat={(w) => num(w / 1000, 0) + ' kW'}
|
||||
/>
|
||||
) : (
|
||||
<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.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="card p-4">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="text-sm font-semibold">{paramField?.label}</h2>
|
||||
<select
|
||||
value={paramField?.key}
|
||||
onChange={(e) => setParam(e.target.value)}
|
||||
className="min-h-9 rounded-lg border border-line bg-surface-2 px-2 text-sm"
|
||||
aria-label="Parameter to chart"
|
||||
>
|
||||
{chartable.map((f) => (
|
||||
<option key={f.key} value={f.key}>
|
||||
{f.label}
|
||||
{f.unit ? ` (${f.unit})` : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{data && paramField ? (
|
||||
<TimeLines
|
||||
points={data.points}
|
||||
series={[{ key: paramField.key, name: paramField.label, color: c.series[0] }]}
|
||||
from={from}
|
||||
to={to}
|
||||
bucket={data.bucket}
|
||||
format={(v) => formatField(paramField, v)}
|
||||
axisFormat={(v) => num(v, paramField.decimals > 1 ? 1 : 0)}
|
||||
height={200}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-52" />
|
||||
)}
|
||||
</section>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
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 ? (
|
||||
<DayBars
|
||||
days={data.days}
|
||||
series={[{ key: 'energy_wh', name: 'Energy', color: c.accent }]}
|
||||
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>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default function InverterDetail({ summaryPoll }) {
|
||||
const { id } = useParams()
|
||||
const { data: summary, refresh } = summaryPoll
|
||||
const { data: fields } = usePoll(() => api.fields(), 3_600_000)
|
||||
const [editing, setEditing] = useState(false)
|
||||
const status = useMemo(() => summary?.inverters.find((s) => s.inverter.id === id), [summary, id])
|
||||
|
||||
if (!summary) return <div className="py-24 text-center text-sm text-ink-2">Loading…</div>
|
||||
if (!status) {
|
||||
return (
|
||||
<div className="py-24 text-center text-sm text-ink-2">
|
||||
Unknown inverter “{id}”.{' '}
|
||||
<Link to="/" className="underline">
|
||||
Back to overview
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
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">
|
||||
<div>
|
||||
<Link to="/" className="-ml-1 inline-flex min-h-9 items-center gap-1 text-sm text-ink-2 hover:text-ink">
|
||||
<Icon name="back" size={16} /> All inverters
|
||||
</Link>
|
||||
<div className="mt-1 flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h1 className="truncate text-2xl font-semibold tracking-tight">{inverter.name}</h1>
|
||||
<div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted">
|
||||
<OnlineDot online={live} />
|
||||
<span>· last reading {ago(latest?.timestamp)}</span>
|
||||
{inverter.capacity_kwp && <span>· {num(inverter.capacity_kwp, 2)} kWp</span>}
|
||||
{inverter.name !== inverter.id && <span>· {inverter.id}</span>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<StatePill state={health.state} size="lg" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing(true)}
|
||||
className="inline-flex min-h-9 items-center gap-1 rounded-lg border border-line px-3 text-sm text-ink-2 hover:text-ink"
|
||||
>
|
||||
<Icon name="edit" size={14} /> Edit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{inverter.notes && <p className="mt-2 text-sm text-ink-2">{inverter.notes}</p>}
|
||||
</div>
|
||||
|
||||
<IssueList issues={health.issues} />
|
||||
|
||||
<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="vs fleet median"
|
||||
parts={[health.relative_output == null ? '—' : num(health.relative_output * 100, 0), '%']}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{fields && <Parameters fields={fields} latest={latest} live={live} />}
|
||||
{fields && <HistoryCharts id={id} fields={fields} />}
|
||||
<YearEnergy id={id} />
|
||||
|
||||
{editing && (
|
||||
<EditInverterDialog
|
||||
inverter={inverter}
|
||||
onClose={() => setEditing(false)}
|
||||
onSaved={() => {
|
||||
setEditing(false)
|
||||
refresh()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import { VitePWA } from 'vite-plugin-pwa'
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.VITE_API_PROXY || 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
manifest: {
|
||||
name: 'Solar Monitor',
|
||||
short_name: 'Solar',
|
||||
description: 'Live status and output of the Refusol inverters',
|
||||
start_url: '/',
|
||||
display: 'standalone',
|
||||
background_color: '#0d0d0d',
|
||||
theme_color: '#0d0d0d',
|
||||
icons: [
|
||||
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png', purpose: 'any' },
|
||||
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' },
|
||||
{ src: '/icons/icon-maskable-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
|
||||
],
|
||||
},
|
||||
workbox: {
|
||||
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
|
||||
// Live data must never come from the cache
|
||||
navigateFallbackDenylist: [/^\/api/],
|
||||
runtimeCaching: [],
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
Reference in New Issue
Block a user