Files
wled-screen-controller-mixed/server/tests/test_api.py
alexei.dolgolyov d471a40234
Some checks failed
Validate / validate (push) Failing after 1m6s
Initial commit: WLED Screen Controller with FastAPI server and Home Assistant integration
This is a complete WLED ambient lighting controller that captures screen border pixels
and sends them to WLED devices for immersive ambient lighting effects.

## Server Features:
- FastAPI-based REST API with 17+ endpoints
- Real-time screen capture with multi-monitor support
- Advanced LED calibration system with visual GUI
- API key authentication with labeled tokens
- Per-device brightness control (0-100%)
- Configurable FPS (1-60), border width, and color correction
- Persistent device storage (JSON-based)
- Comprehensive Web UI with dark/light themes
- Docker support with docker-compose
- Windows monitor name detection via WMI (shows "LG ULTRAWIDE" etc.)

## Web UI Features:
- Device management (add, configure, remove WLED devices)
- Real-time status monitoring with FPS metrics
- Settings modal for device configuration
- Visual calibration GUI with edge testing
- Brightness slider per device
- Display selection with friendly monitor names
- Token-based authentication with login/logout
- Responsive button layout

## Calibration System:
- Support for any LED strip layout (clockwise/counterclockwise)
- 4 starting position options (corners)
- Per-edge LED count configuration
- Visual preview with starting position indicator
- Test buttons to light up individual edges
- Smart LED ordering based on start position and direction

## Home Assistant Integration:
- Custom HACS integration
- Switch entities for processing control
- Sensor entities for status and FPS
- Select entities for display selection
- Config flow for easy setup
- Auto-discovery of devices from server

## Technical Stack:
- Python 3.11+
- FastAPI + uvicorn
- mss (screen capture)
- httpx (async WLED client)
- Pydantic (validation)
- WMI (Windows monitor detection)
- Structlog (logging)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 16:38:27 +03:00

76 lines
2.1 KiB
Python

"""Tests for API endpoints."""
import pytest
from fastapi.testclient import TestClient
from wled_controller.main import app
from wled_controller import __version__
client = TestClient(app)
def test_root_endpoint():
"""Test root endpoint."""
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data["name"] == "WLED Screen Controller"
assert data["version"] == __version__
assert "/docs" in data["docs"]
def test_health_check():
"""Test health check endpoint."""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["version"] == __version__
assert "timestamp" in data
def test_version_endpoint():
"""Test version endpoint."""
response = client.get("/api/v1/version")
assert response.status_code == 200
data = response.json()
assert data["version"] == __version__
assert "python_version" in data
assert data["api_version"] == "v1"
def test_get_displays():
"""Test get displays endpoint."""
response = client.get("/api/v1/config/displays")
assert response.status_code == 200
data = response.json()
assert "displays" in data
assert "count" in data
assert isinstance(data["displays"], list)
assert data["count"] >= 0
# If displays are found, validate structure
if data["count"] > 0:
display = data["displays"][0]
assert "index" in display
assert "name" in display
assert "width" in display
assert "height" in display
assert "is_primary" in display
def test_openapi_docs():
"""Test OpenAPI documentation is available."""
response = client.get("/openapi.json")
assert response.status_code == 200
data = response.json()
assert data["info"]["title"] == "WLED Screen Controller"
assert data["info"]["version"] == __version__
def test_swagger_ui():
"""Test Swagger UI is available."""
response = client.get("/docs")
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]