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 = []