Skip to content

Commit

Permalink
Merge pull request #848 from AskBojesen/828_null_in_devicelist_windows
Browse files Browse the repository at this point in the history
Windows: Fixed null entries in DiscoveredDevices  #828
  • Loading branch information
janusw committed May 11, 2024
2 parents a5f8e6c + 5d152a0 commit 18d5e3f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Source/Plugin.BLE/Windows/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,14 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
{
var deviceId = btAdv.BluetoothAddress.ParseDeviceId();

if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device) && device != null)
if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device))
{
// This deviceId has been discovered
Trace.Message("AdvReceived - Old: {0}", btAdv.ToDetailedString(device.Name));
(device as Device)?.Update(btAdv.RawSignalStrengthInDBm, ParseAdvertisementData(btAdv.Advertisement));
this.HandleDiscoveredDevice(device);
HandleDiscoveredDevice(device);
}
if (device == null)
else
{
var bluetoothLeDevice = BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress).AsTask().Result;
if (bluetoothLeDevice != null) //make sure advertisement bluetooth address actually returns a device
Expand All @@ -285,12 +286,7 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
ParseAdvertisementData(btAdv.Advertisement),
btAdv.IsConnectable);
Trace.Message("AdvReceived - New: {0}", btAdv.ToDetailedString(device.Name));
_ = DiscoveredDevicesRegistry.TryRemove(deviceId, out _);
this.HandleDiscoveredDevice(device);
}
else
{
DiscoveredDevicesRegistry[deviceId] = null;
HandleDiscoveredDevice(device);
}
}
}
Expand Down

0 comments on commit 18d5e3f

Please sign in to comment.