From 71f9ab3f198de5f51f212625ef5ed05854719967 Mon Sep 17 00:00:00 2001 From: Lilian <30466471+hlxid@users.noreply.github.com> Date: Thu, 1 Aug 2024 22:18:11 +0200 Subject: [PATCH] Remove redundant BLE service UUID check as it is already done using a ScanFilter --- src/ble.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/ble.rs b/src/ble.rs index b8c4264..3af8408 100644 --- a/src/ble.rs +++ b/src/ble.rs @@ -71,22 +71,15 @@ impl Device { } async fn from_peripheral(peripheral: Peripheral) -> Option { - // Check whether the BLE device has the service UUID we're looking for - // and also the correct name. - // The service uuid is also by devices that are not LED badges, so - // the name check is also necessary. + // The existance of the service with the correct UUID + // exists is already checked by the scan filter. + // But we also need to check the device name to make sure + // we're talking to a badge as some devices that are not led badges + // also use the same service UUID. let props = peripheral.properties().await.ok()??; - let local_name = props.local_name.as_ref()?; - if local_name != BADGE_BLE_DEVICE_NAME { - return None; - } - if props - .services - .iter() - .any(|uuid| *uuid == BADGE_SERVICE_UUID) - { + if local_name == BADGE_BLE_DEVICE_NAME { Some(Self { peripheral }) } else { None