1
0

Rework watch module

This commit is contained in:
2024-01-04 06:26:47 +01:00
parent fe6f6e3d51
commit 37c0057aad
2 changed files with 62 additions and 64 deletions

View File

@@ -32,21 +32,12 @@ class Equipment {
// Initialization of properties
this.name = this.equipmentItem.name;
this.watch = new Object();
this.timers = new timer.Timer();
// Check if equipment has state item
if (this.hasProperty('State')) {
this.stateItem = items[this.getPropertyItemName('State')];
this.watch['State'] = new watch.Watch(this.stateItem);
} else {
console.info(`Item ${this.equipmentItem.name} has no state item`)
}
// Check if equipment has LowBat item
if (this.hasProperty('LowBat')) {
this.watch['LowBat'] = new watch.Watch(this.getPropertyItemName('LowBat'));
this.watch['LowBat'].add({
watches.add({
item: this.getPropertyItemName('LowBat'),
targetState: 'ON',
alertFunc: () => { this.#notifyLowBat(); },
alertRepeat: 'PT23H'
@@ -55,8 +46,8 @@ class Equipment {
// Check if equipment has Unreach item
if (this.hasProperty('Unreach')) {
this.watch['Unreach'] = new watch.Watch(this.getPropertyItemName('Unreach'));
this.watch['Unreach'].add({
watches.add({
item: this.getPropertyItemName('Unreach'),
targetState: 'ON',
alertFunc: () => { this.#notifyUnreach(); },
alertDelay: 'PT15M',
@@ -110,12 +101,7 @@ class Equipment {
}
gc() {
console.log('Denitialization of eqipment ' + this.name);
// Delete all watchObjects
for (let watchItem of Object.keys(this.watch)) {
this.watch[watchItem].deleteAll();
}
console.log('Denitialization of equipment ' + this.name);
// Cancel all timers
this.timers.cancelAll();
@@ -139,12 +125,13 @@ class CCTV extends Equipment {
super(equipmentItem);
// Watch
this.watch['AP_ResidentsAreHome'] = new watch.Watch('AP_ResidentsAreHome');
this.watch['AP_ResidentsAreHome'].add({
watches.add({
item: 'AP_ResidentsAreHome',
targetState: 'ON',
alertFunc: () => { this.setHomeMode('ON'); }
});
this.watch['AP_ResidentsAreHome'].add({
watches.add({
item: 'AP_ResidentsAreHome',
targetState: 'OFF',
alertFunc: () => { this.setHomeMode('OFF'); },
alertDelay: 'PT1M'
@@ -229,6 +216,7 @@ class Doorbell extends Equipment {
super(equipmentItem);
this.watch['State'].add({
item: this.getPropertyItemName('State'),
targetState: 'ON',
alertFunc: () => { items.getItem("OF_Alexa_Desk_TTS").sendCommand('Es hat geklingelt'); items.getItem("LR_Alexa_TV_TTS").sendCommand('Es hat geklingelt'); }
});
@@ -243,7 +231,8 @@ class Irrigation extends Equipment {
this.valves = new Object();
// Add on/off watch rule
this.watch['State'].add({
watches.add({
item: this.getPropertyItemName('State'),
targetState: 'ON',
alertFunc: () => { this.#irrigationOn(); },
endAlertFunc: () => { this.#irrigationOff(); },
@@ -346,7 +335,8 @@ class IrrigationValve extends Equipment {
constructor(equipmentItem) {
super(equipmentItem);
this.watch['State'].add({
watches.add({
item: this.getPropertyItemName('State'),
targetState: 'ON',
alertFunc: () => { this.stateItem.sendCommand('OFF'); },
alertDelay: 'PT30M'
@@ -376,7 +366,8 @@ class TowelRadiator extends Equipment {
constructor(equipmentItem) {
super(equipmentItem);
this.watch['State'].add({
watches.add({
item: this.getPropertyItemName('State'),
targetState: 'ON',
alertFunc: () => { this.stateItem.sendCommand('OFF'); },
alertDelay: 'PT59M'
@@ -403,7 +394,7 @@ class Window extends Equipment {
}
const watches = new watch.Watch();
const eMgr = new Object();
for (let equipmentItem of items.getItems().filter(element => { return (element.semantics.isEquipment == true) && (element.semantics.equipment == null) })) {
@@ -430,7 +421,9 @@ cache.shared.put('eMgr', eMgr);
require('@runtime').lifecycleTracker.addDisposeHook(() => {
console.log('Deinitialization of equipmentMgr');
watches.deleteAll();
for (let equipmentItemName of Object.keys(eMgr)) {
eMgr[equipmentItemName].gc();
}
});
});