Skip to content

Commit

Permalink
feat: log the adapter when connecting (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 30, 2022
1 parent 0a18f04 commit ab873c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/bleak_retry_connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ def ble_device_has_changed(original: BLEDevice, new: BLEDevice) -> bool:

def ble_device_description(device: BLEDevice) -> str:
"""Get the device description."""
if isinstance(device.details, dict) and "path" in device.details:
return device.details["path"]
return device.address
details = device.details
address = device.address
if isinstance(details, dict):
if path := details.get("path"):
# /org/bluez/hci2
return f"{address} -> {path[0:15]}"
if source := details.get("source"):
return f"{address} -> {source}"
return address


def _get_possible_paths(path: str) -> Generator[str, None, None]:
Expand Down
20 changes: 14 additions & 6 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,19 @@ async def disconnect(self, *args, **kwargs):
try:
await establish_connection(
FakeBleakClient,
BLEDevice("aa:bb:cc:dd:ee:ff", "name", {"path": "/dev/1"}),
BLEDevice(
"aa:bb:cc:dd:ee:ff",
"name",
{"path": "/org/bluez/hci2/dev_FA_23_9D_AA_45_46"},
),
"test",
)
except BleakError as e:
exc = e

assert isinstance(exc, BleakAbortedError)
assert str(exc) == (
"test - /dev/1: "
"test - aa:bb:cc:dd:ee:ff -> /org/bluez/hci2: "
"Failed to connect: "
"le-connection-abort-by-local: "
"Interference/range; "
Expand All @@ -459,15 +463,15 @@ async def disconnect(self, *args, **kwargs):
try:
await establish_connection(
FakeBleakClient,
BLEDevice("aa:bb:cc:dd:ee:ff", "name", {"path": "/dev/1"}),
BLEDevice("aa:bb:cc:dd:ee:ff", "name", {"source": "esphome_proxy_1"}),
"test",
)
except BleakError as e:
exc = e

assert isinstance(exc, BleakOutOfConnectionSlotsError)
assert str(exc) == (
"test - /dev/1: "
"test - aa:bb:cc:dd:ee:ff -> esphome_proxy_1: "
"Failed to connect: "
"out of connection slots: "
"The proxy/adapter is out of connection slots; "
Expand Down Expand Up @@ -496,15 +500,19 @@ async def disconnect(self, *args, **kwargs):
try:
await establish_connection(
FakeBleakClient,
BLEDevice("aa:bb:cc:dd:ee:ff", "name", {"path": "/dev/1"}),
BLEDevice(
"aa:bb:cc:dd:ee:ff",
"name",
{"path": "/org/bluez/hci2/dev_FA_23_9D_AA_45_46"},
),
"test",
)
except BleakError as e:
exc = e

assert isinstance(exc, BleakNotFoundError)
assert str(exc) == (
"test - /dev/1: "
"test - aa:bb:cc:dd:ee:ff -> /org/bluez/hci2: "
"Failed to connect: "
"[org.freedesktop.DBus.Error.UnknownObject] "
'Method "Connect" with signature "" on interface "org.bluez.Device1" '
Expand Down

0 comments on commit ab873c8

Please sign in to comment.