Add complete REST API for lighting control
- Migrated from websockets to aiohttp for unified HTTP/WebSocket server - Added REST endpoints: /api/pattern, /api/parameters, /api/state, /api/tempo/reset - Implemented color palette API with 8-slot system and selected colors - First selected color (index 0) is used as primary RGB for patterns - All operations now available via simple HTTP requests (no WebSocket needed) - Added comprehensive documentation: FRONTEND_API.md, COLOR_PALETTE_API.md - Added test scripts: test_rest_api.sh, test_color_patterns.py - Updated test/test_control_server.py for new /ws WebSocket path - Configuration persistence via lighting_config.json - Pattern parameters (n1-n4, brightness, delay) controllable via API - WebSocket still available at /ws for legacy support
This commit is contained in:
57
test_color_selection.py
Normal file
57
test_color_selection.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify that selected color is used for patterns
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Add src to path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
||||
|
||||
from control_server import LightingController
|
||||
|
||||
def test_color_selection():
|
||||
"""Test that the first selected color is used as RGB"""
|
||||
|
||||
# Create controller (without connecting)
|
||||
controller = LightingController(transport="spi")
|
||||
|
||||
# Load config
|
||||
controller._load_config()
|
||||
|
||||
print("Color Palette Selection Test")
|
||||
print("=" * 50)
|
||||
print(f"\nColor Palette:")
|
||||
for i, color in enumerate(controller.color_palette):
|
||||
r, g, b = color['r'], color['g'], color['b']
|
||||
print(f" Slot {i}: RGB({r:3d}, {g:3d}, {b:3d})")
|
||||
|
||||
print(f"\nSelected Indices: {controller.selected_color_indices}")
|
||||
|
||||
if controller.selected_color_indices:
|
||||
first_index = controller.selected_color_indices[0]
|
||||
print(f"First Selected: Slot {first_index}")
|
||||
selected_color = controller.color_palette[first_index]
|
||||
print(f" RGB({selected_color['r']}, {selected_color['g']}, {selected_color['b']})")
|
||||
|
||||
# Test the _current_color_rgb method
|
||||
rgb = controller._current_color_rgb()
|
||||
print(f"\nPattern RGB (from _current_color_rgb): RGB{rgb}")
|
||||
|
||||
# Verify it matches the first selected color
|
||||
if controller.selected_color_indices:
|
||||
first_index = controller.selected_color_indices[0]
|
||||
expected_color = controller.color_palette[first_index]
|
||||
expected_rgb = (expected_color['r'], expected_color['g'], expected_color['b'])
|
||||
|
||||
if rgb == expected_rgb:
|
||||
print("\n✅ SUCCESS: Pattern RGB matches first selected color!")
|
||||
else:
|
||||
print(f"\n❌ FAIL: Expected {expected_rgb}, got {rgb}")
|
||||
|
||||
print("=" * 50)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_color_selection()
|
||||
|
Reference in New Issue
Block a user