forked from RnD/rotatingMachine
Refactor child registration to use dedicated connection methods for measurement and reactor types
This commit is contained in:
@@ -77,52 +77,62 @@ class Machine {
|
|||||||
registerChild(child, softwareType) {
|
registerChild(child, softwareType) {
|
||||||
this.logger.debug('Setting up child event for softwaretype ' + softwareType);
|
this.logger.debug('Setting up child event for softwaretype ' + softwareType);
|
||||||
|
|
||||||
if(softwareType === "measurement"){
|
switch (softwareType) {
|
||||||
const position = child.config.functionality.positionVsParent;
|
case "measurement":
|
||||||
const distance = child.config.functionality.distanceVsParent || 0;
|
this._connectMeasurement(child);
|
||||||
const measurementType = child.config.asset.type;
|
break;
|
||||||
const key = `${measurementType}_${position}`;
|
case "reactor":
|
||||||
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
|
this._connectReactor(child);
|
||||||
const eventName = `${measurementType}.measured.${position}`;
|
break;
|
||||||
|
|
||||||
this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`);
|
default:
|
||||||
// Register event listener for measurement updates
|
this.logger.error(`Unrecognized softwareType: ${softwareType}`);
|
||||||
child.measurements.emitter.on(eventName, (eventData) => {
|
|
||||||
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
|
||||||
|
|
||||||
|
|
||||||
console.log(` Emitting... ${eventName} with data:`);
|
|
||||||
// Store directly in parent's measurement container
|
|
||||||
this.measurements
|
|
||||||
.type(measurementType)
|
|
||||||
.variant("measured")
|
|
||||||
.position(position)
|
|
||||||
.value(eventData.value, eventData.timestamp, eventData.unit);
|
|
||||||
|
|
||||||
// Call the appropriate handler
|
|
||||||
this._callMeasurementHandler(measurementType, eventData.value, position, eventData);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centralized handler dispatcher
|
_connectMeasurement(measurementChild) {
|
||||||
_callMeasurementHandler(measurementType, value, position, context) {
|
const position = measurementChild.config.functionality.positionVsParent;
|
||||||
switch (measurementType) {
|
const distance = measurementChild.config.functionality.distanceVsParent || 0;
|
||||||
case 'pressure':
|
const measurementType = measurementChild.config.asset.type;
|
||||||
this.updateMeasuredPressure(value, position, context);
|
const key = `${measurementType}_${position}`;
|
||||||
break;
|
//rebuild to measurementype.variant no position and then switch based on values not strings or names.
|
||||||
|
const eventName = `${measurementType}.measured.${position}`;
|
||||||
|
|
||||||
case 'flow':
|
this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`);
|
||||||
this.updateMeasuredFlow(value, position, context);
|
// Register event listener for measurement updates
|
||||||
break;
|
measurementChild.measurements.emitter.on(eventName, (eventData) => {
|
||||||
|
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
||||||
|
|
||||||
default:
|
|
||||||
this.logger.warn(`No handler for measurement type: ${measurementType}`);
|
console.log(` Emitting... ${eventName} with data:`);
|
||||||
// Generic handler - just update position
|
// Store directly in parent's measurement container
|
||||||
this.updatePosition();
|
this.measurements
|
||||||
break;
|
.type(measurementType)
|
||||||
|
.variant("measured")
|
||||||
|
.position(position)
|
||||||
|
.value(eventData.value, eventData.timestamp, eventData.unit);
|
||||||
|
|
||||||
|
// Call the appropriate handler
|
||||||
|
switch (measurementType) {
|
||||||
|
case 'pressure':
|
||||||
|
this.updateMeasuredPressure(eventData.value, position, eventData);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'flow':
|
||||||
|
this.updateMeasuredFlow(eventData.value, position, eventData);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.logger.warn(`No handler for measurement type: ${measurementType}`);
|
||||||
|
// Generic handler - just update position
|
||||||
|
this.updatePosition();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_connectReactor(reactorChild) {
|
||||||
|
this.logger.error("Reactor child not implemented yet.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//---------------- END child stuff -------------//
|
//---------------- END child stuff -------------//
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user