Skip to content

Commit a202c60

Browse files
authored
Improve reliability by adding missing exceptions to the retry list (#204)
1 parent 3513691 commit a202c60

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

switchbot/devices/device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from uuid import UUID
1212

1313
import async_timeout
14-
from bleak import BleakError
1514
from bleak.backends.device import BLEDevice
1615
from bleak.backends.service import BleakGATTCharacteristic, BleakGATTServiceCollection
1716
from bleak.exc import BleakDBusError
@@ -40,6 +39,7 @@
4039
# Base key when encryption is set
4140
KEY_PASSWORD_PREFIX = "571"
4241

42+
DBUS_ERROR_BACKOFF_TIME = 0.25
4343

4444
# How long to hold the connection
4545
# to wait for additional commands for
@@ -383,7 +383,7 @@ async def _execute_disconnect_with_lock(self) -> None:
383383
_LOGGER.debug("%s: Disconnecting", self.name)
384384
try:
385385
await client.disconnect()
386-
except BleakError as ex:
386+
except BLEAK_RETRY_EXCEPTIONS as ex:
387387
_LOGGER.warning(
388388
"%s: Error disconnecting: %s; RSSI: %s",
389389
self.name,
@@ -399,17 +399,17 @@ async def _send_command_locked(self, key: str, command: bytes) -> bytes:
399399
return await self._execute_command_locked(key, command)
400400
except BleakDBusError as ex:
401401
# Disconnect so we can reset state and try again
402-
await asyncio.sleep(0.25)
402+
await asyncio.sleep(DBUS_ERROR_BACKOFF_TIME)
403403
_LOGGER.debug(
404404
"%s: RSSI: %s; Backing off %ss; Disconnecting due to error: %s",
405405
self.name,
406406
self.rssi,
407-
0.25,
407+
DBUS_ERROR_BACKOFF_TIME,
408408
ex,
409409
)
410410
await self._execute_forced_disconnect()
411411
raise
412-
except BleakError as ex:
412+
except BLEAK_RETRY_EXCEPTIONS as ex:
413413
# Disconnect so we can reset state and try again
414414
_LOGGER.debug(
415415
"%s: RSSI: %s; Disconnecting due to error: %s", self.name, self.rssi, ex

0 commit comments

Comments
 (0)