mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-01 05:47:48 +02:00
feat: monitor connected Wi-Fi signal per interface (#2367)
This commit is contained in:
20
internal/site/src/lib/wifi.ts
Normal file
20
internal/site/src/lib/wifi.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { SystemRecord, WiFi } from "@/types"
|
||||
|
||||
// Current system info is independent of the selected historical chart window.
|
||||
// No fallback to history: missing data, disconnect and offline all hide the panel.
|
||||
export function connectedWiFi(system: Pick<SystemRecord, "status" | "info">): [string, WiFi][] {
|
||||
return system.status === "up" ? Object.entries(system.info?.wifi ?? {}).sort(([a], [b]) => a.localeCompare(b)) : []
|
||||
}
|
||||
|
||||
export function strongestWiFiSignal(system: Pick<SystemRecord, "status" | "info">): number | undefined {
|
||||
const signals = connectedWiFi(system)
|
||||
.map(([, wifi]) => wifi.r)
|
||||
.filter((signal): signal is number => signal !== undefined && Number.isFinite(signal))
|
||||
return signals.length ? Math.max(...signals) : undefined
|
||||
}
|
||||
|
||||
export function wifiColor(id: string): string {
|
||||
let hash = 0
|
||||
for (const char of id) hash = (Math.imul(hash, 31) + char.charCodeAt(0)) | 0
|
||||
return `hsl(${(hash >>> 0) % 360}, 65%, 52%)`
|
||||
}
|
||||
Reference in New Issue
Block a user