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:
75
test_color_api.sh
Executable file
75
test_color_api.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
# Color Palette API Test Script
|
||||
# Usage: ./test_color_api.sh [server_ip]
|
||||
|
||||
SERVER=${1:-localhost}
|
||||
PORT=8765
|
||||
API_URL="http://${SERVER}:${PORT}/api/color-palette"
|
||||
|
||||
echo "Testing Color Palette API at ${API_URL}"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Test 1: GET current palette
|
||||
echo "Test 1: GET current palette"
|
||||
echo "----------------------------"
|
||||
curl -s "${API_URL}" | python3 -m json.tool
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 2: Update selected colors to slots 0 and 2 (Red and Blue)
|
||||
echo "Test 2: Update selected colors to [0, 2] (Red and Blue)"
|
||||
echo "--------------------------------------------------------"
|
||||
curl -s -X POST "${API_URL}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"selected_indices": [0, 2]}' | python3 -m json.tool
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 3: Update slot 3 to purple (128, 0, 128)
|
||||
echo "Test 3: Update slot 3 to purple (128, 0, 128)"
|
||||
echo "----------------------------------------------"
|
||||
curl -s -X POST "${API_URL}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"palette": [
|
||||
{"r": 255, "g": 0, "b": 0},
|
||||
{"r": 0, "g": 255, "b": 0},
|
||||
{"r": 0, "g": 0, "b": 255},
|
||||
{"r": 128, "g": 0, "b": 128},
|
||||
{"r": 255, "g": 179, "b": 255},
|
||||
{"r": 0, "g": 255, "b": 255},
|
||||
{"r": 255, "g": 255, "b": 255},
|
||||
{"r": 128, "g": 128, "b": 128}
|
||||
]}' | python3 -m json.tool
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 4: Select the new purple color (slots 3 and 5)
|
||||
echo "Test 4: Select slots 3 and 5 (Purple and Cyan)"
|
||||
echo "-----------------------------------------------"
|
||||
curl -s -X POST "${API_URL}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"selected_indices": [3, 5]}' | python3 -m json.tool
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 5: GET final state
|
||||
echo "Test 5: GET final state"
|
||||
echo "-----------------------"
|
||||
curl -s "${API_URL}" | python3 -m json.tool
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 6: Test backup port (8766)
|
||||
echo "Test 6: Test backup port 8766"
|
||||
echo "------------------------------"
|
||||
curl -s "http://${SERVER}:8766/api/color-palette" | python3 -m json.tool | head -15
|
||||
echo "..."
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo "All tests completed!"
|
||||
echo ""
|
||||
echo "Config file location: lighting_config.json"
|
||||
echo "To view: cat lighting_config.json | python3 -m json.tool"
|
||||
|
Reference in New Issue
Block a user