From 6b28d16ccfed4e9e1a488a6310044c9352db2949 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 29 Apr 2023 23:34:24 +0200 Subject: [PATCH] Exclude more noisy Bluetooth beacons. Exclude any beacons from devices with no name, no children other than services, and with none of those services being public/known. --- platypush/plugins/bluetooth/_ble/_event_handler.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/bluetooth/_ble/_event_handler.py b/platypush/plugins/bluetooth/_ble/_event_handler.py index c68a90cb6c..eb03bd14f6 100644 --- a/platypush/plugins/bluetooth/_ble/_event_handler.py +++ b/platypush/plugins/bluetooth/_ble/_event_handler.py @@ -89,7 +89,7 @@ event_matchers: Dict[ and _has_been_set(old, new, 'connected', False), BluetoothDeviceFoundEvent: lambda old, new: old is None or (old.reachable is False and new.reachable is True), - BluetoothDeviceSignalUpdateEvent: lambda old, new: ( + BluetoothDeviceSignalUpdateEvent: lambda old, new: ( # type: ignore (new.rssi is not None or new.tx_power is not None) and bool(old and old.rssi) and ( @@ -183,7 +183,7 @@ class EventHandler: get_bus().post(event) if events: - new_entity.reachable = True + new_entity.reachable = True # type: ignore self._device_queue.put_nowait(new_entity) @staticmethod @@ -218,6 +218,14 @@ class EventHandler: if any(not isinstance(child, BluetoothService) for child in device.children): return False + # If the device's only children are unknown services, skip it + if not any( + isinstance(child, BluetoothService) + and child.service_class != ServiceClass.UNKNOWN + for child in device.children + ): + return True + mapped_uuids = [ int(str(srv.uuid).split('-', maxsplit=1)[0], 16) & 0xFFFF if isinstance(srv.uuid, UUID)