Files
led2/lightsync/api/devices.py
Claude 5e10272c69 feat(01-01): create device registry, show store, FastAPI app, API routes, and frontend shell
- DeviceRegistry with load/save/add/remove/instantiate and _DEVICE_CLASSES dict
- ShowStore with save/load/list_ids using aiofiles for async I/O
- FastAPI app with lifespan hook (startup: load registry/store, shutdown: save registry)
- API routes: GET/POST /api/devices/, DELETE /api/devices/{id}, GET/POST /api/shows/, GET /api/shows/{id}
- WebSocket stub at /ws with ConnectionManager and ack echo
- Frontend shell: DAW layout with header, sidebar (DEVICES + ANIMATIONS), TIMELINE, TRANSPORT
- Terminal aesthetic: dark theme, cyan accents, monospace fonts, no drop shadows
- .gitignore for runtime data (devices.json, shows/, __pycache__, .venv)
2026-04-05 18:47:25 +00:00

25 lines
706 B
Python

from fastapi import APIRouter, HTTPException
from lightsync.models.device import DeviceConfig
import lightsync.main as state # access registry via module-level ref
router = APIRouter(tags=["devices"])
@router.get("/")
async def list_devices() -> list[DeviceConfig]:
return state.registry.list_all()
@router.post("/", status_code=201)
async def add_device(config: DeviceConfig) -> DeviceConfig:
state.registry.add(config)
await state.registry.save()
return config
@router.delete("/{device_id}", status_code=204)
async def remove_device(device_id: str):
if not state.registry.remove(device_id):
raise HTTPException(404, "Device not found")
await state.registry.save()