Sched for group

This commit is contained in:
Артём Кокос
2026-02-21 09:53:49 +07:00
parent 7d30afe9a3
commit ff0add2f58

26
main.py
View File

@@ -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()} 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") @app.get("/schedules/active")
async def get_active_jobs(): async def get_active_jobs():
jobs = [] jobs = []