v0.1.37: Enhanced Home Assistant add-on configuration with integrated settings\n\n- Added complete Home Assistant add-on configuration in config.yaml\n- Integrated host_dbus, host_network, and device settings directly\n- Added port, address, transport, and channel as configurable options\n- Added schema validation for all configuration options\n- Updated CLI to use environment variables for all settings\n- Added log_level configuration option\n- Improved default values and documentation\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>
Some checks failed
Deploy to GitHub Pages / build (push) Has been cancelled
Deploy to GitHub Pages / deploy (push) Has been cancelled

This commit is contained in:
paul2212
2026-03-18 19:25:39 +01:00
parent 2d9748a1cd
commit c86a185ec4
2 changed files with 32 additions and 3 deletions

View File

@@ -1,11 +1,34 @@
name: "Fichero Printer"
version: "0.1.37"
host_dbus: true
name: "Fichero Printer"
description: "REST API for Fichero D11s thermal label printer with BLE and Classic Bluetooth support"
url: "https://github.com/your-repo/fichero-printer"
startup: "application"
boot: "auto"
host_network: true
host_dbus: true
host_pid: true
devices:
- /dev/rfcomm0
- /dev/ttyACM0
environment:
DBUS_SYSTEM_BUS_ADDRESS: "unix:path=/host/run/dbus/system_bus_socket"
FICHERO_PORT: "8765"
FICHERO_ADDR: ""
FICHERO_TRANSPORT: "ble"
FICHERO_CHANNEL: "1"
options:
port: 8765
address: ""
transport: "ble"
channel: 1
log_level: "info"
schema:
port: int(1024,65535)
address: str?
transport: list(ble|classic)
channel: int(1,30)
log_level: list(trace|debug|info|warning|error|fatal)
slug: "fichero_printer"
description: "REST API for the Fichero D11s (AiYin) thermal label printer over Bluetooth"
url: "https://git.leuschner.dev/Tobias/Fichero"

View File

@@ -46,11 +46,14 @@ from fichero.printer import (
# Global connection settings (env vars or CLI flags at startup)
# ---------------------------------------------------------------------------
_DEFAULT_ADDRESS: str | None = os.environ.get("FICHERO_ADDR")
# Try to get from options first (Home Assistant add-on), then env vars
_DEFAULT_ADDRESS: str | None = os.environ.get("FICHERO_ADDR") or ""
# Default to BLE transport (most reliable for Fichero/D11s printers)
# Set FICHERO_TRANSPORT=classic to force Classic Bluetooth (RFCOMM)
_DEFAULT_CLASSIC: bool = os.environ.get("FICHERO_TRANSPORT", "").lower() == "classic"
_DEFAULT_CHANNEL: int = int(os.environ.get("FICHERO_CHANNEL", "1"))
_DEFAULT_PORT: int = int(os.environ.get("FICHERO_PORT", "8765"))
_DEFAULT_LOG_LEVEL: str = os.environ.get("LOG_LEVEL", "info").lower()
_PAPER_MAP = {"gap": 0, "black": 1, "continuous": 2}
@@ -586,7 +589,7 @@ def main() -> None:
parser = argparse.ArgumentParser(description="Fichero Printer API Server")
parser.add_argument("--host", default="127.0.0.1", help="Bind host (default: 127.0.0.1)")
parser.add_argument("--port", type=int, default=8765, help="Bind port (default: 8765)")
parser.add_argument("--port", type=int, default=_DEFAULT_PORT, help=f"Bind port (default: {_DEFAULT_PORT})")
parser.add_argument("--address", default=_DEFAULT_ADDRESS, metavar="BLE_ADDR",
help="Default BLE address (or set FICHERO_ADDR env var)")
parser.add_argument("--classic", action="store_true", default=_DEFAULT_CLASSIC,
@@ -594,12 +597,15 @@ def main() -> None:
parser.add_argument("--channel", type=int, default=_DEFAULT_CHANNEL,
help="Default RFCOMM channel (default: 1)")
parser.add_argument("--reload", action="store_true", help="Enable auto-reload (development)")
parser.add_argument("--log-level", choices=["trace", "debug", "info", "warning", "error", "fatal"],
default=_DEFAULT_LOG_LEVEL, help="Set log level (default: info)")
args = parser.parse_args()
# Push CLI overrides into module-level defaults so all handlers pick them up
_DEFAULT_ADDRESS = args.address
_DEFAULT_CLASSIC = args.classic
_DEFAULT_CHANNEL = args.channel
_DEFAULT_PORT = args.port
# Pass the app object directly when not reloading so that the module-level
# globals (_DEFAULT_ADDRESS etc.) set above are visible to the handlers.