Web-UI: Schedules support
This commit is contained in:
@@ -90,19 +90,37 @@ async def add_cron_task(
|
||||
@router.get("/tasks")
|
||||
async def get_all_tasks():
|
||||
jobs = []
|
||||
|
||||
for job in scheduler.get_jobs():
|
||||
# Разбираем строку типа "Group: bedroom | {'state': True}"
|
||||
# Вытаскиваем цель (bedroom) и состояние (True/False)
|
||||
name_parts = job.name.split("|")
|
||||
target = name_parts[0].replace("Group:", "").replace("Device:", "").strip()
|
||||
|
||||
# Пытаемся понять, ВКЛ или ВЫКЛ задача
|
||||
is_on = "True" in job.name
|
||||
|
||||
jobs.append(
|
||||
{
|
||||
"id": job.id,
|
||||
"name": job.name,
|
||||
"target_id": target,
|
||||
"state": is_on,
|
||||
# Достаем время из триггера APScheduler
|
||||
"next_run": (
|
||||
job.next_run_time.isoformat() if job.next_run_time else None
|
||||
),
|
||||
"params": str(job.args[1]) if len(job.args) > 1 else None,
|
||||
# Вытаскиваем час и минуту прямо из настроек триггера для красоты
|
||||
"hour": (
|
||||
str(job.trigger.fields[5]).zfill(2)
|
||||
if hasattr(job.trigger, "fields")
|
||||
else "??"
|
||||
),
|
||||
"minute": (
|
||||
str(job.trigger.fields[6]).zfill(2)
|
||||
if hasattr(job.trigger, "fields")
|
||||
else "??"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
return {"tasks": jobs}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user