DELETE groups
This commit is contained in:
53
main.py
53
main.py
@@ -174,9 +174,60 @@ async def control_group(
|
||||
return {"status": "ok", "applied": params, "sent_to": ips}
|
||||
|
||||
|
||||
# Монтируем папку static для фронтенда
|
||||
@app.delete("/groups/{group_id}")
|
||||
async def delete_group(group_id: str):
|
||||
async with async_session() as session:
|
||||
# Ищем в базе
|
||||
result = await session.execute(
|
||||
select(GroupModel).where(GroupModel.id == group_id)
|
||||
)
|
||||
group = result.scalar_one_or_none()
|
||||
|
||||
if not group:
|
||||
raise HTTPException(status_code=404, detail="Группа не найдена")
|
||||
|
||||
await session.delete(group)
|
||||
await session.commit()
|
||||
|
||||
# Удаляем из оперативной памяти
|
||||
if group_id in state_manager.groups:
|
||||
del state_manager.groups[group_id]
|
||||
|
||||
return {"status": "deleted", "id": group_id}
|
||||
|
||||
|
||||
@app.post("/discovery/rescan")
|
||||
async def rescan_network():
|
||||
logger.info("🔄 Ручной перезапуск сканирования сети...")
|
||||
|
||||
found_devices = await discovery.scan_network()
|
||||
for dev_data in found_devices:
|
||||
state_manager.update_device(dev_data)
|
||||
|
||||
return {"status": "ok", "found": len(state_manager.devices)}
|
||||
|
||||
|
||||
@app.post("/control/device/{device_id}/blink")
|
||||
async def blink_device(device_id: str):
|
||||
device = state_manager.devices.get(device_id)
|
||||
if not device:
|
||||
raise HTTPException(status_code=404, detail="Лампа оффлайн")
|
||||
|
||||
# Сцена 34 в WiZ — это пульсация/мигание
|
||||
await wiz.set_pilot(device.ip, {"sceneId": 34, "speed": 100})
|
||||
|
||||
# Через 3 секунды выключаем, чтобы не мигала вечно
|
||||
await asyncio.sleep(3)
|
||||
await wiz.set_pilot(device.ip, {"state": False})
|
||||
|
||||
return {"status": "blink_sent"}
|
||||
|
||||
|
||||
# --- МОНТИРОВАНИЕ СТАТИКИ (ДОЛЖНО БЫТЬ ПОСЛЕ ВСЕХ API МАРШРУТОВ) ---
|
||||
|
||||
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user