busylight_modular/wled_client.py
Christian Mueller 5267baf0b4 feat: rewrite busylight as FastAPI web application with SQLite
Replace the standalone Python script + config.cfg with a full web
application featuring:
- FastAPI backend with REST API
- SQLite database (config, state, activity log separated)
- Bootstrap 5 web interface for configuration
- Pages: Dashboard, Users, Devices, Assignments, Color Rules, Settings, Log
- APScheduler background polling for Teams presence + AIDA status
- systemd service file for Linux deployment
- Migration script to import existing config.cfg data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-23 20:46:33 +02:00

27 lines
756 B
Python

import logging
import requests
logger = logging.getLogger(__name__)
TIMEOUT = 5
def build_wled_url(hostname, r, g, b, segment=None, effect=""):
"""Build WLED HTTP API URL."""
base = f"http://{hostname}/win&A=255&R={r}&G={g}&B={b}"
if effect:
base = f"http://{hostname}{effect}&R={r}&G={g}&B={b}"
if segment is not None:
base = f"{base}&SS={segment}"
return base
def call_wled(url):
"""Send HTTP request to WLED device. Returns (success, status_text)."""
try:
r = requests.post(url, timeout=TIMEOUT)
return True, f"{r.status_code} {r.reason}"
except requests.exceptions.RequestException as e:
logger.warning("WLED nicht erreichbar: %s - %s", url, e)
return False, str(e)