Enhance measurement child registration and update measurement handling in Reactor class

This commit is contained in:
2025-09-15 12:48:18 +02:00
parent c2cd29db56
commit f6b026928e

View File

@@ -99,6 +99,10 @@ class Reactor {
registerChild(child, softwareType) {
switch (softwareType) {
case "measurement":
this.logger.debug(`Registering measurement child.`);
this.connectMeasurement(child);
break;
case "reactor":
this.logger.debug(`Registering reactor child.`);
this.connectReactor(child);
@@ -107,9 +111,35 @@ class Reactor {
default:
this.logger.error(`Unrecognized softwareType: ${softwareType}`);
}
}
connectMeasurement(measurement) {
if (!measurement) {
this.logger.warn("Invalid measurement provided.");
return;
}
const position = child.config.functionality.positionVsParent;
const measurementType = child.config.asset.type;
const key = `${measurementType}_${position}`;
const eventName = `${measurementType}.measured.${position}`;
// Register event listener for measurement updates
child.measurements.emitter.on(eventName, (eventData) => {
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
// Store directly in parent's measurement container
this.measurements
.type(measurementType)
.variant("measured")
.position(position)
.value(eventData.value, eventData.timestamp, eventData.unit);
this.updateMeasurement(measurementType, eventData.value, position, eventData);
});
}
connectReactor(reactor) {
if (!reactor) {
this.logger.warn("Invalid reactor provided.");
@@ -125,14 +155,17 @@ class Reactor {
}
updateMeasurement(variant, subType, value, position) {
this.logger.debug(`---------------------- updating ${subType} ------------------ `);
switch (subType) {
updateMeasurement(measurementType, value, position, context) {
this.logger.debug(`---------------------- updating ${measurementType} ------------------ `);
switch (measurementType) {
case "concentration":
// add concentation handling function
break;
case "temperature":
this.temperature = value;
break;
default:
this.logger.error(`Type '${subType}' not recognized for measured update.`);
this.logger.error(`Type '${measurementType}' not recognized for measured update.`);
return;
}
}