1111from uuid import UUID
1212
1313import async_timeout
14- from bleak import BleakError
1514from bleak .backends .device import BLEDevice
1615from bleak .backends .service import BleakGATTCharacteristic , BleakGATTServiceCollection
1716from bleak .exc import BleakDBusError
4039# Base key when encryption is set
4140KEY_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