add files
This commit is contained in:
@@ -8,6 +8,7 @@ Device class: AiYinNormalDevice (LuckPrinter SDK)
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import errno
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
@@ -427,14 +428,31 @@ async def connect(
|
||||
yield pc
|
||||
return
|
||||
except (PrinterError, PrinterTimeout) as exc:
|
||||
# On Linux, a stale BlueZ device state can cause RFCOMM connect()
|
||||
# to fail with [Errno 12] Out of memory. This is a known quirk.
|
||||
# We treat this specific error as a signal to fall back to BLE.
|
||||
if isinstance(exc.__cause__, OSError) and exc.__cause__.errno == errno.ENOMEM:
|
||||
print(
|
||||
"Classic Bluetooth connection failed with [Errno 12] Out of memory. "
|
||||
"Falling back to BLE connection."
|
||||
)
|
||||
classic = False # Modify flag to trigger BLE path below
|
||||
last_exc = exc
|
||||
break
|
||||
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:
|
||||
|
||||
# If the 'classic' flag is still true, it means the loop completed without
|
||||
# hitting the ENOMEM fallback case, so all classic attempts failed.
|
||||
if classic:
|
||||
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}'.")
|
||||
|
||||
# If classic=False initially, or if it was set to False for the ENOMEM fallback:
|
||||
if not classic:
|
||||
target = await resolve_ble_target(address)
|
||||
def _is_retryable_ble_error(exc: Exception) -> bool:
|
||||
msg = str(exc).lower()
|
||||
|
||||
Reference in New Issue
Block a user