Refactor NetworkDevices widget and GetDevices API to simplify device handling and remove interface-based grouping.

This commit is contained in:
2025-12-28 12:49:18 +01:00
parent 79166b344c
commit 598e93c9d2
2 changed files with 23 additions and 43 deletions

View File

@@ -21,35 +21,29 @@ type Device struct {
Online bool `json:"online"`
}
func GetDevices() map[string]map[string]Device {
result := make(map[string]map[string]Device)
func GetDevices() map[string]Device {
result := make(map[string]Device)
devices := make(map[string]Device)
arpDevices := arpDevices()
knownDevices := knownDevices()
for mac, device := range arpDevices {
if strings.HasPrefix(device.Interface, "macvlan") {
continue
}
if strings.HasPrefix(device.Interface, "br") {
continue
}
if known, ok := knownDevices[mac]; ok {
devices[mac] = Device{Name: known.Name, IP: device.IP, Interface: device.Interface, Icon: known.Icon}
devices[mac] = Device{Name: known.Name, IP: device.IP, Icon: known.Icon}
} else {
devices[mac] = device
}
}
for mac, device := range knownDevices {
if _, ok := devices[mac]; !ok {
devices[mac] = Device{Name: device.Name, IP: device.IP, Interface: "_unknown_", Icon: device.Icon}
devices[mac] = Device{Name: device.Name, IP: device.IP, Icon: device.Icon}
}
}
writeDevices(devices)
for mac, device := range devices {
if _, ok := result[device.Interface]; !ok {
result[device.Interface] = make(map[string]Device)
}
if device.Icon == "" {
device.Icon = "\U000F0C8A"
}
@@ -63,7 +57,7 @@ func GetDevices() map[string]map[string]Device {
}
}
}
result[device.Interface][mac] = device
result[mac] = device
}
return result