Skip to content

Commit 297c269

Browse files
authored
fix: increase rssi switch threshold for advertisements (#110)
1 parent 9d0bca8 commit 297c269

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/habluetooth/const.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@
5353

5454

5555
FAILED_ADAPTER_MAC = "00:00:00:00:00:00"
56+
57+
58+
ADV_RSSI_SWITCH_THRESHOLD: Final = 10
59+
# The switch threshold for the rssi value
60+
# to switch to a different adapter for advertisements
61+
# Note that this does not affect the connection
62+
# selection that uses RSSI_SWITCH_THRESHOLD from
63+
# bleak_retry_connector

src/habluetooth/manager.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from .base_scanner cimport BaseHaScanner
55
from .models cimport BluetoothServiceInfoBleak
66

77
cdef int NO_RSSI_VALUE
8-
cdef int RSSI_SWITCH_THRESHOLD
8+
cdef int ADV_RSSI_SWITCH_THRESHOLD
99
cdef double TRACKER_BUFFERING_WOBBLE_SECONDS
1010
cdef double FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
1111
cdef object FILTER_UUIDS

src/habluetooth/manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import TYPE_CHECKING, Any, Final
1111

1212
from bleak.backends.scanner import AdvertisementDataCallback
13-
from bleak_retry_connector import NO_RSSI_VALUE, RSSI_SWITCH_THRESHOLD, BleakSlotManager
13+
from bleak_retry_connector import NO_RSSI_VALUE, BleakSlotManager
1414
from bluetooth_adapters import (
1515
ADAPTER_ADDRESS,
1616
ADAPTER_PASSIVE_SCAN,
@@ -24,6 +24,7 @@
2424
AdvertisementTracker,
2525
)
2626
from .const import (
27+
ADV_RSSI_SWITCH_THRESHOLD,
2728
CALLBACK_TYPE,
2829
FAILED_ADAPTER_MAC,
2930
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS,
@@ -430,10 +431,10 @@ def _prefer_previous_adv_from_different_source(
430431
stale_seconds,
431432
)
432433
return False
433-
if (new.rssi or NO_RSSI_VALUE) - RSSI_SWITCH_THRESHOLD > (
434+
if (new.rssi or NO_RSSI_VALUE) - ADV_RSSI_SWITCH_THRESHOLD > (
434435
old.rssi or NO_RSSI_VALUE
435436
):
436-
# If new advertisement is RSSI_SWITCH_THRESHOLD more,
437+
# If new advertisement is ADV_RSSI_SWITCH_THRESHOLD more,
437438
# the new one is preferred.
438439
if self._debug:
439440
_LOGGER.debug(
@@ -446,7 +447,7 @@ def _prefer_previous_adv_from_different_source(
446447
self._async_describe_source(old),
447448
self._async_describe_source(new),
448449
new.rssi,
449-
RSSI_SWITCH_THRESHOLD,
450+
ADV_RSSI_SWITCH_THRESHOLD,
450451
old.rssi,
451452
)
452453
return False

0 commit comments

Comments
 (0)