From ff0add2f58a8835095ddb3d8a8aa5872deeb8b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9A=D0=BE=D0=BA=D0=BE?= =?UTF-8?q?=D1=81?= Date: Sat, 21 Feb 2026 09:53:49 +0700 Subject: [PATCH] Sched for group --- main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.py b/main.py index 89b5eaa..e847bf9 100644 --- a/main.py +++ b/main.py @@ -247,6 +247,32 @@ async def add_once_task(device_id: str, minutes: int, state: bool): return {"status": "scheduled", "job_id": job.id, "run_at": run_time.isoformat()} +@app.post("/schedules/group/once") +async def add_group_once_task(group_id: str, minutes: int, state: bool): + group = state_manager.groups.get(group_id) + if not group: + raise HTTPException(status_code=404, detail="Группа не найдена") + + # Собираем все IP ламп группы + ips = [ + state_manager.devices[mac].ip + for mac in group.device_ids + if mac in state_manager.devices + ] + run_time = datetime.now(scheduler.timezone) + timedelta(minutes=minutes) + + for ip in ips: + scheduler.add_job( + execute_lamp_command, "date", run_date=run_time, args=[ip, {"state": state}] + ) + return { + "status": "scheduled", + "group": group_id, + "lamps": len(ips), + "run_at": run_time, + } + + @app.get("/schedules/active") async def get_active_jobs(): jobs = []