add features
This commit is contained in:
@@ -23,6 +23,7 @@ from typing import Annotated
|
||||
|
||||
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import RedirectResponse
|
||||
from PIL import Image
|
||||
|
||||
from fichero.cli import DOTS_PER_MM, do_print
|
||||
@@ -91,6 +92,11 @@ def _address(address: str | None) -> str | None:
|
||||
# Endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def root():
|
||||
"""Redirect root to interactive API docs."""
|
||||
return RedirectResponse(url="/docs")
|
||||
|
||||
|
||||
@app.get(
|
||||
"/status",
|
||||
|
||||
@@ -12,6 +12,7 @@ from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from bleak import BleakClient, BleakGATTCharacteristic, BleakScanner
|
||||
from bleak.exc import BleakDBusError, BleakError
|
||||
|
||||
# --- RFCOMM (Classic Bluetooth) support - Linux + Windows (Python 3.9+) ---
|
||||
|
||||
@@ -374,7 +375,17 @@ async def connect(
|
||||
yield pc
|
||||
else:
|
||||
addr = address or await find_printer()
|
||||
async with BleakClient(addr) as client:
|
||||
pc = PrinterClient(client)
|
||||
await pc.start()
|
||||
yield pc
|
||||
try:
|
||||
async with BleakClient(addr) as client:
|
||||
pc = PrinterClient(client)
|
||||
await pc.start()
|
||||
yield pc
|
||||
except BleakDBusError as exc:
|
||||
if "br-connection-not-supported" in str(exc).lower():
|
||||
raise PrinterError(
|
||||
"BLE connection failed (br-connection-not-supported). "
|
||||
"Try Classic Bluetooth with classic=true and channel=1."
|
||||
) from exc
|
||||
raise PrinterError(f"BLE connection failed: {exc}") from exc
|
||||
except BleakError as exc:
|
||||
raise PrinterError(f"BLE error: {exc}") from exc
|
||||
|
||||
Reference in New Issue
Block a user