mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
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:
parent
76244e0d6b
commit
d69bcc02b0
@ -7,7 +7,10 @@ from typing import TYPE_CHECKING
|
|||||||
from aioshelly.ble import async_start_scanner, create_scanner
|
from aioshelly.ble import async_start_scanner, create_scanner
|
||||||
from aioshelly.ble.const import BLE_SCAN_RESULT_EVENT, BLE_SCAN_RESULT_VERSION
|
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 homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback as hass_callback
|
||||||
|
|
||||||
from ..const import BLEScannerMode
|
from ..const import BLEScannerMode
|
||||||
@ -15,6 +18,11 @@ from ..const import BLEScannerMode
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..coordinator import ShellyRpcCoordinator
|
from ..coordinator import ShellyRpcCoordinator
|
||||||
|
|
||||||
|
BLE_SCANNER_MODE_TO_BLUETOOTH_SCANNING_MODE = {
|
||||||
|
BLEScannerMode.PASSIVE: BluetoothScanningMode.PASSIVE,
|
||||||
|
BLEScannerMode.ACTIVE: BluetoothScanningMode.ACTIVE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_connect_scanner(
|
async def async_connect_scanner(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -25,7 +33,13 @@ async def async_connect_scanner(
|
|||||||
"""Connect scanner."""
|
"""Connect scanner."""
|
||||||
device = coordinator.device
|
device = coordinator.device
|
||||||
entry = coordinator.config_entry
|
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 = [
|
unload_callbacks = [
|
||||||
async_register_scanner(
|
async_register_scanner(
|
||||||
hass,
|
hass,
|
||||||
|
@ -109,8 +109,14 @@ async def test_rpc_config_entry_diagnostics(
|
|||||||
"bluetooth": {
|
"bluetooth": {
|
||||||
"scanner": {
|
"scanner": {
|
||||||
"connectable": False,
|
"connectable": False,
|
||||||
"current_mode": None,
|
"current_mode": {
|
||||||
"requested_mode": None,
|
"__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_device_timestamps": {"AA:BB:CC:DD:EE:FF": ANY},
|
||||||
"discovered_devices_and_advertisement_data": [
|
"discovered_devices_and_advertisement_data": [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user