Skip to content

Commit

Permalink
[bluetooth] Notify things again when they are removed from listeners …
Browse files Browse the repository at this point in the history
…like Inbox

Signed-off-by: Peter Rosenberg <prosenb.dev@gmail.com>
  • Loading branch information
PRosenb committed Feb 17, 2021
1 parent b700335 commit f7054c5
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = null;
});
removeOlderResults(getTimestampOfLastScan());
}

Expand Down Expand Up @@ -296,6 +303,9 @@ private void publishDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult re

private void retractDiscoveryResult(BluetoothAdapter adapter, DiscoveryResult result) {
Set<DiscoveryResult> 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 = null;
if (results != null) {
for (DiscoveryResult r : results) {
thingRemoved(r.getThingUID());
Expand Down

0 comments on commit f7054c5

Please sign in to comment.