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:
49
test_pattern_color.py
Normal file
49
test_pattern_color.py
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify patterns are using the selected palette color
|
||||
"""
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import json
|
||||
|
||||
async def test_pattern_with_color():
|
||||
"""Test sending a pattern and verifying the color"""
|
||||
|
||||
# Connect to WebSocket
|
||||
session = aiohttp.ClientSession()
|
||||
try:
|
||||
async with session.ws_connect('http://localhost:8765/ws') as ws:
|
||||
print("✅ Connected to WebSocket at ws://localhost:8765/ws")
|
||||
|
||||
# Send pattern change to 'on'
|
||||
msg = {
|
||||
"type": "pattern_change",
|
||||
"data": {"pattern": "on"}
|
||||
}
|
||||
print(f"\n📤 Sending: {json.dumps(msg, indent=2)}")
|
||||
await ws.send_json(msg)
|
||||
|
||||
# Wait a moment
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# Send alternating pattern
|
||||
msg = {
|
||||
"type": "pattern_change",
|
||||
"data": {"pattern": "alternating"}
|
||||
}
|
||||
print(f"\n📤 Sending: {json.dumps(msg, indent=2)}")
|
||||
await ws.send_json(msg)
|
||||
|
||||
await asyncio.sleep(2)
|
||||
|
||||
print("\n✅ Patterns sent successfully!")
|
||||
print("Check the LED bar to see if it's using purple RGB(128, 0, 128)")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_pattern_with_color())
|
||||
|
Reference in New Issue
Block a user