Skip to content

Commit

Permalink
Catch and throw AuthenticationFailed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
abmantis committed Oct 7, 2023
1 parent e97348e commit 32b9269
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions idasen_ha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

from bleak import BleakClient
from bleak.backends.device import BLEDevice
from bleak.exc import BleakDBusError
from idasen import IdasenDesk

_LOGGER = logging.getLogger(__name__)


class AuthFailedError(Exception):
"""Authentication Failed Exception."""


class Desk:
"""Wrapper around the IdasenDesk from the idasen library."""

Expand Down Expand Up @@ -46,8 +51,14 @@ def disconnect_callback(client: BleakClient) -> None:
)

await self._idasen_desk.connect()

try:
await self._idasen_desk.pair()
except BleakDBusError as ex:
await self._idasen_desk.disconnect()
if ex.dbus_error == "org.bluez.Error.AuthenticationFailed":
raise AuthFailedError() from ex
raise ex
except Exception as ex:
await self._idasen_desk.disconnect()
self._idasen_desk = None
Expand Down

0 comments on commit 32b9269

Please sign in to comment.