Skip to content

Commit

Permalink
feat: small speed ups to scanner detection callback (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 26, 2024
1 parent d58ce2b commit 7a5129a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/habluetooth/scanner.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from .models cimport BluetoothServiceInfoBleak
cdef object NO_RSSI_VALUE
cdef object AdvertisementData
cdef object BLEDevice

cdef bint TYPE_CHECKING


Expand Down
22 changes: 11 additions & 11 deletions src/habluetooth/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 7a5129a

Please sign in to comment.