mirror of
https://github.com/elisspace/core.git
synced 2026-09-30 06:19:55 +00:00
Remove call to deprecated bleak register_detection_callback (#79558)
This commit is contained in:
committed by
Paulus Schoutsen
parent
85c131ed43
commit
b1883609cf
@@ -2,7 +2,7 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import time
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from unittest.mock import ANY, MagicMock, Mock, patch
|
||||
|
||||
from bleak import BleakError
|
||||
from bleak.backends.scanner import AdvertisementData, BLEDevice
|
||||
@@ -114,6 +114,7 @@ async def test_setup_and_stop_passive(hass, mock_bleak_scanner_start, one_adapte
|
||||
"adapter": "hci0",
|
||||
"bluez": scanner.PASSIVE_SCANNER_ARGS,
|
||||
"scanning_mode": "passive",
|
||||
"detection_callback": ANY,
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +162,7 @@ async def test_setup_and_stop_old_bluez(
|
||||
assert init_kwargs == {
|
||||
"adapter": "hci0",
|
||||
"scanning_mode": "active",
|
||||
"detection_callback": ANY,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -174,6 +174,10 @@ async def test_recovery_from_dbus_restart(hass, one_adapter):
|
||||
mock_discovered = []
|
||||
|
||||
class MockBleakScanner:
|
||||
def __init__(self, detection_callback, *args, **kwargs):
|
||||
nonlocal _callback
|
||||
_callback = detection_callback
|
||||
|
||||
async def start(self, *args, **kwargs):
|
||||
"""Mock Start."""
|
||||
nonlocal called_start
|
||||
@@ -190,23 +194,15 @@ async def test_recovery_from_dbus_restart(hass, one_adapter):
|
||||
nonlocal mock_discovered
|
||||
return mock_discovered
|
||||
|
||||
def register_detection_callback(self, callback: AdvertisementDataCallback):
|
||||
"""Mock Register Detection Callback."""
|
||||
nonlocal _callback
|
||||
_callback = callback
|
||||
|
||||
scanner = MockBleakScanner()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.scanner.OriginalBleakScanner",
|
||||
return_value=scanner,
|
||||
MockBleakScanner,
|
||||
):
|
||||
await async_setup_with_one_adapter(hass)
|
||||
|
||||
assert called_start == 1
|
||||
|
||||
start_time_monotonic = time.monotonic()
|
||||
scanner = _get_manager()
|
||||
mock_discovered = [MagicMock()]
|
||||
|
||||
# Ensure we don't restart the scanner if we don't need to
|
||||
|
||||
Reference in New Issue
Block a user