Skip to content

Commit

Permalink
Option to disable schedules without delting them (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Jan 22, 2018
1 parent c3f5596 commit f729585
Show file tree
Hide file tree
Showing 5 changed files with 2,286 additions and 2,275 deletions.
Binary file modified code/espurna/data/index.html.gz
Binary file not shown.
19 changes: 13 additions & 6 deletions code/espurna/scheduler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ void _schWebSocketOnSend(JsonObject &root){
for (byte i = 0; i < SCHEDULER_MAX_SCHEDULES; i++) {
if (!hasSetting("schSwitch", i)) break;
JsonObject &scheduler = sch.createNestedObject();
scheduler["schSwitch"] = getSetting("schSwitch", i, "");
scheduler["schAction"] = getSetting("schAction", i, "");
scheduler["schHour"] = getSetting("schHour", i, "");
scheduler["schMinute"] = getSetting("schMinute", i, "");
scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1;
scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt();
scheduler["schAction"] = getSetting("schAction", i, 0).toInt();
scheduler["schHour"] = getSetting("schHour", i, 0).toInt();
scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt();
scheduler["schWDs"] = getSetting("schWDs", i, "");
}
}
Expand All @@ -45,6 +46,7 @@ void _schConfigure() {

if (delete_flag) {

delSetting("schEnabled", i);
delSetting("schSwitch", i);
delSetting("schAction", i);
delSetting("schHour", i);
Expand All @@ -55,14 +57,16 @@ void _schConfigure() {

#if DEBUG_SUPPORT

int sch_enabled = getSetting("schEnabled", i, 1).toInt() == 1;
int sch_action = getSetting("schAction", i, 0).toInt();
int sch_hour = getSetting("schHour", i, 0).toInt();
int sch_minute = getSetting("schMinute", i, 0).toInt();
String sch_weekdays = getSetting("schWDs", i, "");
DEBUG_MSG_P(
PSTR("[SCH] Schedule #%d: %s switch #%d at %02d:%02d on %s\n"),
PSTR("[SCH] Schedule #%d: %s switch #%d at %02d:%02d on %s%s\n"),
i, sch_action == 0 ? "turn OFF" : sch_action == 1 ? "turn ON" : "toggle", sch_switch,
sch_hour, sch_minute, (char *) sch_weekdays.c_str()
sch_hour, sch_minute, (char *) sch_weekdays.c_str(),
sch_enabled ? "" : " (disabled)"
);

#endif // DEBUG_SUPPORT
Expand Down Expand Up @@ -104,6 +108,9 @@ void _schCheck() {
int sch_switch = getSetting("schSwitch", i, 0xFF).toInt();
if (sch_switch == 0xFF) break;

// Skip disabled schedules
if (getSetting("schEnabled", i, 1).toInt() == 0) continue;

String sch_weekdays = getSetting("schWDs", i, "");
if (_schIsThisWeekday(sch_weekdays)) {

Expand Down
Loading

0 comments on commit f729585

Please sign in to comment.