Initial commit

Made-with: Cursor
This commit is contained in:
Dusan Vojacek
2026-03-20 13:27:37 +01:00
commit 8b4af663d8
77 changed files with 13337 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { useCallback, useEffect, useState } from 'react'
import { getJson } from '../api/postgrest'
import type { SiteStatusRow } from '../types/ems'
const POLL_MS = 5_000
export function useSiteStatus() {
const [row, setRow] = useState<SiteStatusRow | null>(null)
const [ready, setReady] = useState(false)
const load = useCallback(async () => {
try {
const rows = await getJson<SiteStatusRow[]>('/vw_site_status')
setRow(Array.isArray(rows) && rows.length > 0 ? rows[0]! : null)
} catch {
setRow(null)
} finally {
setReady(true)
}
}, [])
useEffect(() => {
void load()
const id = window.setInterval(() => void load(), POLL_MS)
return () => window.clearInterval(id)
}, [load])
const hasTelemetry =
row != null &&
(row.pv_power_w != null ||
row.battery_power_w != null ||
row.grid_power_w != null ||
row.battery_soc_percent != null)
return {
site: row,
ready,
/** Máme řádek lokality a alespoň jednu telemetrickou hodnotu (jinak skeleton). */
hasLiveData: row != null && hasTelemetry,
reload: load,
}
}