Skip to content

Commit

Permalink
scheduler: midnight as default HH:MM
Browse files Browse the repository at this point in the history
allow just "UTC", "Monday", "05-01", etc.
clarify webui paragraph and mention KEYWORD as an element

ignore sunrise and sunset keywords when sun module is disabled

move all of parsing to time module, test whether combined match works
  • Loading branch information
mcspr committed May 27, 2024
1 parent 17a599f commit d6f807d
Show file tree
Hide file tree
Showing 25 changed files with 11,097 additions and 10,754 deletions.
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.curtain.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.garland.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.thermostat.html.gz
Binary file not shown.
58 changes: 9 additions & 49 deletions code/espurna/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,55 +321,7 @@ struct Parsed {
};

Schedule schedule(size_t index) {
Schedule out;

bool parsed_date { false };
bool parsed_weekdays { false };
bool parsed_time { false };

const auto time = settings::time(index);
auto split = SplitStringView(time);

while (split.next()) {
auto elem = split.current();

// most expected order, starting with date
if (!parsed_date && ((parsed_date = parse_date(out.date, elem)))) {
continue;
}

// then weekdays
if (!parsed_weekdays && ((parsed_weekdays = parse_weekdays(out.weekdays, elem)))) {
continue;
}

// then time
if (!parsed_time && ((parsed_time = parse_time(out.time, elem)))) {
continue;
}

// and keyword is always at the end. forcibly stop the parsing, regardless of the state
if (parse_time_keyword(out.time, elem)) {
if (want_utc(out.time)) {
break;
}

#if SCHEDULER_SUN_SUPPORT
// do not want both time and sun{rise,set}
if (want_sunrise_sunset(out.time)) {
parsed_time = !parsed_time;
}
#endif

break;
}
}

out.ok = parsed_date
|| parsed_weekdays
|| parsed_time;

return out;
return parse_schedule(settings::time(index));
}

size_t count() {
Expand Down Expand Up @@ -1339,6 +1291,10 @@ void run_today(Context& ctx) {
context_pending(ctx, index, schedule);
continue;
}
#else
if (want_sunrise_sunset(schedule.time)) {
continue;
}
#endif

handle_today(ctx, index, schedule);
Expand Down Expand Up @@ -1394,6 +1350,10 @@ void check(const datetime::Context& ctx) {
if (!sun::update_schedule(schedule)) {
continue;
}
#else
if (want_sunrise_sunset(schedule.time)) {
continue;
}
#endif

const auto& time = select_time(ctx, schedule);
Expand Down
69 changes: 69 additions & 0 deletions code/espurna/scheduler_time.re
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,75 @@ using parse::parse_weekdays;
using parse::parse_time;
using parse::parse_time_keyword;

Schedule parse_schedule(StringView view) {
Schedule out;

// DATE " " WDS " " TIME " " KW
const auto spaces = std::count(view.begin(), view.end(), ' ');
if (spaces > 3) {
return out;
}

auto split = SplitStringView(view);

bool parsed_date { false };
bool parsed_weekdays { false };
bool parsed_time { false };
bool parsed_keyword { false };

int parsed { 0 };

while (split.next()) {
auto elem = split.current();

// most expected order, starting with date
if (!parsed_date && ((parsed_date = parse_date(out.date, elem)))) {
++parsed;
continue;
}

// then weekdays
if (!parsed_weekdays && ((parsed_weekdays = parse_weekdays(out.weekdays, elem)))) {
++parsed;
continue;
}

// then time
if (!parsed_time && ((parsed_time = parse_time(out.time, elem)))) {
++parsed;
continue;
}

// and keyword is always at the end. forcibly stop the parsing, regardless of the state
if ((parsed_keyword = parse_time_keyword(out.time, elem))) {
++parsed;
break;
}
}

// expect one of each element, plus optional keyword
if (parsed != (1 + spaces)) {
return out;
}

// do not want both time and sun{rise,set}
if (want_sunrise_sunset(out.time) && parsed_time) {
return out;
}

out.ok = parsed_date
|| parsed_weekdays
|| parsed_time
|| parsed_keyword;

if (out.ok && !parsed_time && !want_sunrise_sunset(out.time)) {
out.time.hour = 0b1;
out.time.minute = 0b1;
}

return out;
}

} // namespace
} // namespace scheduler
} // namespace espurna
69 changes: 69 additions & 0 deletions code/espurna/scheduler_time.re.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,75 @@ using parse::parse_weekdays;
using parse::parse_time;
using parse::parse_time_keyword;

Schedule parse_schedule(StringView view) {
Schedule out;

// DATE " " WDS " " TIME " " KW
const auto spaces = std::count(view.begin(), view.end(), ' ');
if (spaces > 3) {
return out;
}

auto split = SplitStringView(view);

bool parsed_date { false };
bool parsed_weekdays { false };
bool parsed_time { false };
bool parsed_keyword { false };

int parsed { 0 };

while (split.next()) {
auto elem = split.current();

// most expected order, starting with date
if (!parsed_date && ((parsed_date = parse_date(out.date, elem)))) {
++parsed;
continue;
}

// then weekdays
if (!parsed_weekdays && ((parsed_weekdays = parse_weekdays(out.weekdays, elem)))) {
++parsed;
continue;
}

// then time
if (!parsed_time && ((parsed_time = parse_time(out.time, elem)))) {
++parsed;
continue;
}

// and keyword is always at the end. forcibly stop the parsing, regardless of the state
if ((parsed_keyword = parse_time_keyword(out.time, elem))) {
++parsed;
break;
}
}

// expect one of each element, plus optional keyword
if (parsed != (1 + spaces)) {
return out;
}

// do not want both time and sun{rise,set}
if (want_sunrise_sunset(out.time) && parsed_time) {
return out;
}

out.ok = parsed_date
|| parsed_weekdays
|| parsed_time
|| parsed_keyword;

if (out.ok && !parsed_time && !want_sunrise_sunset(out.time)) {
out.time.hour = 0b1;
out.time.minute = 0b1;
}

return out;
}

} // namespace
} // namespace scheduler
} // namespace espurna
Loading

0 comments on commit d6f807d

Please sign in to comment.