mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 14:08:21 +00:00
Accept advertisements from alternate scanners when a scanner stops scanning (#82448)
This commit is contained in:
@@ -26,7 +26,8 @@ from . import (
|
||||
@pytest.fixture
|
||||
def register_hci0_scanner(hass: HomeAssistant) -> None:
|
||||
"""Register an hci0 scanner."""
|
||||
cancel = bluetooth.async_register_scanner(hass, BaseHaScanner(hass, "hci0"), True)
|
||||
hci0_scanner = BaseHaScanner(hass, "hci0", "hci0")
|
||||
cancel = bluetooth.async_register_scanner(hass, hci0_scanner, True)
|
||||
yield
|
||||
cancel()
|
||||
|
||||
@@ -34,7 +35,8 @@ def register_hci0_scanner(hass: HomeAssistant) -> None:
|
||||
@pytest.fixture
|
||||
def register_hci1_scanner(hass: HomeAssistant) -> None:
|
||||
"""Register an hci1 scanner."""
|
||||
cancel = bluetooth.async_register_scanner(hass, BaseHaScanner(hass, "hci1"), True)
|
||||
hci1_scanner = BaseHaScanner(hass, "hci1", "hci1")
|
||||
cancel = bluetooth.async_register_scanner(hass, hci1_scanner, True)
|
||||
yield
|
||||
cancel()
|
||||
|
||||
@@ -416,7 +418,7 @@ async def test_switching_adapters_when_one_goes_away(
|
||||
):
|
||||
"""Test switching adapters when one goes away."""
|
||||
cancel_hci2 = bluetooth.async_register_scanner(
|
||||
hass, BaseHaScanner(hass, "hci2"), True
|
||||
hass, BaseHaScanner(hass, "hci2", "hci2"), True
|
||||
)
|
||||
|
||||
address = "44:44:33:11:23:45"
|
||||
@@ -460,3 +462,55 @@ async def test_switching_adapters_when_one_goes_away(
|
||||
bluetooth.async_ble_device_from_address(hass, address)
|
||||
is switchbot_device_poor_signal
|
||||
)
|
||||
|
||||
|
||||
async def test_switching_adapters_when_one_stop_scanning(
|
||||
hass, enable_bluetooth, register_hci0_scanner
|
||||
):
|
||||
"""Test switching adapters when stops scanning."""
|
||||
hci2_scanner = BaseHaScanner(hass, "hci2", "hci2")
|
||||
cancel_hci2 = bluetooth.async_register_scanner(hass, hci2_scanner, True)
|
||||
|
||||
address = "44:44:33:11:23:45"
|
||||
|
||||
switchbot_device_good_signal = BLEDevice(address, "wohand_good_signal")
|
||||
switchbot_adv_good_signal = generate_advertisement_data(
|
||||
local_name="wohand_good_signal", service_uuids=[], rssi=-60
|
||||
)
|
||||
inject_advertisement_with_source(
|
||||
hass, switchbot_device_good_signal, switchbot_adv_good_signal, "hci2"
|
||||
)
|
||||
|
||||
assert (
|
||||
bluetooth.async_ble_device_from_address(hass, address)
|
||||
is switchbot_device_good_signal
|
||||
)
|
||||
|
||||
switchbot_device_poor_signal = BLEDevice(address, "wohand_poor_signal")
|
||||
switchbot_adv_poor_signal = generate_advertisement_data(
|
||||
local_name="wohand_poor_signal", service_uuids=[], rssi=-100
|
||||
)
|
||||
inject_advertisement_with_source(
|
||||
hass, switchbot_device_poor_signal, switchbot_adv_poor_signal, "hci0"
|
||||
)
|
||||
|
||||
# We want to prefer the good signal when we have options
|
||||
assert (
|
||||
bluetooth.async_ble_device_from_address(hass, address)
|
||||
is switchbot_device_good_signal
|
||||
)
|
||||
|
||||
hci2_scanner.scanning = False
|
||||
|
||||
inject_advertisement_with_source(
|
||||
hass, switchbot_device_poor_signal, switchbot_adv_poor_signal, "hci0"
|
||||
)
|
||||
|
||||
# Now that hci2 has stopped scanning, we should prefer the poor signal
|
||||
# since poor signal is better than no signal
|
||||
assert (
|
||||
bluetooth.async_ble_device_from_address(hass, address)
|
||||
is switchbot_device_poor_signal
|
||||
)
|
||||
|
||||
cancel_hci2()
|
||||
|
||||
Reference in New Issue
Block a user