1
0

Various improvements

This commit is contained in:
2023-08-15 17:26:16 +02:00
parent 8032e1cd83
commit 8a214aa1b9

View File

@@ -3,21 +3,31 @@ console.log('Load equipment modules');
class Equipment {
constructor(equipmentItem) {
console.info('Initialization of eqipment ' + equipmentItem.name + ' with type ' + this.constructor.name);
console.info(`Initialization of eqipment ${equipmentItem.name} with type ${this.constructor.name}`);
// Set equipmentItem
this.equipmentItem = equipmentItem;
// Set stateItem, toDo: error when no stateItem existing
this.stateItem = items[this.equipmentItem.name + '_State'];
// Initialization of properties
this.name = this.equipmentItem.name;
this.watch = new Object();
// Set stateItem, toDo: error when no stateItem existing
this.stateItem = items[this.getPropertyItemName('State')];
// Check if equipment has LowBat item
if (this.hasProperty('LowBat')) {
this.watch['lowBat'] = new watch.Watch(this.getPropertyItemName('LowBat'));
this.watch['lowBat'].add({
targetState: 'ON',
alertFunc: () => { this.#notifyLowBat(); },
alertRepeat: 'PT23H'
});
}
}
getValue(valueName, defaultValue = '') {
let valueItemName = this.name + '_' + valueName;
getValue(propertyName, defaultValue = '') {
let valueItemName = this.name + '_' + propertyName;
let returnValue = defaultValue;
if (items[valueItemName] == null) { // Return default value if item is missing
@@ -34,10 +44,28 @@ class Equipment {
}
}
console.debug('Return value ' + valueName + ' for ' + this.name + ': ' + returnValue);
console.debug(`Return value ${valueName} for ${this.name}: ${returnValue}`);
return returnValue;
}
getPropertyItemName(propertyName) {
if (this.hasProperty(propertyName)) {
return items[this.name + '_' + propertyName].name;
}
}
hasProperty(propertyName) {
if (items[this.name + '_' + propertyName] == null) {
console.debug(`Eqipment ${this.name} has no property ${propertyName}`)
return false;
}
return true;
}
#notifyLowBat() {
console.warn(`${this.name} has a low battery level.`);
}
gc() {
console.log('Denitialization of eqipment ' + this.name);
@@ -59,7 +87,7 @@ class IrrigationValve extends Equipment {
super(equipmentItem);
this.watch['state'] = new watch.Watch(this.stateItem.name);
this.autoOff = this.watch['state'].add({
this.watch['state'].add({
targetState: 'ON',
alertFunc: () => { this.stateItem.sendCommand('OFF'); },
alertDelay: 'PT59M'
@@ -92,6 +120,4 @@ module.exports = {
IrrigationValve,
TowelRadiator,
WeatherService
};
};