Files
Convivo/apps/printer/worker/network.py
T
00c89c1b48 feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view
- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations,
  token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs,
  welcome_checkin enqueue; badge_print_tests.sql (101 assertions)
- apps/printer: Python worker (Playwright render -> brother_ql via pyusb),
  comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token),
  arm64 image build + idempotent Pi setup/install scripts, 77 pytest
- apps/admin: Printing view, station management/DLQ, global printer status
  pill, Print button on Registrations, standalone print renderer entry
  (print.html -> dist-print) with bundled fonts
- docs: printing.md + architecture/schema/rpcs/tests/admin-app updates,
  apps/printer/AGENT.md operating manual
- e2e: printing.spec.ts

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-10-18 22:25:38 +02:00

40 lines
1.1 KiB
Python

"""Read the comitup network state file written by the host."""
from __future__ import annotations
import json
import socket
from pathlib import Path
UNKNOWN = {"state": "UNKNOWN", "ssid": None, "ip": None}
def _detect_ip() -> str | None:
# UDP connect trick: picks the source address of the default route, no traffic sent.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
sock.connect(("8.8.8.8", 53))
return str(sock.getsockname()[0])
except OSError:
return None
finally:
sock.close()
def read_network(path: str) -> dict:
try:
raw = json.loads(Path(path).read_text())
except (OSError, ValueError):
result = dict(UNKNOWN)
result["ip"] = _detect_ip()
return result
if not isinstance(raw, dict):
result = dict(UNKNOWN)
result["ip"] = _detect_ip()
return result
return {
"state": str(raw.get("state") or "UNKNOWN"),
"ssid": raw.get("ssid") or None,
"ip": raw.get("ip") or None,
"updated_at": raw.get("updated_at"),
}