From 97a27310e2456e3df2a99c2f670641520fc6feb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 19 Aug 2017 16:33:10 +0200 Subject: [PATCH] Handle relay status tracking in scheduler --- code/espurna/relay.ino | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 18811078..a299c961 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -153,7 +153,15 @@ bool relayStatus(unsigned char id, bool status, bool report) { bool changed = false; #if TRACK_RELAY_STATUS - if (relayStatus(id) != status) { + if (relayStatus(id) == status) { + if (_relays[id].scheduled) { + DEBUG_MSG_P(PSTR("[RELAY] #%d scheduled change cancelled\n"), id); + _relays[id].scheduled = false; + _relays[id].scheduledStatus = status; + _relays[id].scheduledReport = false; + changed = true; + } + } else { #endif unsigned int currentTime = millis(); @@ -467,11 +475,7 @@ void relayLoop(void) { unsigned int currentTime = millis(); bool status = _relays[id].scheduledStatus; - #if TRACK_RELAY_STATUS - if (relayStatus(id) != status && currentTime >= _relays[id].scheduledStatusTime) { - #else if (_relays[id].scheduled && currentTime >= _relays[id].scheduledStatusTime) { - #endif DEBUG_MSG_P(PSTR("[RELAY] #%d set to %s\n"), id, status ? "ON" : "OFF");