Files
wled-screen-controller-mixed/server/tests/test_config.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

121 lines
3.2 KiB
Python

"""Tests for configuration management."""
import os
from pathlib import Path
import pytest
import yaml
from wled_controller.config import (
Config,
ServerConfig,
ProcessingConfig,
WLEDConfig,
get_config,
reload_config,
)
def test_default_config():
"""Test default configuration values."""
config = Config()
assert config.server.host == "0.0.0.0"
assert config.server.port == 8080
assert config.processing.default_fps == 30
assert config.processing.max_fps == 60
assert config.wled.timeout == 5
def test_load_from_yaml(tmp_path):
"""Test loading configuration from YAML file."""
config_data = {
"server": {"host": "127.0.0.1", "port": 9000},
"processing": {"default_fps": 60, "border_width": 20},
"wled": {"timeout": 10},
}
config_path = tmp_path / "test_config.yaml"
with open(config_path, "w") as f:
yaml.dump(config_data, f)
config = Config.from_yaml(config_path)
assert config.server.host == "127.0.0.1"
assert config.server.port == 9000
assert config.processing.default_fps == 60
assert config.processing.border_width == 20
assert config.wled.timeout == 10
def test_load_from_yaml_file_not_found():
"""Test loading from non-existent YAML file."""
with pytest.raises(FileNotFoundError):
Config.from_yaml("nonexistent.yaml")
def test_environment_variables(monkeypatch):
"""Test configuration from environment variables."""
monkeypatch.setenv("WLED_SERVER__HOST", "192.168.1.1")
monkeypatch.setenv("WLED_SERVER__PORT", "7000")
monkeypatch.setenv("WLED_PROCESSING__DEFAULT_FPS", "45")
config = Config()
assert config.server.host == "192.168.1.1"
assert config.server.port == 7000
assert config.processing.default_fps == 45
def test_server_config():
"""Test server configuration."""
server_config = ServerConfig(host="localhost", port=8000)
assert server_config.host == "localhost"
assert server_config.port == 8000
assert server_config.log_level == "INFO"
def test_processing_config():
"""Test processing configuration."""
proc_config = ProcessingConfig(default_fps=25, max_fps=50)
assert proc_config.default_fps == 25
assert proc_config.max_fps == 50
assert proc_config.interpolation_mode == "average"
def test_wled_config():
"""Test WLED configuration."""
wled_config = WLEDConfig(timeout=10, retry_attempts=5)
assert wled_config.timeout == 10
assert wled_config.retry_attempts == 5
assert wled_config.protocol == "http"
def test_config_validation():
"""Test configuration validation."""
# Test valid interpolation mode
config = Config(
processing=ProcessingConfig(interpolation_mode="median")
)
assert config.processing.interpolation_mode == "median"
# Test invalid interpolation mode
with pytest.raises(ValueError):
ProcessingConfig(interpolation_mode="invalid")
def test_get_config():
"""Test global config getter."""
config = get_config()
assert isinstance(config, Config)
def test_reload_config():
"""Test config reload."""
config1 = get_config()
config2 = reload_config()
assert isinstance(config2, Config)