Skip to content

Commit

Permalink
fix: 12.3 (21E230) MacOs version
Browse files Browse the repository at this point in the history
Signed-off-by: o98k-ok <[email protected]>
  • Loading branch information
o98k-ok committed Mar 16, 2022
1 parent b26acce commit 75ca0ac
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions system/bluetooth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,34 @@ func GetAllBlueTooth() []models.BlueToothDevice {
res := make([]models.BlueToothDevice, 0, 3)

for _, dataType := range dataTypes {
deviceAll := dataType.(map[string]interface{})["devices_list"]
for _, device := range deviceAll.([]interface{}) {
for name, d := range device.(map[string]interface{}) {
info := d.(map[string]interface{})
res = append(res, FilterDevice(dataType.(map[string]interface{}), "device_connected")...)
res = append(res, FilterDevice(dataType.(map[string]interface{}), "device_not_connected")...)
}
return res
}

device := models.BlueToothDevice{
Name: name,
Addr: strings.Replace(AsString(info, "device_address"), ":", "-", -1),
BatteryLevel: GetBattery(info),
Product: AsString(info, "device_minorType"),
Status: AsString(info, "device_connected") == "Yes",
}
if device.Product != "" {
res = append(res, device)
}
}
func FilterDevice(dataType map[string]interface{}, key string) []models.BlueToothDevice {
res := make([]models.BlueToothDevice, 0, 3)

devices, ok := dataType[key].([]interface{})
if !ok {
return res
}

for _, device := range devices {
for name, d := range device.(map[string]interface{}) {
info := d.(map[string]interface{})

device := models.BlueToothDevice{
Name: name,
Addr: strings.Replace(AsString(info, "device_address"), ":", "-", -1),
BatteryLevel: GetBattery(info),
Product: AsString(info, "device_minorType"),
Status: key == "device_connected",
}
if device.Product != "" {
res = append(res, device)
}
}
}
return res
Expand Down

0 comments on commit 75ca0ac

Please sign in to comment.