This commit is contained in:
znetsixe
2026-03-11 11:12:52 +01:00
parent f8012c8bad
commit b337bf9eb7
3 changed files with 217 additions and 60 deletions

View File

@@ -1,4 +1,4 @@
const { outputUtils, configManager } = require("generalFunctions");
const { outputUtils, configManager, convert } = require("generalFunctions");
const Specific = require("./specificClass");
class nodeClass {
@@ -37,13 +37,14 @@ class nodeClass {
_loadConfig(uiConfig, node) {
const cfgMgr = new configManager();
this.defaultConfig = cfgMgr.getConfig(this.name);
const flowUnit = this._resolveUnitOrFallback(uiConfig.unit, 'volumeFlowRate', 'm3/h', 'flow');
// Merge UI config over defaults
this.config = {
general: {
name: uiConfig.name,
id: node.id, // node.id is for the child registration process
unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards)
unit: flowUnit,
logging: {
enabled: uiConfig.enableLog,
logLevel: uiConfig.logLevel,
@@ -57,6 +58,24 @@ class nodeClass {
this._output = new outputUtils();
}
_resolveUnitOrFallback(candidate, expectedMeasure, fallbackUnit, label) {
const raw = typeof candidate === "string" ? candidate.trim() : "";
const fallback = String(fallbackUnit || "").trim();
if (!raw) {
return fallback;
}
try {
const desc = convert().describe(raw);
if (expectedMeasure && desc.measure !== expectedMeasure) {
throw new Error(`expected '${expectedMeasure}' but got '${desc.measure}'`);
}
return raw;
} catch (error) {
this.node?.warn?.(`Invalid ${label} unit '${raw}' (${error.message}). Falling back to '${fallback}'.`);
return fallback;
}
}
_updateNodeStatus() {
//console.log('Updating node status...');
const mg = this.source;
@@ -68,13 +87,13 @@ class nodeClass {
?.type("flow")
?.variant("predicted")
?.position("atequipment")
?.getCurrentValue('m3/h') || 0;
?.getCurrentValue(mg?.unitPolicy?.output?.flow || 'm3/h') || 0;
const totalPower = mg.measurements
?.type("power")
?.variant("predicted")
?.position("atEquipment")
?.getCurrentValue() || 0;
?.getCurrentValue(mg?.unitPolicy?.output?.power || 'kW') || 0;
// Calculate total capacity based on available machines with safety checks
const availableMachines = Object.values(mg.machines || {}).filter((machine) => {