bug fixes

This commit is contained in:
znetsixe
2025-07-02 10:54:01 +02:00
parent a2018509ef
commit 4665949c88
2 changed files with 37 additions and 29 deletions

View File

@@ -7,9 +7,11 @@ class ChildRegistrationUtils {
async registerChild(child, positionVsParent) { async registerChild(child, positionVsParent) {
this.logger.debug(`Registering child: ${child.id} with position=${positionVsParent}`);
const { softwareType } = child.config.functionality; const { softwareType } = child.config.functionality;
const { name, id, unit } = child.config.general; const { name, id, unit } = child.config.general;
const { type = "", subType = "" } = child.config.asset || {}; const { category = "", type = "" } = child.config.asset || {};
console.log(`Registering child: ${name}, id: ${id}, softwareType: ${softwareType}, category: ${category}, type: ${type}, positionVsParent: ${positionVsParent}` );
const emitter = child.emitter; const emitter = child.emitter;
//define position vs parent in child //define position vs parent in child
@@ -19,33 +21,33 @@ class ChildRegistrationUtils {
if (!this.mainClass.child) this.mainClass.child = {}; if (!this.mainClass.child) this.mainClass.child = {};
if (!this.mainClass.child[softwareType]) if (!this.mainClass.child[softwareType])
this.mainClass.child[softwareType] = {}; this.mainClass.child[softwareType] = {};
if (!this.mainClass.child[softwareType][type]) if (!this.mainClass.child[softwareType][category])
this.mainClass.child[softwareType][type] = {}; this.mainClass.child[softwareType][category] = {};
if (!this.mainClass.child[softwareType][type][subType]) if (!this.mainClass.child[softwareType][category][type])
this.mainClass.child[softwareType][type][subType] = {}; this.mainClass.child[softwareType][category][type] = {};
// Use an array to handle multiple subtypes // Use an array to handle multiple categories
if (!Array.isArray(this.mainClass.child[softwareType][type][subType])) { if (!Array.isArray(this.mainClass.child[softwareType][category][type])) {
this.mainClass.child[softwareType][type][subType] = []; this.mainClass.child[softwareType][category][type] = [];
} }
// Push the new child to the array of the mainclass so we can track the childs // Push the new child to the array of the mainclass so we can track the childs
this.mainClass.child[softwareType][type][subType].push({ this.mainClass.child[softwareType][category][type].push({
name, name,
id, id,
unit, unit,
emitter, emitter,
}); });
//then connect the child depending on the type subtype etc.. //then connect the child depending on the type type etc..
this.connectChild( this.connectChild(
id, id,
softwareType, softwareType,
emitter, emitter,
type, category,
child, child,
subType, type,
positionVsParent positionVsParent
); );
} }
@@ -54,21 +56,21 @@ class ChildRegistrationUtils {
id, id,
softwareType, softwareType,
emitter, emitter,
type, category,
child, child,
subType, type,
positionVsParent positionVsParent
) { ) {
this.logger.debug( this.logger.debug(
`Connecting child id=${id}: desc=${softwareType}, type=${type},subType=${subType}, position=${positionVsParent}` `Connecting child id=${id}: desc=${softwareType}, category=${category},type=${type}, position=${positionVsParent}`
); );
switch (softwareType) { switch (softwareType) {
case "measurement": case "measurement":
this.logger.debug( this.logger.debug(
`Registering measurement child: ${id} with type=${type}` `Registering measurement child: ${id} with category=${category}`
); );
this.connectMeasurement(child, subType, positionVsParent); this.connectMeasurement(child, type, positionVsParent);
break; break;
case "machine": case "machine":
@@ -92,34 +94,34 @@ class ChildRegistrationUtils {
} }
} }
connectMeasurement(child, subType, position) { connectMeasurement(child, type, position) {
this.logger.debug( this.logger.debug(
`Connecting measurement child: ${subType} with position=${position}` `Connecting measurement child: ${type} with position=${position}`
); );
// Check if subType is valid // Check if type is valid
if (!subType) { if (!type) {
this.logger.error(`Invalid subType for measurement: ${subType}`); this.logger.error(`Invalid type for measurement: ${type}`);
return; return;
} }
// initialize the measurement to a number - logging each step for debugging // initialize the measurement to a number - logging each step for debugging
try { try {
this.logger.debug( this.logger.debug(
`Initializing measurement: ${subType}, position: ${position} value: 0` `Initializing measurement: ${type}, position: ${position} value: 0`
); );
const typeResult = this.mainClass.measurements.type(subType); const typeResult = this.mainClass.measurements.type(type);
const variantResult = typeResult.variant("measured"); const variantResult = typeResult.variant("measured");
const positionResult = variantResult.position(position); const positionResult = variantResult.position(position);
positionResult.value(0); positionResult.value(0);
this.logger.debug( this.logger.debug(
`Subscribing on mAbs event for measurement: ${subType}, position: ${position}` `Subscribing on mAbs event for measurement: ${type}, position: ${position}`
); );
// Listen for the mAbs event and update the measurement // Listen for the mAbs event and update the measurement
this.logger.debug( this.logger.debug(
`Successfully initialized measurement: ${subType}, position: ${position}` `Successfully initialized measurement: ${type}, position: ${position}`
); );
} catch (error) { } catch (error) {
this.logger.error(`Failed to initialize measurement: ${error.message}`); this.logger.error(`Failed to initialize measurement: ${error.message}`);
@@ -129,12 +131,12 @@ class ChildRegistrationUtils {
child.emitter.on("mAbs", (value) => { child.emitter.on("mAbs", (value) => {
// Use the same method chaining approach that worked during initialization // Use the same method chaining approach that worked during initialization
this.mainClass.measurements this.mainClass.measurements
.type(subType) .type(type)
.variant("measured") .variant("measured")
.position(position) .position(position)
.value(value); .value(value);
this.mainClass.updateMeasurement("measured", subType, value, position); this.mainClass.updateMeasurement("measured", type, value, position);
//this.logger.debug(`--------->>>>>>>>>Updated measurement: ${subType}, value: ${value}, position: ${position}`); //this.logger.debug(`--------->>>>>>>>>Updated measurement: ${type}, value: ${value}, position: ${position}`);
}); });
} }

View File

@@ -390,6 +390,12 @@ class ValidationUtils {
return fieldSchema.default; return fieldSchema.default;
} }
// Check for uppercase characters and convert to lowercase if present
if (newConfigValue !== newConfigValue.toLowerCase()) {
this.logger.warn(`${name}.${key} contains uppercase characters. Converting to lowercase: ${newConfigValue} -> ${newConfigValue.toLowerCase()}`);
newConfigValue = newConfigValue.toLowerCase();
}
return newConfigValue; return newConfigValue;
} }