Various improvements
This commit is contained in:
@@ -3,21 +3,31 @@ console.log('Load equipment modules');
|
|||||||
|
|
||||||
class Equipment {
|
class Equipment {
|
||||||
constructor(equipmentItem) {
|
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
|
// Set equipmentItem
|
||||||
this.equipmentItem = equipmentItem;
|
this.equipmentItem = equipmentItem;
|
||||||
|
|
||||||
// Set stateItem, toDo: error when no stateItem existing
|
|
||||||
this.stateItem = items[this.equipmentItem.name + '_State'];
|
|
||||||
|
|
||||||
// Initialization of properties
|
// Initialization of properties
|
||||||
this.name = this.equipmentItem.name;
|
this.name = this.equipmentItem.name;
|
||||||
this.watch = new Object();
|
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 = '') {
|
getValue(propertyName, defaultValue = '') {
|
||||||
let valueItemName = this.name + '_' + valueName;
|
let valueItemName = this.name + '_' + propertyName;
|
||||||
let returnValue = defaultValue;
|
let returnValue = defaultValue;
|
||||||
|
|
||||||
if (items[valueItemName] == null) { // Return default value if item is missing
|
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;
|
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() {
|
gc() {
|
||||||
console.log('Denitialization of eqipment ' + this.name);
|
console.log('Denitialization of eqipment ' + this.name);
|
||||||
|
|
||||||
@@ -59,7 +87,7 @@ class IrrigationValve extends Equipment {
|
|||||||
super(equipmentItem);
|
super(equipmentItem);
|
||||||
|
|
||||||
this.watch['state'] = new watch.Watch(this.stateItem.name);
|
this.watch['state'] = new watch.Watch(this.stateItem.name);
|
||||||
this.autoOff = this.watch['state'].add({
|
this.watch['state'].add({
|
||||||
targetState: 'ON',
|
targetState: 'ON',
|
||||||
alertFunc: () => { this.stateItem.sendCommand('OFF'); },
|
alertFunc: () => { this.stateItem.sendCommand('OFF'); },
|
||||||
alertDelay: 'PT59M'
|
alertDelay: 'PT59M'
|
||||||
@@ -92,6 +120,4 @@ module.exports = {
|
|||||||
IrrigationValve,
|
IrrigationValve,
|
||||||
TowelRadiator,
|
TowelRadiator,
|
||||||
WeatherService
|
WeatherService
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user