mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 05:05:09 +02:00
Catch bluetooth_tracker OSError (#60437)
Catch when bluetooth_tracker integration throws an OSError when a bluetooth device can't be found.
This commit is contained in:
@@ -60,6 +60,7 @@ def is_bluetooth_device(device: Device) -> bool:
|
||||
|
||||
def discover_devices(device_id: int) -> list[tuple[str, str]]:
|
||||
"""Discover Bluetooth devices."""
|
||||
try:
|
||||
result = bluetooth.discover_devices(
|
||||
duration=8,
|
||||
lookup_names=True,
|
||||
@@ -67,6 +68,10 @@ def discover_devices(device_id: int) -> list[tuple[str, str]]:
|
||||
lookup_class=False,
|
||||
device_id=device_id,
|
||||
)
|
||||
except OSError as ex:
|
||||
# OSError is generally thrown if a bluetooth device isn't found
|
||||
_LOGGER.error("Couldn't discover bluetooth devices: %s", ex)
|
||||
return []
|
||||
_LOGGER.debug("Bluetooth devices discovered = %d", len(result))
|
||||
return result # type: ignore[no-any-return]
|
||||
|
||||
|
Reference in New Issue
Block a user