1
0

Complete alertDelay and alertRepeat

This commit is contained in:
2023-08-15 17:17:21 +02:00
parent 949eb8e9a6
commit 8032e1cd83

View File

@@ -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,
};
};