Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions catprinter/ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from bleak import BleakClient, BleakScanner
from bleak.backends.scanner import AdvertisementData
from bleak.backends.device import BLEDevice
from bleak.backends.bluezdbus.client import BleakClientBlueZDBus
# In MacOS capture exception trying Linux library import and set a flag
try:
from bleak.backends.bluezdbus.client import BleakClientBlueZDBus
except ImportError:
BleakClientBlueZDBus = None
from catprinter import logger

# For some reason, bleak reports the 0xaf30 service on my macOS, while it reports
Expand Down Expand Up @@ -99,7 +103,8 @@ async def run_ble(data, device: Optional[str]):
async with BleakClient(address) as client:
# XXX: BlueZ incorrectly reports a fixed MTU of 23; force MTU negotiation manually.
# https://bleak.readthedocs.io/en/latest/api/client.html#bleak.BleakClient.mtu_size
if isinstance(client, BleakClientBlueZDBus):
# Only use this library on Linux, not MacOS
if BleakClientBlueZDBus and isinstance(client, BleakClientBlueZDBus):
await client._acquire_mtu()

logger.info(f"✅ Connected: {client.is_connected}; MTU: {client.mtu_size}")
Expand Down
Loading