Add add-on changelog and improve classic RFCOMM fallback (0.1.9)
This commit is contained in:
@@ -384,10 +384,25 @@ async def connect(
|
||||
if classic:
|
||||
if not address:
|
||||
raise PrinterError("--address is required for Classic Bluetooth (no scanning)")
|
||||
async with RFCOMMClient(address, channel) as client:
|
||||
pc = PrinterClient(client)
|
||||
await pc.start()
|
||||
yield pc
|
||||
# D11s variants are commonly exposed on channel 1 or 3.
|
||||
candidates = [channel, 1, 2, 3]
|
||||
channels = [ch for i, ch in enumerate(candidates) if ch > 0 and ch not in candidates[:i]]
|
||||
last_exc: Exception | None = None
|
||||
for ch in channels:
|
||||
try:
|
||||
async with RFCOMMClient(address, ch) as client:
|
||||
pc = PrinterClient(client)
|
||||
await pc.start()
|
||||
yield pc
|
||||
return
|
||||
except (PrinterError, PrinterTimeout) as exc:
|
||||
last_exc = exc
|
||||
if last_exc is not None:
|
||||
raise PrinterError(
|
||||
f"Classic Bluetooth connection failed for '{address}'. "
|
||||
f"Tried channels: {channels}. Last error: {last_exc}"
|
||||
) from last_exc
|
||||
raise PrinterError(f"Classic Bluetooth connection failed for '{address}'.")
|
||||
else:
|
||||
addr = address or await find_printer()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user