code: def wrap_exception(func: Callable) -> Callable:
      
      try:
          # only do the wrapping if bluepy is installed.
          # otherwise it's pointless anyway
          from bluepy.btle import BTLEException
      except ImportError:
          return func
  
      def _func_wrapper(*args, **kwargs):
          error_count = 0
          last_error = None
          while error_count < RETRY_LIMIT:
              try:
                  return func(*args, **kwargs)
              except BTLEException as exception:
                  error_count += 1
                  last_error = exception
                  time.sleep(RETRY_DELAY)
                  _LOGGER.debug('Call to %s failed, try %d of %d', func, error_count, RETRY_LIMIT)
          raise BluetoothBackendException() from last_error
  
      return _func_wrapper
docs: Decorator to wrap BTLEExceptions into BluetoothBackendException.