Skip to content

Commit

Permalink
fix: stop trying to get devices from bluez if dbus setup times out (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 12, 2022
1 parent f272bfa commit a8da722
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bleak_retry_connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"NO_RSSI_VALUE",
]

DBUS_CONNECT_TIMEOUT = 8.5

BLEAK_EXCEPTIONS = (AttributeError, BleakError)
BLEAK_RETRY_EXCEPTIONS = (
Expand Down Expand Up @@ -319,7 +320,8 @@ async def _get_properties() -> dict[str, dict[str, dict[str, Any]]] | None:
return None

try:
manager = await get_global_bluez_manager()
async with async_timeout.timeout(DBUS_CONNECT_TIMEOUT):
manager = await get_global_bluez_manager()
return manager._properties
except FileNotFoundError as ex:
setattr(_get_properties, "_has_dbus_socket", False)
Expand All @@ -328,6 +330,11 @@ async def _get_properties() -> dict[str, dict[str, dict[str, Any]]] | None:
ex.filename,
ex,
)
except asyncio.TimeoutError:
setattr(_get_properties, "_has_dbus_socket", False)
_LOGGER.debug(
"Timed out trying to connect to DBus; will not try again until next restart"
)
except Exception as ex: # pylint: disable=broad-except
_LOGGER.debug("get_properties failed: %s", ex, exc_info=True)

Expand Down

0 comments on commit a8da722

Please sign in to comment.