fix: setting BLE device name once services are enumerated

This commit is contained in:
evilsocket 2019-03-17 13:36:59 +01:00
commit d6e6746809
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 14 additions and 3 deletions

View file

@ -28,6 +28,7 @@ type BLEService struct {
type BLEDevice struct {
LastSeen time.Time
DeviceName string
Vendor string
RSSI int
Device gatt.Peripheral
@ -62,9 +63,15 @@ func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice
}
func (d *BLEDevice) Name() string {
name := d.Device.Name()
if name == "" && d.Advertisement != nil {
name = d.Advertisement.LocalName
// get the name if it's being set during services enumeration via 'Device Name'
name := d.DeviceName
if name == "" {
// get the name from the device
name := d.Device.Name()
if name == "" && d.Advertisement != nil {
// get the name from the advertisement data
name = d.Advertisement.LocalName
}
}
return name
}