merge update_pool() into update_temp()

This commit is contained in:
Gilles Grandou 2022-04-21 11:31:12 +02:00
parent 87c43ff253
commit 57549371e2

72
pool.js
View File

@ -11,11 +11,11 @@ let status = {
update_temp_max_last: null, update_temp_max_last: null,
disable_temp: null, disable_temp: null,
lock_update: false,
tick_mqtt: 0,
tick_temp: 0, tick_temp: 0,
tick_pool: 0,
tick_pump: 0, tick_pump: 0,
tick_timer: 0,
tick_day: 0, tick_day: 0,
}; };
@ -76,32 +76,6 @@ function time_to_timespec(t) {
return ts; return ts;
} }
// update temperature from Sensor
// - trigger pump update if needed
function update_temp(temp) {
status.tick_temp++;
print("[POOL] update_temp", status.tick_temp, temp);
if (status.disable_temp !== null) {
print("[POOL] updated disabled");
return;
}
status.temp = temp;
status.temp_today = Math.max(status.temp_today, temp);
status.temp_max = Math.max(status.temp_today, status.temp_yesterday);
print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday);
if (status.temp_max !== status.update_temp_max_last) {
update_pool();
}
else {
print("[POOL] no temp change, skip update_pool");
}
}
// new day, update status // new day, update status
function update_new_day() { function update_new_day() {
@ -184,15 +158,35 @@ function update_pump(temp, max, time) {
do_call(calls); do_call(calls);
} }
// update pool: // update temperature from Sensor
// - update max temp
// - retrieve current time // - retrieve current time
// - switch to next day // - switch to new day
// - do a pump update if the last one didn't not happen too close // - do a pump update if the last one didn't happen too close and if max temp has changed
function update_pool() { function update_temp(temp) {
status.tick_pool++; status.tick_temp++;
print("update_pool", status.tick_pool);
print("[POOL] update_temp", status.tick_temp, temp);
if (status.disable_temp !== null) {
print("[POOL] updated disabled");
return;
}
if (status.lock_update) {
print("[POOL] update_temp locked");
return;
}
status.lock_update = true;
status.temp = temp;
status.temp_today = Math.max(status.temp_today, temp);
status.temp_max = Math.max(status.temp_today, status.temp_yesterday);
print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday);
if (status.temp_max !== status.update_temp_max_last) {
Shelly.call ( Shelly.call (
"Sys.GetStatus", "Sys.GetStatus",
{}, {},
@ -215,12 +209,18 @@ function update_pool() {
status.update_temp_max_last = status.temp_max; status.update_temp_max_last = status.temp_max;
} }
else { else {
print("[POOL] to much update_pool, skipped"); print("[POOL] to much update_pump, skipped");
} }
} }
} }
); );
} }
else {
print("[POOL] no temp change, skip update_pump");
}
status.lock_update = false;
}
// receives update from Pool Sensor // receives update from Pool Sensor
// - trigger all temperature and pump updates // - trigger all temperature and pump updates
@ -228,6 +228,8 @@ function update_pool() {
MQTT.subscribe( MQTT.subscribe(
"zigbee2mqtt/Piscine", "zigbee2mqtt/Piscine",
function (topic, msg) { function (topic, msg) {
status.tick_mqtt++;
print("[POOL] mqtt", topic);
let obj = JSON.parse(msg); let obj = JSON.parse(msg);
if (obj.temperature === undefined) { if (obj.temperature === undefined) {
return; return;