From 4cda3ad7f54974d62dd61528ddf4b39d8883f63d Mon Sep 17 00:00:00 2001 From: Peter Rosenberg Date: Wed, 13 Jan 2021 15:33:38 +0100 Subject: [PATCH] [bluetooth] Notify things again when they are removed from listeners like Inbox Signed-off-by: Peter Rosenberg --- .../discovery/internal/BluetoothDiscoveryService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java index af31f910b25e9..5a156ddad1a1e 100644 --- a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java +++ b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java @@ -133,6 +133,13 @@ public void stopScan() { for (BluetoothAdapter adapter : adapters) { adapter.scanStop(); } + + // The method `removeOlderResults()` removes the Things from listeners like `Inbox`. + // We therefore need to reset `latestSnapshot` so that the Things are notified again next time. + // Results newer than `getTimestampOfLastScan()` will also be notified again but do not lead to duplicates. + discoveryCaches.values().forEach(discoveryCache -> { + discoveryCache.latestSnapshot.putValue(null); + }); removeOlderResults(getTimestampOfLastScan()); } @@ -296,6 +303,9 @@ private void publishDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult re private void retractDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult result) { Set results = discoveryResults.remove(adapter); + // The method `thingRemoved()` removes the Thing from listeners like `Inbox`. + // We therefore need to reset `latestSnapshot` so that the Thing is notified again next time. + latestSnapshot.putValue(null); if (results != null) { for (DiscoveryResult r : results) { thingRemoved(r.getThingUID());