]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth.bluez] Fix the unpairing of all devices on binding disposal (#9011)
authorBenjamin Lafois <benjamin.lafois@gmail.com>
Sat, 28 Nov 2020 14:59:39 +0000 (15:59 +0100)
committerGitHub <noreply@github.com>
Sat, 28 Nov 2020 14:59:39 +0000 (15:59 +0100)
Signed-off-by: Benjamin Lafois <benjamin.lafois@gmail.com>
bundles/org.openhab.binding.bluetooth.bluez/src/main/java/org/openhab/binding/bluetooth/bluez/internal/BlueZBluetoothDevice.java

index af80f79d2f12a77fa67eaf27e706a371fb7c7622..86a134823cd9d4987c2c4ce797567497c5564f0a 100644 (file)
@@ -120,6 +120,10 @@ public class BlueZBluetoothDevice extends BaseBluetoothDevice implements BlueZEv
     public void dispose() {
         BluetoothDevice dev = device;
         if (dev != null) {
+            if (Boolean.TRUE.equals(dev.isPaired())) {
+                return;
+            }
+
             try {
                 dev.getAdapter().removeDevice(dev.getRawDevice());
             } catch (DBusException ex) {
@@ -359,8 +363,10 @@ public class BlueZBluetoothDevice extends BaseBluetoothDevice implements BlueZEv
         }
         BluetoothCharacteristic c = getCharacteristic(UUID.fromString(characteristic.getUuid()));
         if (c != null) {
-            c.setValue(event.getData());
-            notifyListeners(BluetoothEventType.CHARACTERISTIC_UPDATED, c, BluetoothCompletionStatus.SUCCESS);
+            synchronized (c) {
+                c.setValue(event.getData());
+                notifyListeners(BluetoothEventType.CHARACTERISTIC_UPDATED, c, BluetoothCompletionStatus.SUCCESS);
+            }
         }
     }