This commit is contained in:
znetsixe
2026-01-20 18:17:40 +01:00
parent b6e2474a1c
commit ed9409fc29
6 changed files with 735 additions and 155 deletions

View File

@@ -4,7 +4,7 @@
* Encapsulates all node logic in a reusable class. In future updates we can split this into multiple generic classes and use the config to specifiy which ones to use.
* This allows us to keep the Node-RED node clean and focused on wiring up the UI and event handlers.
*/
const { outputUtils, configManager } = require('generalFunctions');
const { outputUtils, configManager, convert } = require('generalFunctions');
const Specific = require("./specificClass");
class nodeClass {
@@ -69,6 +69,10 @@ class nodeClass {
samplingtime: Number(uiConfig.samplingtime),
minVolume: Number(uiConfig.minvolume),
maxWeight: Number(uiConfig.maxweight),
nominalFlowMin: Number(uiConfig.nominalFlowMin),
flowMax: Number(uiConfig.flowMax),
maxRainRef: Number(uiConfig.maxRainRef),
minSampleIntervalSec: Number(uiConfig.minSampleIntervalSec),
},
functionality: {
positionVsParent: uiConfig.positionVsParent || 'atEquipment',
@@ -110,20 +114,33 @@ try{
const bucketVol = m.bucketVol;
const maxVolume = m.maxVolume;
const state = m.running;
const mode = "AI" ; //m.mode;
const mode = "AI"; //m.mode;
const flowMin = m.nominalFlowMin;
const flowMax = m.flowMax;
let status;
switch (state) {
case false:
status = { fill: "red", shape: "dot", text: `${mode}: OFF` };
break;
case true:
status = { fill: "green", shape: "dot", text: `${mode}: ON => ${bucketVol} | ${maxVolume}` };
break;
if (m.invalidFlowBounds) {
return {
fill: "red",
shape: "ring",
text: `Config error: nominalFlowMin (${flowMin}) >= flowMax (${flowMax})`
};
}
return status;
if (state) {
const levelText = `${bucketVol}/${maxVolume} L`;
const cooldownMs = typeof m.getSampleCooldownMs === 'function'
? m.getSampleCooldownMs()
: 0;
if (cooldownMs > 0) {
const cooldownSec = Math.ceil(cooldownMs / 1000);
return { fill: "yellow", shape: "ring", text: `SAMPLING (${cooldownSec}s) ${levelText}` };
}
return { fill: "green", shape: "dot", text: `${mode}: RUNNING ${levelText}` };
}
return { fill: "grey", shape: "ring", text: `${mode}: IDLE` };
} catch (error) {
this.node.error("Error in updateNodeStatus: " + error);
return { fill: "red", shape: "ring", text: "Status Error" };
@@ -182,6 +199,28 @@ try{
const m = this.source;
try {
switch(msg.topic) {
case 'input_q': {
const value = Number(msg.payload?.value);
const unit = msg.payload?.unit;
if (!Number.isFinite(value) || !unit) {
this.node.warn('input_q payload must include numeric value and unit.');
break;
}
let converted = value;
try {
converted = convert(value).from(unit).to('m3/h');
} catch (error) {
this.node.warn(`input_q unit conversion failed: ${error.message}`);
break;
}
m.handleInput('input_q', { value: converted, unit: 'm3/h' });
break;
}
case 'i_start':
case 'monsternametijden':
case 'rain_data':
m.handleInput(msg.topic, msg.payload);
break;
case 'registerChild': {
const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId);