Switch to timer module
This commit is contained in:
@@ -6,6 +6,8 @@ class Watch {
|
|||||||
#watchItem
|
#watchItem
|
||||||
#watchObjects = new Object();
|
#watchObjects = new Object();
|
||||||
|
|
||||||
|
#timers = new timer.Timer();
|
||||||
|
|
||||||
constructor(watchItem) {
|
constructor(watchItem) {
|
||||||
|
|
||||||
// Fetch item if provided itemName is a string
|
// Fetch item if provided itemName is a string
|
||||||
@@ -64,16 +66,10 @@ class Watch {
|
|||||||
console.log(`Delete watch object for item ${this.#watchItem.name} with watchUUID ${watchUUID}`);
|
console.log(`Delete watch object for item ${this.#watchItem.name} with watchUUID ${watchUUID}`);
|
||||||
|
|
||||||
// End repeatAlertTimer if existing
|
// End repeatAlertTimer if existing
|
||||||
if (this.#watchObjects[watchUUID].hasOwnProperty('repeatAlertTimer') && this.#watchObjects[watchUUID].repeatAlertTimer.isActive()) {
|
this.#timers.cancel('repeatAlarm ' + watchUUID);
|
||||||
console.log('Cancel repeatAlertTimer for ' + watchUUID);
|
|
||||||
this.#watchObjects[watchUUID].repeatAlertTimer.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
// End startAlertTimer if existing
|
// End startAlertTimer if existing
|
||||||
if (this.#watchObjects[watchUUID].hasOwnProperty('startAlertTimer') && this.#watchObjects[watchUUID].startAlertTimer.isActive()) {
|
this.#timers.cancel('startAlert ' + watchUUID);
|
||||||
console.log('Cancel startAlertTimer for ' + watchUUID);
|
|
||||||
this.#watchObjects[watchUUID].startAlertTimer.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this.#watchObjects[watchUUID];
|
delete this.#watchObjects[watchUUID];
|
||||||
|
|
||||||
@@ -166,16 +162,10 @@ class Watch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End repeatAlertTimer if existing
|
// End repeatAlertTimer if existing
|
||||||
if (this.#watchObjects[watchUUID].hasOwnProperty('repeatAlertTimer') && this.#watchObjects[watchUUID].repeatAlertTimer.isActive()) {
|
this.#timers.cancel('repeatAlarm ' + watchUUID);
|
||||||
console.log('Cancel repeatAlertTimer');
|
|
||||||
this.#watchObjects[watchUUID].repeatAlertTimer.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
// End startAlertTimer if startAlert started timer with delay
|
// End startAlertTimer if startAlert started timer with delay
|
||||||
if (this.#watchObjects[watchUUID].hasOwnProperty('startAlertTimer') && this.#watchObjects[watchUUID].startAlertTimer.isActive()) {
|
this.#timers.cancel('startAlert ' + watchUUID);
|
||||||
console.log('Cancel startAlertTimer');
|
|
||||||
this.#watchObjects[watchUUID].startAlertTimer.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#processItemEvent(event) {
|
#processItemEvent(event) {
|
||||||
@@ -223,27 +213,26 @@ class Watch {
|
|||||||
let alertDelayZDT = time.toZDT(alertDelay);
|
let alertDelayZDT = time.toZDT(alertDelay);
|
||||||
alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000);
|
alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000);
|
||||||
|
|
||||||
this.#watchObjects[watchUUID].startAlertTimer = actions.ScriptExecution.createTimer('startAlert ' + watchUUID,
|
this.#timers.create('startAlert ' + watchUUID,
|
||||||
alertDelayZDT,
|
alertDelayZDT,
|
||||||
() => {
|
() => {
|
||||||
console.log('Run initial alert function for watchObject ' + watchUUID);
|
console.log('Run initial alert function for watchObject ' + watchUUID);
|
||||||
initialAlertFunc();
|
initialAlertFunc();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create timer to run repeat alert rule if required
|
// Create timer to run repeat alert rule if required
|
||||||
if (alertRepeat != '') {
|
if (alertRepeat != '') {
|
||||||
console.log(`Shedule repeat alert function for watchObject ${watchUUID} with repeat setting ${alertRepeat}`);
|
console.log(`Shedule repeat alert function for watchObject ${watchUUID} with repeat setting ${alertRepeat}`);
|
||||||
this.#watchObjects[watchUUID].repeatAlertTimer = actions.ScriptExecution.createTimer('repeatAlarm ' + watchUUID,
|
this.#timers.create('repeatAlarm ' + watchUUID,
|
||||||
time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute),
|
time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute),
|
||||||
() => {
|
() => {
|
||||||
console.log('Run repeat alert function for watchObject ' + watchUUID);
|
console.log('Run repeat alert function for watchObject ' + watchUUID);
|
||||||
this.#watchObjects[watchUUID].alertFunc();
|
this.#watchObjects[watchUUID].alertFunc();
|
||||||
this.#watchObjects[watchUUID].repeatAlertTimer.reschedule(time.toZDT(alertRepeat));
|
this.#watchObjects[watchUUID].repeatAlertTimer.reschedule(time.toZDT(alertRepeat));
|
||||||
}
|
}
|
||||||
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user