feat: add immich/backrest/HA entity/UK states to state.js

This commit is contained in:
2026-04-06 07:33:00 +00:00
parent af602723d0
commit cacb7782db
+26 -128
View File
@@ -23,140 +23,38 @@ const DEFAULT_DATA = {
}, },
system: { system: {
generated_at: new Date().toISOString(), generated_at: new Date().toISOString(),
source: { source: { name: "beszel", status: "online", host_name: "nas", agent_name: "beszel-agent" },
name: "beszel", cpu: { usage_percent: 23, cores: 8, load_1: 0.8, load_5: 0.6, load_15: 0.5 },
status: "online", memory: { used_gb: 12.4, total_gb: 32.0, available_gb: 19.6, usage_percent: 38.7 },
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 },
network: { primary_interface: "eth0", rx_mbps: 12.4, tx_mbps: 3.1 }, network: { primary_interface: "eth0", rx_mbps: 12.4, tx_mbps: 3.1 },
host: { uptime_seconds: 864000, platform: "linux", kernel: "6.8.0" }, host: { uptime_seconds: 864000, platform: "linux", kernel: "6.1.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(),
},
],
}, },
storage: { storage: {
generated_at: new Date().toISOString(), generated_at: new Date().toISOString(),
summary: { overall_status: "degraded", critical_disks: 0, warning_disks: 1, total_disks: 3 }, summary: { total_used_gb: 2048, total_size_gb: 8192, total_free_gb: 6144, overall_usage_percent: 25 },
root: { name: "rootfs", mount: "/", used_gb: 233.8, total_gb: 480, free_gb: 246.2, usage_percent: 48.7, status: "online" }, disks: [],
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" },
],
}, },
adguard: { services: {
source_name: "adguard", generated_at: new Date().toISOString(),
source_status: "offline", summary: { overall_status: "online", total: 11, online: 8, degraded: 2, offline: 1 },
total_queries: 0, docker: { running: 18, stopped: 2, unhealthy: 1, total: 20, source_status: "online" },
blocked_queries: 0, uptime_kuma: { monitors_up: 8, monitors_down: 1, source_status: "online" },
blocked_percent: 0, items: [],
avg_processing_ms: 0,
},
scrutiny: {
source_name: "scrutiny",
source_status: "offline",
overall_status: "offline",
devices: [],
failed_count: 0,
total_count: 0,
}, },
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 = { export function getState() { return _state; }
data: structuredClone(DEFAULT_DATA), export function subscribe(fn) { _subscribers.push(fn); }
isLoading: true, export function updateData(partial) {
error: null, _state = { ..._state, ...partial };
lastRefreshAt: null, _subscribers.forEach((fn) => fn(_state));
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);
}
}