{{ group.name }}
+ +IgnisCore
+ +Создайте группу в админке, чтобы управлять лампами
+{{ group.name }}
+ {{ id }} • {{ group.device_ids?.length || 0 }} ламп +Новая группа
- -Устройства в сети
+ +Доступные лампы в сети:
-diff --git a/app/api/routes/control.py b/app/api/routes/control.py index 94bc96f..480d87c 100644 --- a/app/api/routes/control.py +++ b/app/api/routes/control.py @@ -84,11 +84,23 @@ async def blink_device(device_id: str): if not device: raise HTTPException(status_code=404, detail="Лампа оффлайн") - await wiz.set_pilot(device.ip, {"sceneId": 34, "speed": 100}) - await asyncio.sleep(3) - await wiz.set_pilot(device.ip, {"state": False}) + try: + # 1. Получаем текущее состояние + current = await wiz.get_pilot(device.ip) + # Если не удалось получить статус, считаем что она выключена (False) + original_state = current.get("result", {}).get("state", False) - return {"status": "blink_sent"} + # 2. Инвертируем состояние + await wiz.set_pilot(device.ip, {"state": not original_state}) + await asyncio.sleep(0.5) + + # 3. Возвращаем как было + await wiz.set_pilot(device.ip, {"state": original_state}) + + return {"status": "blink_done", "original": original_state} + except Exception as e: + logger.error(f"Blink error: {e}") + raise HTTPException(status_code=500, detail="Ошибка связи с лампой") @router.get("/device/{device_id}/status") diff --git a/main.py b/main.py index c67c8d9..58f392f 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,15 @@ app.include_router(control.router, prefix="/control", tags=["Control"]) app.include_router(schedules.router, prefix="/schedules", tags=["Schedules"]) # Статика -app.mount("/", StaticFiles(directory="static", html=True), name="static") +# Мы убираем html=True из корня, чтобы 404-е ошибки API не превращались в загрузку index.html +app.mount("/static", StaticFiles(directory="static"), name="static") + + +@app.get("/") +async def read_index(): + from fastapi.responses import FileResponse + + return FileResponse("static/index.html") if __name__ == "__main__": diff --git a/static/index.html b/static/index.html index 4ec605f..c1dbdaf 100644 --- a/static/index.html +++ b/static/index.html @@ -3,133 +3,141 @@
-Введите API ключ из .env
+Создайте группу в админке, чтобы управлять лампами
+Доступные лампы в сети:
-