mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-26 19:37:47 +02:00
- Info.WiFi uses json "wf" with omitempty so systems without Wi-Fi no longer store/broadcast "wifi":null - move osascript exec into wifi_darwin.go; drop unused commandRunner - share strongest-connection logic between table cell and sorting - trim agent/wifi README
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
// Package wifi collects only currently associated station interfaces. Collection
|
|
// failures are empty snapshots, never cached connected state.
|
|
package wifi
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"time"
|
|
"unicode/utf8"
|
|
|
|
"github.com/henrygd/beszel/internal/entities/system"
|
|
)
|
|
|
|
// validSSID omits non-UTF-8 SSIDs: 802.11 permits arbitrary octets, but CBOR
|
|
// text strings require UTF-8. Metadata must never invalidate the whole response.
|
|
func validSSID(ssid string) string {
|
|
if !utf8.ValidString(ssid) {
|
|
return ""
|
|
}
|
|
return ssid
|
|
}
|
|
|
|
// Collect uses a single deadline across interface queries where supported.
|
|
// Unsupported platforms and denied association access produce no readings;
|
|
// later polls retry.
|
|
func Collect() map[string]system.WiFi {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
return collect(ctx)
|
|
}
|
|
|
|
// Signals reduces a snapshot to the RSSI values stored in stats history.
|
|
// Interfaces without an available reading are omitted.
|
|
func Signals(snapshot map[string]system.WiFi) map[string]int8 {
|
|
var signals map[string]int8
|
|
for id, reading := range snapshot {
|
|
if reading.Signal == nil {
|
|
continue
|
|
}
|
|
if signals == nil {
|
|
signals = make(map[string]int8, len(snapshot))
|
|
}
|
|
signals[id] = int8(max(math.Round(*reading.Signal), math.MinInt8))
|
|
}
|
|
return signals
|
|
}
|