Compare commits

..

3 Commits

Author SHA1 Message Date
f98edbb8d6 fix compute_schedule_filt: scoping bug and reserved word 'stop'
- 'let s' was declared inside if/else blocks (block-scoped),
  making it invisible to 'return s' outside — declare s before the blocks
- 'stop' is a reserved identifier in Espruino (Shelly JS engine),
  rename to t_start/t_stop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 17:51:40 +01:00
0c175b4a8e fix duplicate 'let on' declaration in update_pump()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 17:47:50 +01:00
f9a579529b stop script before upload, restart after
Required since recent Shelly firmware update: Script.PutCode
fails with error -103 if the script is running.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 17:46:50 +01:00
2 changed files with 10 additions and 7 deletions

15
pool.js
View File

@@ -72,17 +72,18 @@ function compute_filtration_time(t) {
// [ start1, stop1, start2, stop2, ... ] // [ start1, stop1, start2, stop2, ... ]
function compute_schedule_filt(d) { function compute_schedule_filt(d) {
let start = 17 - d/2; let t_start = 17 - d/2;
let stop = 17 + d/2; let t_stop = 17 + d/2;
while (stop >= 24) while (t_stop >= 24)
stop = stop - 24; t_stop = t_stop - 24;
let s;
if (d < 24) { if (d < 24) {
let s = [ start, stop ]; s = [ t_start, t_stop ];
} }
else { else {
let s = [ start ]; s = [ t_start ];
} }
return s; return s;
@@ -183,7 +184,7 @@ function update_pump(temp, max, time) {
} }
// compute the current switch state according to the schedule // compute the current switch state according to the schedule
let on = false; on = false;
if (schedule.length === 1) { if (schedule.length === 1) {
on = true; on = true;
} }

View File

@@ -2,4 +2,6 @@
source $(dirname $0)/shelly.conf source $(dirname $0)/shelly.conf
curl -s "$SHELLY_RPC/Script.Stop?id=$SCRIPT_ID" | jq .
$ROOT_DIR/put_script $SHELLY_HOST $SCRIPT_ID $ROOT_DIR/$SCRIPT_FILENAME $ROOT_DIR/put_script $SHELLY_HOST $SCRIPT_ID $ROOT_DIR/$SCRIPT_FILENAME
curl -s "$SHELLY_RPC/Script.Start?id=$SCRIPT_ID" | jq .