1
0

Rework constructur

This commit is contained in:
2023-08-16 02:14:19 +02:00
parent 8a214aa1b9
commit a24b4c0b75

View File

@@ -3,17 +3,30 @@ console.log('Load equipment modules');
class Equipment {
constructor(equipmentItem) {
console.info(`Initialization of eqipment ${equipmentItem.name} with type ${this.constructor.name}`);
// Set equipmentItem
this.equipmentItem = equipmentItem;
// Fetch item if provided equipmentItem is a string
if (typeof equipmentItem === 'string' || equipmentItem instanceof String) {
this.equipmentItem = items[equipmentItem];
} else {
this.equipmentItem = equipmentItem;
}
// Throw error if item is not existing
if (this.equipmentItem === null) {
throw(`Item ${equipmentItem} not existing`);
}
// Throw error if item is not an equipment type
if (this.equipmentItem.semantics.semanticType != 'Equipment') {
throw(`Item ${this.equipmentItem.name} is not an equipment type`);
}
console.info(`Initialization of equipment ${this.equipmentItem.name} with type ${this.constructor.name}`);
// 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')];
this.watch = new Object();
// Check if equipment has LowBat item
if (this.hasProperty('LowBat')) {