Improve performance of Bluetooth device fallback (#79078)
This commit is contained in:
parent
a8b8b245d1
commit
75f6f9b5e2
10 changed files with 155 additions and 24 deletions
|
@ -17,6 +17,7 @@ from bleak.backends.bluezdbus.advertisement_monitor import OrPattern
|
|||
from bleak.backends.bluezdbus.scanner import BlueZScannerArgs
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from bleak_retry_connector import get_device_by_adapter
|
||||
from dbus_fast import InvalidMessageError
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback as hass_callback
|
||||
|
@ -140,6 +141,16 @@ class HaScanner(BaseHaScanner):
|
|||
"""Return a list of discovered devices."""
|
||||
return self.scanner.discovered_devices
|
||||
|
||||
async def async_get_device_by_address(self, address: str) -> BLEDevice | None:
|
||||
"""Get a device by address."""
|
||||
if platform.system() == "Linux":
|
||||
return await get_device_by_adapter(address, self.adapter)
|
||||
# We don't have a fast version of this for MacOS yet
|
||||
return next(
|
||||
(device for device in self.discovered_devices if device.address == address),
|
||||
None,
|
||||
)
|
||||
|
||||
async def async_diagnostics(self) -> dict[str, Any]:
|
||||
"""Return diagnostic information about the scanner."""
|
||||
base_diag = await super().async_diagnostics()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue