From 7a5129a40a12382c089453880210c41bb0f28a32 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 26 Jul 2024 18:57:16 -0500 Subject: [PATCH] feat: small speed ups to scanner detection callback (#55) --- src/habluetooth/scanner.pxd | 1 + src/habluetooth/scanner.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/habluetooth/scanner.pxd b/src/habluetooth/scanner.pxd index 91c8937..c5c5a32 100644 --- a/src/habluetooth/scanner.pxd +++ b/src/habluetooth/scanner.pxd @@ -7,6 +7,7 @@ from .models cimport BluetoothServiceInfoBleak cdef object NO_RSSI_VALUE cdef object AdvertisementData cdef object BLEDevice + cdef bint TYPE_CHECKING diff --git a/src/habluetooth/scanner.py b/src/habluetooth/scanner.py index f130030..d1da3c8 100644 --- a/src/habluetooth/scanner.py +++ b/src/habluetooth/scanner.py @@ -224,17 +224,17 @@ def _async_detection_callback( central manager. """ callback_time = monotonic_time_coarse() - if ( - advertisement_data.local_name - or advertisement_data.manufacturer_data - or advertisement_data.service_data - or advertisement_data.service_uuids - ): + address = device.address + local_name = advertisement_data.local_name + manufacturer_data = advertisement_data.manufacturer_data + service_data = advertisement_data.service_data + service_uuids = advertisement_data.service_uuids + if local_name or manufacturer_data or service_data or service_uuids: # Don't count empty advertisements # as the adapter is in a failure # state if all the data is empty. self._last_detection = callback_time - name = advertisement_data.local_name or device.name or device.address + name = local_name or device.name or address if name is not None and type(name) is not str: name = str(name) tx_power = advertisement_data.tx_power @@ -243,11 +243,11 @@ def _async_detection_callback( self._manager.scanner_adv_received( BluetoothServiceInfoBleak( name, - device.address, + address, advertisement_data.rssi, - advertisement_data.manufacturer_data, - advertisement_data.service_data, - advertisement_data.service_uuids, + manufacturer_data, + service_data, + service_uuids, self.source, device, advertisement_data,