pool: switch fix when schedule is [off, on]

This commit is contained in:
Gilles Grandou 2022-06-19 16:04:44 +02:00
parent f3c444d0de
commit 34143560a7
1 changed files with 14 additions and 5 deletions

19
pool.js
View File

@ -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<b && time >= 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}});