Pass scanner mode to shelly Bluetooth scanner (#140689)

habluetooth will eventually be able to make better decisions
on how to route data based on the scanning mode.
This commit is contained in:
J. Nick Koston 2025-03-15 12:00:23 -10:00 committed by GitHub
parent 76244e0d6b
commit d69bcc02b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View File

@ -7,7 +7,10 @@ from typing import TYPE_CHECKING
from aioshelly.ble import async_start_scanner, create_scanner
from aioshelly.ble.const import BLE_SCAN_RESULT_EVENT, BLE_SCAN_RESULT_VERSION
from homeassistant.components.bluetooth import async_register_scanner
from homeassistant.components.bluetooth import (
BluetoothScanningMode,
async_register_scanner,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback as hass_callback
from ..const import BLEScannerMode
@ -15,6 +18,11 @@ from ..const import BLEScannerMode
if TYPE_CHECKING:
from ..coordinator import ShellyRpcCoordinator
BLE_SCANNER_MODE_TO_BLUETOOTH_SCANNING_MODE = {
BLEScannerMode.PASSIVE: BluetoothScanningMode.PASSIVE,
BLEScannerMode.ACTIVE: BluetoothScanningMode.ACTIVE,
}
async def async_connect_scanner(
hass: HomeAssistant,
@ -25,7 +33,13 @@ async def async_connect_scanner(
"""Connect scanner."""
device = coordinator.device
entry = coordinator.config_entry
scanner = create_scanner(coordinator.bluetooth_source, entry.title)
bluetooth_scanning_mode = BLE_SCANNER_MODE_TO_BLUETOOTH_SCANNING_MODE[scanner_mode]
scanner = create_scanner(
coordinator.bluetooth_source,
entry.title,
requested_mode=bluetooth_scanning_mode,
current_mode=bluetooth_scanning_mode,
)
unload_callbacks = [
async_register_scanner(
hass,

View File

@ -109,8 +109,14 @@ async def test_rpc_config_entry_diagnostics(
"bluetooth": {
"scanner": {
"connectable": False,
"current_mode": None,
"requested_mode": None,
"current_mode": {
"__type": "<enum 'BluetoothScanningMode'>",
"repr": "<BluetoothScanningMode.ACTIVE: 'active'>",
},
"requested_mode": {
"__type": "<enum 'BluetoothScanningMode'>",
"repr": "<BluetoothScanningMode.ACTIVE: 'active'>",
},
"discovered_device_timestamps": {"AA:BB:CC:DD:EE:FF": ANY},
"discovered_devices_and_advertisement_data": [
{