From 8032e1cd83b4e8d20e9727651170f4d7ca3cdc38 Mon Sep 17 00:00:00 2001 From: Christian Weimann Date: Tue, 15 Aug 2023 17:17:21 +0200 Subject: [PATCH] Complete alertDelay and alertRepeat --- utils/watch.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/utils/watch.js b/utils/watch.js index e7137cf..4d9752a 100644 --- a/utils/watch.js +++ b/utils/watch.js @@ -190,17 +190,25 @@ class Watch { initialAlertFunc = this.#watchObjects[watchUUID].initialAlertFunc; } + let alertDelay = this.#watchObjects[watchUUID].alertDelay; + let alertRepeat = this.#watchObjects[watchUUID].alertRepeat; + let alertDelayAbsolute = 0; + // Set alert state this.#watchObjects[watchUUID].alert = true; // Execute initial alert function or create timer to run initial alert rule if required - if (this.#watchObjects[watchUUID].alertDelay == '') { + if (alertDelay == '') { console.log(`Run initial alert function for watchObject ${watchUUID}`); initialAlertFunc(); } else { - console.log(`Run initial alert function for watchObject ${watchUUID} with delay setting ${this.#watchObjects[watchUUID].alertDelay}`); + console.log(`Shedule initial alert function for watchObject ${watchUUID} with delay setting ${alertDelay}`); + + let alertDelayZDT = time.toZDT(alertDelay); + alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000); + this.#watchObjects[watchUUID].startAlertTimer = actions.ScriptExecution.createTimer('startAlert ' + watchUUID, - time.toZDT(this.#watchObjects[watchUUID].alertDelay), + alertDelayZDT, () => { console.log('Run initial alert function for watchObject ' + watchUUID); initialAlertFunc(); @@ -209,13 +217,14 @@ class Watch { } // Create timer to run repeat alert rule if required - if (this.#watchObjects[watchUUID].alertRepeat != '') { + if (alertRepeat != '') { + console.log(`Shedule repeat alert function for watchObject ${watchUUID} with repeat setting ${alertRepeat}`); this.#watchObjects[watchUUID].repeatAlertTimer = actions.ScriptExecution.createTimer('repeatAlarm ' + watchUUID, - time.toZDT(this.#watchObjects[watchUUID].alertDelay + this.#watchObjects[watchUUID].alertRepeat), + time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute), () => { console.log('Run repeat alert function for watchObject ' + watchUUID); this.#watchObjects[watchUUID].alertFunc(); - this.#watchObjects[watchUUID].repeatAlertTimer.reschedule(time.ZonedDateTime.now().plusSeconds(this.#watchObjects[watchUUID].alertRepeat)); + this.#watchObjects[watchUUID].repeatAlertTimer.reschedule(time.toZDT(alertRepeat)); } ); @@ -225,4 +234,4 @@ class Watch { module.exports = { Watch, -}; \ No newline at end of file +};