From aaa88a77920bc96580a33272e44db1ea2b12a40c Mon Sep 17 00:00:00 2001 From: Rene De Ren Date: Wed, 11 Mar 2026 13:39:57 +0100 Subject: [PATCH] Fix ESLint errors and bugs Co-Authored-By: Claude Opus 4.6 --- src/nodeClass.js | 202 +++++++++++++++++++++---------------------- src/specificClass.js | 20 +++-- 2 files changed, 112 insertions(+), 110 deletions(-) diff --git a/src/nodeClass.js b/src/nodeClass.js index 8e7da76..47cdda4 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -141,111 +141,109 @@ class nodeClass { } - _updateNodeStatus() { - const v = this.source; + _updateNodeStatus() { + const v = this.source; - try { - const mode = v.currentMode; // modus is bijv. auto, manual, etc. - const state = v.state.getCurrentState(); //is bijv. operational, idle, off, etc. - const fluidCompatibility = typeof v.getFluidCompatibility === "function" - ? v.getFluidCompatibility() - : null; - const fluidWarningText = ( - fluidCompatibility - && (fluidCompatibility.status === "mismatch" || fluidCompatibility.status === "conflict") - ) - ? fluidCompatibility.message - : ""; - const flowUnit = v?.unitPolicy?.output?.flow || this.config.general.unit || "m3/h"; - const pressureUnit = v?.unitPolicy?.output?.pressure || "mbar"; - // check if measured flow is available otherwise use predicted flow - const flow = Math.round(v.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue(flowUnit)); + try { + const mode = v.currentMode; + const state = v.state.getCurrentState(); + const fluidCompatibility = typeof v.getFluidCompatibility === "function" + ? v.getFluidCompatibility() + : null; + const fluidWarningText = ( + fluidCompatibility + && (fluidCompatibility.status === "mismatch" || fluidCompatibility.status === "conflict") + ) + ? fluidCompatibility.message + : ""; + const flowUnit = v?.unitPolicy?.output?.flow || this.config.general.unit || "m3/h"; + const pressureUnit = v?.unitPolicy?.output?.pressure || "mbar"; + const flow = Math.round(v.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue(flowUnit)); - let deltaP = v.measurements.type("pressure").variant("predicted").position("delta").getCurrentValue(pressureUnit); - if (deltaP !== null) { - deltaP = parseFloat(deltaP.toFixed(0)); - } //afronden op 4 decimalen indien geen "null" - if(isNaN(deltaP)) { - deltaP = "∞"; - } - const roundedPosition = Math.round(v.state.getCurrentPosition() * 100) / 100; - let symbolState; - switch(state){ - case "off": - symbolState = "⬛"; - break; - case "idle": - symbolState = "⏸️"; - break; - case "operational": - symbolState = "⏵️"; - break; - case "starting": - symbolState = "⏯️"; - break; - case "warmingup": - symbolState = "🔄"; - break; - case "accelerating": - symbolState = "⏩"; - break; - case "stopping": - symbolState = "⏹️"; - break; - case "coolingdown": - symbolState = "❄️"; - break; - case "decelerating": - symbolState = "⏪"; - break; - } - - - let status; - switch (state) { - case "off": - status = { fill: "red", shape: "dot", text: `${mode}: OFF` }; - break; - case "idle": - status = { fill: "blue", shape: "dot", text: `${mode}: ${symbolState}` }; - break; - case "operational": - status = { fill: "green", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; //deltaP toegevoegd - break; - case "starting": - status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; - break; - case "warmingup": - status = { fill: "green", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; //deltaP toegevoegd - break; - case "accelerating": - status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}` }; //deltaP toegevoegd - break; - case "stopping": - status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; - break; - case "coolingdown": - status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; - break; - case "decelerating": - status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState} - ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; //deltaP toegevoegd - break; - default: - status = { fill: "grey", shape: "dot", text: `${mode}: ${symbolState}` }; - } - if (fluidWarningText) { - status = { - fill: "yellow", - shape: "ring", - text: `${status.text} | ⚠ ${fluidWarningText}`, - }; - } - return status; - } catch (error) { - this.node.error("Error in updateNodeStatus: " + error.message); - return { fill: "red", shape: "ring", text: "Status Error" }; - } + let deltaP = v.measurements.type("pressure").variant("predicted").position("delta").getCurrentValue(pressureUnit); + if (deltaP !== null) { + deltaP = parseFloat(deltaP.toFixed(0)); } + if(isNaN(deltaP)) { + deltaP = "∞"; + } + const roundedPosition = Math.round(v.state.getCurrentPosition() * 100) / 100; + let symbolState; + switch(state){ + case "off": + symbolState = "⬛"; + break; + case "idle": + symbolState = "⏸️"; + break; + case "operational": + symbolState = "⏵️"; + break; + case "starting": + symbolState = "⏯️"; + break; + case "warmingup": + symbolState = "🔄"; + break; + case "accelerating": + symbolState = "⏩"; + break; + case "stopping": + symbolState = "⏹️"; + break; + case "coolingdown": + symbolState = "❄️"; + break; + case "decelerating": + symbolState = "⏪"; + break; + } + + let status; + switch (state) { + case "off": + status = { fill: "red", shape: "dot", text: `${mode}: OFF` }; + break; + case "idle": + status = { fill: "blue", shape: "dot", text: `${mode}: ${symbolState}` }; + break; + case "operational": + status = { fill: "green", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; + break; + case "starting": + status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; + break; + case "warmingup": + status = { fill: "green", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; + break; + case "accelerating": + status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState} | ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}` }; + break; + case "stopping": + status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; + break; + case "coolingdown": + status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState}` }; + break; + case "decelerating": + status = { fill: "yellow", shape: "dot", text: `${mode}: ${symbolState} - ${roundedPosition}% | 💨${flow}${flowUnit} | ΔP${deltaP} ${pressureUnit}`}; + break; + default: + status = { fill: "grey", shape: "dot", text: `${mode}: ${symbolState}` }; + } + if (fluidWarningText) { + status = { + fill: "yellow", + shape: "ring", + text: `${status.text} | ⚠ ${fluidWarningText}`, + }; + } + return status; + } catch (error) { + this.node.error("Error in updateNodeStatus: " + error.message); + return { fill: "red", shape: "ring", text: "Status Error" }; + } + } /** * Register this node as a child upstream and downstream. diff --git a/src/specificClass.js b/src/specificClass.js index 8fe1cd2..76e62a2 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -703,7 +703,7 @@ class Valve { this.logger.debug(`Updating pressure: variant=${variant}, value=${value}, position=${position}`); switch (variant) { - case ("measured"): + case ("measured"): { // put value in measurements container this._writeMeasurement("pressure", "measured", position, Number(value), unit); // get latest downstream pressure measurement @@ -712,18 +712,20 @@ class Valve { const predictedFlow = this._readMeasurement("flow", "predicted", "downstream", FORMULA_UNITS.flow); const activeFlow = Number.isFinite(predictedFlow) ? predictedFlow : measuredFlow; // update predicted flow measurement - this.updateDeltaPKlep(activeFlow,this.kv,measuredDownStreamP,this.rho,this.T); //update deltaP based on new flow + this.updateDeltaPKlep(activeFlow,this.kv,measuredDownStreamP,this.rho,this.T); break; + } - case ("predicted"): + case ("predicted"): { // put value in measurements container this._writeMeasurement("pressure", "predicted", position, Number(value), unit); const predictedDownStreamP = this._readMeasurement("pressure", "predicted", "downstream", FORMULA_UNITS.pressure); const measuredFlowFromPred = this._readMeasurement("flow", "measured", "downstream", FORMULA_UNITS.flow); const predictedFlowFromPred = this._readMeasurement("flow", "predicted", "downstream", FORMULA_UNITS.flow); const activeFlowFromPred = Number.isFinite(predictedFlowFromPred) ? predictedFlowFromPred : measuredFlowFromPred; - this.updateDeltaPKlep(activeFlowFromPred,this.kv,predictedDownStreamP,this.rho,this.T); //update deltaP based on new flow + this.updateDeltaPKlep(activeFlowFromPred,this.kv,predictedDownStreamP,this.rho,this.T); break; + } default: this.logger.warn(`Unrecognized variant '${variant}' for flow update.`); @@ -784,23 +786,25 @@ class Valve { this.logger.debug(`Updating flow: variant=${variant}, value=${value}, position=${position}`); switch (variant) { - case ("measured"): + case ("measured"): { // put value in measurements container this._writeMeasurement("flow", "measured", position, Number(value), unit); // get latest downstream pressure measurement const measuredDownStreamP = this._readMeasurement("pressure", "measured", "downstream", FORMULA_UNITS.pressure); const measuredFlow = this._readMeasurement("flow", "measured", position, FORMULA_UNITS.flow); // update predicted flow measurement - this.updateDeltaPKlep(measuredFlow,this.kv,measuredDownStreamP,this.rho,this.T); //update deltaP based on new flow + this.updateDeltaPKlep(measuredFlow,this.kv,measuredDownStreamP,this.rho,this.T); break; + } - case ("predicted"): + case ("predicted"): { // put value in measurements container this._writeMeasurement("flow", "predicted", position, Number(value), unit); const predictedDownStreamP = this._readMeasurement("pressure", "measured", "downstream", FORMULA_UNITS.pressure); const predictedFlow = this._readMeasurement("flow", "predicted", position, FORMULA_UNITS.flow); - this.updateDeltaPKlep(predictedFlow,this.kv,predictedDownStreamP,this.rho,this.T); //update deltaP based on new flow + this.updateDeltaPKlep(predictedFlow,this.kv,predictedDownStreamP,this.rho,this.T); break; + } default: this.logger.warn(`Unrecognized variant '${variant}' for flow update.`);