Refactor NetworkDevices widget and GetDevices API to simplify device handling and remove interface-based grouping.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user