From aa125736f3310f99710e8b0da9b5d840e7a61d09 Mon Sep 17 00:00:00 2001 From: paul2212 Date: Sat, 7 Mar 2026 13:59:30 +0100 Subject: [PATCH] Fix RFCOMM connect under uvloop and bump version to 0.1.4 --- fichero/printer.py | 13 +++++++++---- fichero_printer/config.yaml | 2 +- fichero_printer/fichero/printer.py | 13 +++++++++---- pyproject.toml | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fichero/printer.py b/fichero/printer.py index 1fbf137..6a9da82 100644 --- a/fichero/printer.py +++ b/fichero/printer.py @@ -155,13 +155,18 @@ class RFCOMMClient: sock = _socket.socket( _socket.AF_BLUETOOTH, _socket.SOCK_STREAM, _socket.BTPROTO_RFCOMM ) - sock.setblocking(False) loop = asyncio.get_running_loop() try: - await asyncio.wait_for( - loop.sock_connect(sock, (self._address, self._channel)), - timeout=10.0, + # uvloop's sock_connect path goes through getaddrinfo and doesn't + # support AF_BLUETOOTH addresses reliably. Use direct socket connect + # in a thread instead. + sock.settimeout(10.0) + await loop.run_in_executor( + None, + sock.connect, + (self._address, self._channel), ) + sock.setblocking(False) except asyncio.TimeoutError as exc: sock.close() raise PrinterTimeout( diff --git a/fichero_printer/config.yaml b/fichero_printer/config.yaml index 242a9e0..1f397bf 100644 --- a/fichero_printer/config.yaml +++ b/fichero_printer/config.yaml @@ -1,5 +1,5 @@ name: "Fichero Printer" -version: "0.1.3" +version: "0.1.4" slug: "fichero_printer" description: "REST API for the Fichero D11s (AiYin) thermal label printer over Bluetooth" url: "https://git.leuschner.dev/Tobias/Fichero" diff --git a/fichero_printer/fichero/printer.py b/fichero_printer/fichero/printer.py index 1fbf137..6a9da82 100644 --- a/fichero_printer/fichero/printer.py +++ b/fichero_printer/fichero/printer.py @@ -155,13 +155,18 @@ class RFCOMMClient: sock = _socket.socket( _socket.AF_BLUETOOTH, _socket.SOCK_STREAM, _socket.BTPROTO_RFCOMM ) - sock.setblocking(False) loop = asyncio.get_running_loop() try: - await asyncio.wait_for( - loop.sock_connect(sock, (self._address, self._channel)), - timeout=10.0, + # uvloop's sock_connect path goes through getaddrinfo and doesn't + # support AF_BLUETOOTH addresses reliably. Use direct socket connect + # in a thread instead. + sock.settimeout(10.0) + await loop.run_in_executor( + None, + sock.connect, + (self._address, self._channel), ) + sock.setblocking(False) except asyncio.TimeoutError as exc: sock.close() raise PrinterTimeout( diff --git a/pyproject.toml b/pyproject.toml index af58e2e..ac6e3de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "fichero-printer" -version = "0.1.3" +version = "0.1.4" description = "Fichero D11s thermal label printer - BLE CLI tool" requires-python = ">=3.10" dependencies = [