Fix ESLint errors and bugs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Rene De Ren
2026-03-11 13:39:57 +01:00
parent e236cccfd6
commit ccfa90394b
2 changed files with 45 additions and 70 deletions

View File

@@ -190,7 +190,7 @@ class nodeClass {
} }
return status; return status;
} catch (error) { } catch (error) {
node.error("Error in updateNodeStatus: " + error.message); this.node.error("Error in updateNodeStatus: " + error.message);
return { fill: "red", shape: "ring", text: "Status Error" }; return { fill: "red", shape: "ring", text: "Status Error" };
} }
} }
@@ -246,32 +246,36 @@ class nodeClass {
/* Update to complete event based node by putting the tick function after an input event */ /* Update to complete event based node by putting the tick function after an input event */
const m = this.source; const m = this.source;
switch(msg.topic) { switch(msg.topic) {
case 'registerChild': case 'registerChild': {
// Register this node as a child of the parent node // Register this node as a child of the parent node
const childId = msg.payload; const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId); const childObj = this.RED.nodes.getNode(childId);
m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent); m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent);
break; break;
}
case 'setMode': case 'setMode':
m.setMode(msg.payload); m.setMode(msg.payload);
break; break;
case 'execSequence': case 'execSequence': {
const { source, action, parameter } = msg.payload; const { source, action, parameter } = msg.payload;
m.handleInput(source, action, parameter); m.handleInput(source, action, parameter);
break; break;
case 'execMovement': }
case 'execMovement': {
const { source: mvSource, action: mvAction, setpoint } = msg.payload; const { source: mvSource, action: mvAction, setpoint } = msg.payload;
m.handleInput(mvSource, mvAction, Number(setpoint)); m.handleInput(mvSource, mvAction, Number(setpoint));
break; break;
case 'flowMovement': }
case 'flowMovement': {
const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload; const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload;
m.handleInput(fmSource, fmAction, Number(fmSetpoint)); m.handleInput(fmSource, fmAction, Number(fmSetpoint));
break; break;
case 'emergencystop': }
case 'emergencystop': {
const { source: esSource, action: esAction } = msg.payload; const { source: esSource, action: esAction } = msg.payload;
m.handleInput(esSource, esAction); m.handleInput(esSource, esAction);
break; break;
}
case 'showWorkingCurves': case 'showWorkingCurves':
m.showWorkingCurves(); m.showWorkingCurves();
send({ topic : "Showing curve" , payload: m.showWorkingCurves() }); send({ topic : "Showing curve" , payload: m.showWorkingCurves() });

View File

@@ -101,10 +101,12 @@ class Machine {
//assume standard atm pressure is at sea level //assume standard atm pressure is at sea level
this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325).unit('Pa'); this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325).unit('Pa');
//populate min and max //populate min and max
if (this.predictFlow) {
const flowunit = this.config.general.unit; const flowunit = this.config.general.unit;
this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit) this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit);
this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit); this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit);
} }
}
_updateState(){ _updateState(){
const isOperational = this._isOperationalState(); const isOperational = this._isOperationalState();
@@ -143,13 +145,11 @@ class Machine {
//rebuild to measurementype.variant no position and then switch based on values not strings or names. //rebuild to measurementype.variant no position and then switch based on values not strings or names.
const eventName = `${measurementType}.measured.${position}`; const eventName = `${measurementType}.measured.${position}`;
this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`); this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`);
// Register event listener for measurement updates // Register event listener for measurement updates
child.measurements.emitter.on(eventName, (eventData) => { measurementChild.measurements.emitter.on(eventName, (eventData) => {
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`); this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
this.logger.debug(` Emitting... ${eventName} with data:`);
// Store directly in parent's measurement container // Store directly in parent's measurement container
this.measurements this.measurements
.type(measurementType) .type(measurementType)
@@ -161,10 +161,9 @@ class Machine {
this._callMeasurementHandler(measurementType, eventData.value, position, eventData); this._callMeasurementHandler(measurementType, eventData.value, position, eventData);
}); });
} }
}
// Centralized handler dispatcher // Centralized handler dispatcher
_callMeasurementHandler(measurementType, value, position, context) { _callMeasurementHandler(measurementType, value, position, context) {
switch (measurementType) { switch (measurementType) {
case 'pressure': case 'pressure':
this.updateMeasuredPressure(value, position, context); this.updateMeasuredPressure(value, position, context);
@@ -184,35 +183,6 @@ _callMeasurementHandler(measurementType, value, position, context) {
this.updatePosition(); this.updatePosition();
break; break;
} }
}
this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`);
// Register event listener for measurement updates
measurementChild.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);
// 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) { _connectReactor(reactorChild) {
@@ -304,11 +274,12 @@ _callMeasurementHandler(measurementType, value, position, context) {
case "exitmaintenance": case "exitmaintenance":
return await this.executeSequence(parameter); return await this.executeSequence(parameter);
case "flowmovement": case "flowmovement": {
// Calculate the control value for a desired flow // Calculate the control value for a desired flow
const pos = this.calcCtrl(parameter); const pos = this.calcCtrl(parameter);
// Move to the desired setpoint // Move to the desired setpoint
return await this.setpoint(pos); return await this.setpoint(pos);
}
case "emergencystop": case "emergencystop":
this.logger.warn(`Emergency stop activated by '${source}'.`); this.logger.warn(`Emergency stop activated by '${source}'.`);