mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
scheduler single action on command
This commit is contained in:
@@ -283,7 +283,9 @@ const Scheduler: FC = () => {
|
|||||||
<Cell stiff>
|
<Cell stiff>
|
||||||
<Stack spacing={0.5} direction="row">
|
<Stack spacing={0.5} direction="row">
|
||||||
<Divider orientation="vertical" flexItem />
|
<Divider orientation="vertical" flexItem />
|
||||||
{si.flags < ScheduleFlag.SCHEDULE_TIMER ? (
|
{si.flags === 0 ? (
|
||||||
|
<></>
|
||||||
|
) : si.flags < ScheduleFlag.SCHEDULE_TIMER ? (
|
||||||
<>
|
<>
|
||||||
{dayBox(si, ScheduleFlag.SCHEDULE_MON)}
|
{dayBox(si, ScheduleFlag.SCHEDULE_MON)}
|
||||||
{dayBox(si, ScheduleFlag.SCHEDULE_TUE)}
|
{dayBox(si, ScheduleFlag.SCHEDULE_TUE)}
|
||||||
|
|||||||
@@ -72,6 +72,17 @@ const SchedulerDialog = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveandactivate = async () => {
|
||||||
|
editItem.active = true;
|
||||||
|
try {
|
||||||
|
setFieldErrors(undefined);
|
||||||
|
await validate(validator, editItem);
|
||||||
|
onSave(editItem);
|
||||||
|
} catch (error) {
|
||||||
|
setFieldErrors(error as ValidateFieldsError);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const remove = () => {
|
const remove = () => {
|
||||||
editItem.deleted = true;
|
editItem.deleted = true;
|
||||||
onSave(editItem);
|
onSave(editItem);
|
||||||
@@ -326,6 +337,8 @@ const SchedulerDialog = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<ValidatedTextField
|
<ValidatedTextField
|
||||||
fieldErrors={fieldErrors}
|
fieldErrors={fieldErrors}
|
||||||
name="cmd"
|
name="cmd"
|
||||||
@@ -354,8 +367,6 @@ const SchedulerDialog = ({
|
|||||||
margin="normal"
|
margin="normal"
|
||||||
onChange={updateFormValue}
|
onChange={updateFormValue}
|
||||||
/>
|
/>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
{!creating && (
|
{!creating && (
|
||||||
@@ -386,6 +397,16 @@ const SchedulerDialog = ({
|
|||||||
>
|
>
|
||||||
{creating ? LL.ADD(0) : LL.UPDATE()}
|
{creating ? LL.ADD(0) : LL.UPDATE()}
|
||||||
</Button>
|
</Button>
|
||||||
|
{editItem.flags === 0 && editItem.cmd !== '' && (
|
||||||
|
<Button
|
||||||
|
startIcon={<DoneIcon />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={saveandactivate}
|
||||||
|
color="warning"
|
||||||
|
>
|
||||||
|
{LL.EXECUTE()}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void WebScheduler::read(WebScheduler & webScheduler, JsonObject root) {
|
|||||||
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
||||||
JsonObject si = schedule.add<JsonObject>();
|
JsonObject si = schedule.add<JsonObject>();
|
||||||
si["id"] = counter++; // id is only used to render the table and must be unique
|
si["id"] = counter++; // id is only used to render the table and must be unique
|
||||||
si["active"] = scheduleItem.active;
|
si["active"] = scheduleItem.flags ? scheduleItem.active : false;
|
||||||
si["flags"] = scheduleItem.flags;
|
si["flags"] = scheduleItem.flags;
|
||||||
si["time"] = scheduleItem.time;
|
si["time"] = scheduleItem.time;
|
||||||
si["cmd"] = scheduleItem.cmd;
|
si["cmd"] = scheduleItem.cmd;
|
||||||
@@ -198,7 +198,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
|||||||
output["onchange"] = scheduleItem.time;
|
output["onchange"] = scheduleItem.time;
|
||||||
} else if (scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_TIMER) {
|
} else if (scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_TIMER) {
|
||||||
output["timer"] = scheduleItem.time;
|
output["timer"] = scheduleItem.time;
|
||||||
} else {
|
} else if (scheduleItem.flags != 0){
|
||||||
output["time"] = scheduleItem.time;
|
output["time"] = scheduleItem.time;
|
||||||
}
|
}
|
||||||
output["command"] = scheduleItem.cmd;
|
output["command"] = scheduleItem.cmd;
|
||||||
@@ -488,6 +488,13 @@ void WebSchedulerService::loop() {
|
|||||||
cmd_changed_.pop_front();
|
cmd_changed_.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||||
|
if (scheduleItem.active && scheduleItem.flags == 0) {
|
||||||
|
command(scheduleItem.name.c_str(), scheduleItem.cmd, compute(scheduleItem.value));
|
||||||
|
scheduleItem.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check conditions every 10 seconds
|
// check conditions every 10 seconds
|
||||||
uint32_t uptime_sec = uuid::get_uptime_sec() / 10;
|
uint32_t uptime_sec = uuid::get_uptime_sec() / 10;
|
||||||
if (last_uptime_sec != uptime_sec) {
|
if (last_uptime_sec != uptime_sec) {
|
||||||
@@ -544,7 +551,7 @@ void WebSchedulerService::loop() {
|
|||||||
// process schedules async
|
// process schedules async
|
||||||
void WebSchedulerService::scheduler_task(void * pvParameters) {
|
void WebSchedulerService::scheduler_task(void * pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
delay(100); // no need to hurry
|
delay(10); // no need to hurry
|
||||||
if (!EMSESP::system_.upload_status()) {
|
if (!EMSESP::system_.upload_status()) {
|
||||||
EMSESP::webSchedulerService.loop();
|
EMSESP::webSchedulerService.loop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user