This commit is contained in:
znetsixe
2026-02-23 13:17:22 +01:00
parent 46adc1ee9b
commit d56f8a382c
2 changed files with 49 additions and 33 deletions

View File

@@ -249,35 +249,50 @@ class nodeClass {
_attachInputHandler() { _attachInputHandler() {
this.node.on('input', (msg, send, done) => { this.node.on('input', (msg, send, done) => {
const v = this.source; const v = this.source;
try {
switch(msg.topic) { switch(msg.topic) {
case 'registerChild': case 'registerChild': {
const childId = msg.payload; const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId); const childObj = this.RED.nodes.getNode(childId);
v.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent); if (!childObj || !childObj.source) {
v.logger.warn(`registerChild skipped: missing child/source for id=${childId}`);
break; break;
}
v.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
break;
}
case 'setMode': case 'setMode':
v.setMode(msg.payload); v.setMode(msg.payload);
break; break;
case 'execSequence': case 'execSequence': {
const { source: seqSource, action: seqAction, parameter } = msg.payload; const { source: seqSource, action: seqAction, parameter } = msg.payload;
v.handleInput(seqSource, seqAction, parameter); v.handleInput(seqSource, seqAction, parameter);
break; break;
case 'execMovement': }
case 'execMovement': {
const { source: mvSource, action: mvAction, setpoint } = msg.payload; const { source: mvSource, action: mvAction, setpoint } = msg.payload;
v.handleInput(mvSource, mvAction, Number(setpoint)); v.handleInput(mvSource, mvAction, Number(setpoint));
break; break;
case 'emergencystop': }
case 'emergencystop': {
const { source: esSource, action: esAction } = msg.payload; const { source: esSource, action: esAction } = msg.payload;
v.handleInput(esSource, esAction); v.handleInput(esSource, esAction);
break; break;
case 'showcurve':
v.showCurve();
send({ topic : "Showing curve" , payload: v.showCurve() });
break;
case 'updateFlow': //Als nieuwe flow van header node dan moet deltaP weer opnieuw worden berekend en doorgegeven aan header node
v.updateFlow(msg.payload.variant, msg.payload.value, msg.payload.position);
} }
done(); case 'showcurve':
send({ topic: 'Showing curve', payload: v.showCurve() });
break;
case 'updateFlow':
v.updateFlow(msg.payload.variant, msg.payload.value, msg.payload.position);
break;
default:
v.logger.warn(`Unknown topic: ${msg.topic}`);
}
} catch (error) {
v.logger.error(`Input handler failure: ${error.message}`);
}
if (typeof done === 'function') done();
}); });
} }
@@ -288,7 +303,7 @@ class nodeClass {
this.node.on('close', (done) => { this.node.on('close', (done) => {
clearInterval(this._tickInterval); clearInterval(this._tickInterval);
clearInterval(this._statusInterval); clearInterval(this._statusInterval);
done(); if (typeof done === 'function') done();
}); });
} }
} }

View File

@@ -139,7 +139,9 @@ class Valve {
} }
setMode(newMode) { setMode(newMode) {
const availableModes = defaultConfig.mode.current.rules.values.map(v => v.value); const availableModes = Array.isArray(this.defaultConfig?.mode?.current?.rules?.values)
? this.defaultConfig.mode.current.rules.values.map(v => v.value)
: Object.keys(this.config?.mode?.allowedSources || {});
if (!availableModes.includes(newMode)) { if (!availableModes.includes(newMode)) {
this.logger.warn(`Invalid mode '${newMode}'. Allowed modes are: ${availableModes.join(', ')}`); this.logger.warn(`Invalid mode '${newMode}'. Allowed modes are: ${availableModes.join(', ')}`);
return; return;
@@ -190,7 +192,7 @@ class Valve {
await this.state.moveTo(setpoint); await this.state.moveTo(setpoint);
} catch (error) { } catch (error) {
console.error(`Error setting setpoint: ${error}`); this.logger.error(`Error setting setpoint: ${error}`);
} }
} }
@@ -204,7 +206,6 @@ class Valve {
switch (variant) { switch (variant) {
case ("measured"): case ("measured"):
// put value in measurements container // put value in measurements container
console.log( 'wtf ... ' + value);
this.measurements.type("pressure").variant("measured").position(position).value(value); this.measurements.type("pressure").variant("measured").position(position).value(value);
// get latest downstream pressure measurement // get latest downstream pressure measurement
const measuredDownStreamP = this.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(); //update downstream pressure measurement const measuredDownStreamP = this.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(); //update downstream pressure measurement