From 34143560a79693674f59583a300e7db159bf0de8 Mon Sep 17 00:00:00 2001 From: Gilles Grandou Date: Sun, 19 Jun 2022 16:04:44 +0200 Subject: [PATCH] pool: switch fix when schedule is [off, on] --- pool.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pool.js b/pool.js index 7e73457..a99c277 100644 --- a/pool.js +++ b/pool.js @@ -158,11 +158,20 @@ function update_pump(temp, max, time) { // compute the current switch state according to the schedule let on = false; - let j = false; - for (let i = 0; i < schedule.length; i++) { - j = !j; - if (time >= schedule[i]) - on = j; + if (schedule.length === 1) { + on = true; + } + else { + for (let i = 0; i < schedule.length; i+=2) { + let a=schedule[i]; + let b=schedule[i+1]; + if (a= a && time < b) { + on = true; + } + else if (a>b && (time >= a || time < b)) { + on = true; + } + } } calls.push({method: "Switch.Set", params: {id: 0, on: on}});