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:
70
test_rest_api.sh
Executable file
70
test_rest_api.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
# Test all REST API endpoints
|
||||
|
||||
SERVER=${1:-localhost}
|
||||
PORT=8765
|
||||
BASE="http://${SERVER}:${PORT}"
|
||||
|
||||
echo "Testing Lighting Controller REST API"
|
||||
echo "====================================="
|
||||
echo ""
|
||||
|
||||
# Test 1: GET /api/state
|
||||
echo "1. GET /api/state"
|
||||
echo "-----------------"
|
||||
curl -s "${BASE}/api/state" | python3 -m json.tool | head -20
|
||||
echo ""
|
||||
|
||||
# Test 2: POST /api/pattern
|
||||
echo "2. POST /api/pattern (set to 'alternating')"
|
||||
echo "--------------------------------------------"
|
||||
curl -s -X POST "${BASE}/api/pattern" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"pattern": "alternating"}' | python3 -m json.tool
|
||||
echo ""
|
||||
|
||||
# Test 3: GET /api/pattern
|
||||
echo "3. GET /api/pattern"
|
||||
echo "-------------------"
|
||||
curl -s "${BASE}/api/pattern" | python3 -m json.tool
|
||||
echo ""
|
||||
|
||||
# Test 4: POST /api/parameters (brightness)
|
||||
echo "4. POST /api/parameters (brightness=75)"
|
||||
echo "----------------------------------------"
|
||||
curl -s -X POST "${BASE}/api/parameters" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"brightness": 75}' | python3 -m json.tool
|
||||
echo ""
|
||||
|
||||
# Test 5: GET /api/parameters
|
||||
echo "5. GET /api/parameters"
|
||||
echo "----------------------"
|
||||
curl -s "${BASE}/api/parameters" | python3 -m json.tool
|
||||
echo ""
|
||||
|
||||
# Test 6: POST /api/color-palette (select slot 2)
|
||||
echo "6. POST /api/color-palette (select slot 2)"
|
||||
echo "-------------------------------------------"
|
||||
curl -s -X POST "${BASE}/api/color-palette" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"selected_indices": [2, 1]}' | python3 -m json.tool | head -10
|
||||
echo ""
|
||||
|
||||
# Test 7: GET /api/color-palette
|
||||
echo "7. GET /api/color-palette"
|
||||
echo "-------------------------"
|
||||
curl -s "${BASE}/api/color-palette" | python3 -m json.tool | head -15
|
||||
echo ""
|
||||
|
||||
# Test 8: POST /api/pattern (rainbow)
|
||||
echo "8. POST /api/pattern (set to 'rainbow')"
|
||||
echo "----------------------------------------"
|
||||
curl -s -X POST "${BASE}/api/pattern" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"pattern": "rainbow"}' | python3 -m json.tool
|
||||
echo ""
|
||||
|
||||
echo "====================================="
|
||||
echo "All tests complete!"
|
||||
|
Reference in New Issue
Block a user