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:
parent
bbb652304e
commit
eaba29657f
1 changed files with 12 additions and 7 deletions
|
@ -60,13 +60,18 @@ def is_bluetooth_device(device: Device) -> bool:
|
||||||
|
|
||||||
def discover_devices(device_id: int) -> list[tuple[str, str]]:
|
def discover_devices(device_id: int) -> list[tuple[str, str]]:
|
||||||
"""Discover Bluetooth devices."""
|
"""Discover Bluetooth devices."""
|
||||||
result = bluetooth.discover_devices(
|
try:
|
||||||
duration=8,
|
result = bluetooth.discover_devices(
|
||||||
lookup_names=True,
|
duration=8,
|
||||||
flush_cache=True,
|
lookup_names=True,
|
||||||
lookup_class=False,
|
flush_cache=True,
|
||||||
device_id=device_id,
|
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))
|
_LOGGER.debug("Bluetooth devices discovered = %d", len(result))
|
||||||
return result # type: ignore[no-any-return]
|
return result # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue