mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
scheduler single action on command
This commit is contained in:
@@ -283,7 +283,9 @@ const Scheduler: FC = () => {
|
||||
<Cell stiff>
|
||||
<Stack spacing={0.5} direction="row">
|
||||
<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_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 = () => {
|
||||
editItem.deleted = true;
|
||||
onSave(editItem);
|
||||
@@ -326,36 +337,36 @@ const SchedulerDialog = ({
|
||||
</>
|
||||
)}
|
||||
</Grid>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="cmd"
|
||||
label={LL.COMMAND(0)}
|
||||
multiline
|
||||
fullWidth
|
||||
value={editItem.cmd}
|
||||
margin="normal"
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
<TextField
|
||||
name="value"
|
||||
label={LL.VALUE(0)}
|
||||
multiline
|
||||
margin="normal"
|
||||
fullWidth
|
||||
value={editItem.value}
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="name"
|
||||
label={LL.NAME(0) + ' (' + LL.OPTIONAL() + ')'}
|
||||
value={editItem.name}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="cmd"
|
||||
label={LL.COMMAND(0)}
|
||||
multiline
|
||||
fullWidth
|
||||
value={editItem.cmd}
|
||||
margin="normal"
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
<TextField
|
||||
name="value"
|
||||
label={LL.VALUE(0)}
|
||||
multiline
|
||||
margin="normal"
|
||||
fullWidth
|
||||
value={editItem.value}
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="name"
|
||||
label={LL.NAME(0) + ' (' + LL.OPTIONAL() + ')'}
|
||||
value={editItem.name}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
onChange={updateFormValue}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
{!creating && (
|
||||
@@ -386,6 +397,16 @@ const SchedulerDialog = ({
|
||||
>
|
||||
{creating ? LL.ADD(0) : LL.UPDATE()}
|
||||
</Button>
|
||||
{editItem.flags === 0 && editItem.cmd !== '' && (
|
||||
<Button
|
||||
startIcon={<DoneIcon />}
|
||||
variant="outlined"
|
||||
onClick={saveandactivate}
|
||||
color="warning"
|
||||
>
|
||||
{LL.EXECUTE()}
|
||||
</Button>
|
||||
)}
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -51,7 +51,7 @@ void WebScheduler::read(WebScheduler & webScheduler, JsonObject root) {
|
||||
for (const ScheduleItem & scheduleItem : webScheduler.scheduleItems) {
|
||||
JsonObject si = schedule.add<JsonObject>();
|
||||
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["time"] = scheduleItem.time;
|
||||
si["cmd"] = scheduleItem.cmd;
|
||||
@@ -198,7 +198,7 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
||||
output["onchange"] = scheduleItem.time;
|
||||
} else if (scheduleItem.flags == SCHEDULEFLAG_SCHEDULE_TIMER) {
|
||||
output["timer"] = scheduleItem.time;
|
||||
} else {
|
||||
} else if (scheduleItem.flags != 0){
|
||||
output["time"] = scheduleItem.time;
|
||||
}
|
||||
output["command"] = scheduleItem.cmd;
|
||||
@@ -488,6 +488,13 @@ void WebSchedulerService::loop() {
|
||||
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
|
||||
uint32_t uptime_sec = uuid::get_uptime_sec() / 10;
|
||||
if (last_uptime_sec != uptime_sec) {
|
||||
@@ -544,7 +551,7 @@ void WebSchedulerService::loop() {
|
||||
// process schedules async
|
||||
void WebSchedulerService::scheduler_task(void * pvParameters) {
|
||||
while (1) {
|
||||
delay(100); // no need to hurry
|
||||
delay(10); // no need to hurry
|
||||
if (!EMSESP::system_.upload_status()) {
|
||||
EMSESP::webSchedulerService.loop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user