From cacb7782db179c57f1997127c15b423ce40c15b1 Mon Sep 17 00:00:00 2001 From: Micha Date: Mon, 6 Apr 2026 07:33:00 +0000 Subject: [PATCH] feat: add immich/backrest/HA entity/UK states to state.js --- apps/dashboard/assets/js/state.js | 154 +++++------------------------- 1 file changed, 26 insertions(+), 128 deletions(-) diff --git a/apps/dashboard/assets/js/state.js b/apps/dashboard/assets/js/state.js index bf99a91..0c33af8 100644 --- a/apps/dashboard/assets/js/state.js +++ b/apps/dashboard/assets/js/state.js @@ -23,140 +23,38 @@ const DEFAULT_DATA = { }, system: { generated_at: new Date().toISOString(), - source: { - name: "beszel", - status: "online", - host_name: "homelab-01", - agent_name: "beszel-agent", - }, - cpu: { usage_percent: 23, cores: 8, load_1: 0.82, load_5: 0.74, load_15: 0.69 }, - memory: { used_gb: 19.6, total_gb: 32, available_gb: 12.4, usage_percent: 61 }, + source: { name: "beszel", status: "online", host_name: "nas", agent_name: "beszel-agent" }, + cpu: { usage_percent: 23, cores: 8, load_1: 0.8, load_5: 0.6, load_15: 0.5 }, + memory: { used_gb: 12.4, total_gb: 32.0, available_gb: 19.6, usage_percent: 38.7 }, network: { primary_interface: "eth0", rx_mbps: 12.4, tx_mbps: 3.1 }, - host: { uptime_seconds: 864000, platform: "linux", kernel: "6.8.0" }, - }, - services: { - generated_at: new Date().toISOString(), - summary: { - overall_status: "degraded", - docker: { running: 18, stopped: 2, unhealthy: 1, total: 20, source_status: "online" }, - uptime_kuma: { monitors_up: 8, monitors_down: 1, monitors_paused: 1, total: 10, source_status: "online" }, - }, - services: [ - { - id: "homeassistant", - name: "Home Assistant", - kind: "core", - status: "online", - health: "healthy", - latency_ms: 142, - docker_state: "running", - url: "#", - source: "home_assistant", - last_checked: new Date().toISOString(), - }, - { - id: "immich", - name: "Immich", - kind: "service", - status: "degraded", - health: "warning", - latency_ms: 821, - docker_state: "running", - url: "#", - source: "uptime_kuma", - last_checked: new Date().toISOString(), - }, - { - id: "gitea", - name: "Gitea", - kind: "service", - status: "online", - health: "healthy", - latency_ms: 98, - docker_state: "running", - url: "#", - source: "uptime_kuma", - last_checked: new Date().toISOString(), - }, - { - id: "adguard", - name: "AdGuard", - kind: "service", - status: "offline", - health: "offline", - latency_ms: null, - docker_state: "stopped", - url: "#", - source: "docker", - last_checked: new Date().toISOString(), - }, - ], + host: { uptime_seconds: 864000, platform: "linux", kernel: "6.1.0" }, }, storage: { generated_at: new Date().toISOString(), - summary: { overall_status: "degraded", critical_disks: 0, warning_disks: 1, total_disks: 3 }, - root: { name: "rootfs", mount: "/", used_gb: 233.8, total_gb: 480, free_gb: 246.2, usage_percent: 48.7, status: "online" }, - disks: [ - { name: "rootfs", mount: "/", used_gb: 233.8, total_gb: 480, free_gb: 246.2, usage_percent: 48.7, status: "online" }, - { name: "data", mount: "/data", used_gb: 712.1, total_gb: 1000, free_gb: 287.9, usage_percent: 71.2, status: "warning" }, - { name: "backup", mount: "/backup", used_gb: 201.4, total_gb: 2000, free_gb: 1798.6, usage_percent: 10.1, status: "online" }, - ], + summary: { total_used_gb: 2048, total_size_gb: 8192, total_free_gb: 6144, overall_usage_percent: 25 }, + disks: [], }, - adguard: { - source_name: "adguard", - source_status: "offline", - total_queries: 0, - blocked_queries: 0, - blocked_percent: 0, - avg_processing_ms: 0, - }, - scrutiny: { - source_name: "scrutiny", - source_status: "offline", - overall_status: "offline", - devices: [], - failed_count: 0, - total_count: 0, + services: { + generated_at: new Date().toISOString(), + summary: { overall_status: "online", total: 11, online: 8, degraded: 2, offline: 1 }, + docker: { running: 18, stopped: 2, unhealthy: 1, total: 20, source_status: "online" }, + uptime_kuma: { monitors_up: 8, monitors_down: 1, source_status: "online" }, + items: [], }, + adguard: { source_name: "adguard", source_status: "offline", total_queries: 0, blocked_queries: 0, blocked_percent: 0, avg_processing_ms: 0 }, + scrutiny: { source_name: "scrutiny", source_status: "offline", overall_status: "offline", devices: [], failed_count: 0, total_count: 0 }, + immich: { source_name: "immich", source_status: "offline", photos: 0, videos: 0, storage_gb: 0 }, + backrest: { source_name: "backrest", source_status: "offline", repo_count: 0, last_backup_age_hours: null, last_backup_status: "unknown", error_count: 0 }, + home_assistant: { source_name: "home_assistant", status: "offline", version: null, lights_on: 0, lights_total: 0, climate_active: 0, doors_open: 0, alerts: 0 }, + uptime_kuma: { source_name: "uptime_kuma", source_status: "offline", monitors_up: 0, monitors_down: 0, monitors_paused: 0, total: 0, monitors: [] }, }; -const listeners = new Set(); +let _state = structuredClone(DEFAULT_DATA); +const _subscribers = []; -const state = { - data: structuredClone(DEFAULT_DATA), - isLoading: true, - error: null, - lastRefreshAt: null, - refreshIntervalMs: 20000, -}; - -export function subscribe(listener) { - listeners.add(listener); - listener(state); - return () => listeners.delete(listener); -} - -export function getState() { - return state; -} - -export function updateData(payload) { - state.data = payload; - state.isLoading = false; - state.error = null; - state.lastRefreshAt = new Date(); - state.refreshIntervalMs = Math.max((payload?.overview?.refresh_hint_seconds ?? 20) * 1000, 15000); - emit(); -} - -export function setError(error) { - state.isLoading = false; - state.error = error; - emit(); -} - -function emit() { - for (const listener of listeners) { - listener(state); - } -} +export function getState() { return _state; } +export function subscribe(fn) { _subscribers.push(fn); } +export function updateData(partial) { + _state = { ..._state, ...partial }; + _subscribers.forEach((fn) => fn(_state)); +} \ No newline at end of file