Switch to timer module
This commit is contained in:
@@ -4,6 +4,7 @@ console.log('Load equipmentMgr');
|
|||||||
const {
|
const {
|
||||||
equipment,
|
equipment,
|
||||||
lib,
|
lib,
|
||||||
|
timer,
|
||||||
watch
|
watch
|
||||||
} = require('../utils');
|
} = require('../utils');
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Equipment {
|
|||||||
this.name = this.equipmentItem.name;
|
this.name = this.equipmentItem.name;
|
||||||
|
|
||||||
this.watch = new Object();
|
this.watch = new Object();
|
||||||
this.timers = new Object();
|
this.timers = new timer.Timer();
|
||||||
|
|
||||||
// Check if equipment has state item
|
// Check if equipment has state item
|
||||||
if (this.hasProperty('State')) {
|
if (this.hasProperty('State')) {
|
||||||
@@ -110,6 +110,9 @@ class Equipment {
|
|||||||
for (let watchItem of Object.keys(this.watch)) {
|
for (let watchItem of Object.keys(this.watch)) {
|
||||||
this.watch[watchItem].deleteAll();
|
this.watch[watchItem].deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cancel all timers
|
||||||
|
this.timers.cancelAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,14 +179,16 @@ class Irrigation extends Equipment {
|
|||||||
let endTime = time.toZDT(totalDuration);
|
let endTime = time.toZDT(totalDuration);
|
||||||
|
|
||||||
// Set timers for valve
|
// Set timers for valve
|
||||||
this.valves[currentValve].timers['autoOn'] = actions.ScriptExecution.createTimer(
|
this.valves[currentValve].timers.create(
|
||||||
|
'autoOn',
|
||||||
startTime,
|
startTime,
|
||||||
() => {
|
() => {
|
||||||
this.valves[currentValve].stateItem.sendCommandIfDifferent('ON');
|
this.valves[currentValve].stateItem.sendCommandIfDifferent('ON');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.valves[currentValve].timers['autoOff'] = actions.ScriptExecution.createTimer(
|
this.valves[currentValve].timers.create(
|
||||||
|
'autoOff',
|
||||||
endTime,
|
endTime,
|
||||||
() => {
|
() => {
|
||||||
this.valves[currentValve].stateItem.sendCommandIfDifferent('OFF');
|
this.valves[currentValve].stateItem.sendCommandIfDifferent('OFF');
|
||||||
@@ -193,7 +198,8 @@ class Irrigation extends Equipment {
|
|||||||
// Stop irrigation after the last valve
|
// Stop irrigation after the last valve
|
||||||
if (nextValve == undefined) {
|
if (nextValve == undefined) {
|
||||||
console.log('No further valves with autoMode enabled available');
|
console.log('No further valves with autoMode enabled available');
|
||||||
this.timers['autoOff'] = actions.ScriptExecution.createTimer(
|
this.timers.create(
|
||||||
|
'autoOff',
|
||||||
endTime.plusSeconds(5),
|
endTime.plusSeconds(5),
|
||||||
() => {
|
() => {
|
||||||
console.debug(`Switch irrigation ${this.name} to off`)
|
console.debug(`Switch irrigation ${this.name} to off`)
|
||||||
@@ -207,20 +213,11 @@ class Irrigation extends Equipment {
|
|||||||
#irrigationOff() {
|
#irrigationOff() {
|
||||||
console.info(`Irrigation ${this.name} received command off`);
|
console.info(`Irrigation ${this.name} received command off`);
|
||||||
|
|
||||||
if (this.timers.hasOwnProperty('autoOff') && this.timers['autoOff'].isActive()) {
|
this.timers.cancel('autoOff')
|
||||||
console.debug(`Cancel stop timer for irrigation`);
|
|
||||||
this.timers['autoOff'].cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let valve of Object.keys(this.valves)) {
|
for (let valve of Object.keys(this.valves)) {
|
||||||
if (this.valves[valve].timers.hasOwnProperty('autoOn') && this.valves[valve].timers['autoOn'].isActive()) {
|
this.valves[valve].timers.cancel('autoOn');
|
||||||
console.debug(`Cancel start timer for valve ${valve}`);
|
this.valves[valve].timers.cancel('autoOff');
|
||||||
this.valves[valve].timers['autoOn'].cancel();
|
|
||||||
}
|
|
||||||
if (this.valves[valve].timers.hasOwnProperty('autoOff') && this.valves[valve].timers['autoOff'].isActive()) {
|
|
||||||
console.debug(`Cancel stop timer for valve ${valve}`);
|
|
||||||
this.valves[valve].timers['autoOff'].cancel();
|
|
||||||
}
|
|
||||||
this.valves[valve].stateItem.sendCommandIfDifferent('OFF')
|
this.valves[valve].stateItem.sendCommandIfDifferent('OFF')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user