diff --git a/src/nodeClass.js b/src/nodeClass.js index 47cdda4..26553d3 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -42,32 +42,13 @@ class nodeClass { * @param {object} uiConfig - Raw config from Node-RED UI. */ _loadConfig(uiConfig,node) { + // Resolve flow unit with validation before building config const flowUnit = this._resolveUnitOrFallback(uiConfig.unit, 'volumeFlowRate', 'm3/h', 'flow'); + const resolvedUiConfig = { ...uiConfig, unit: flowUnit }; - // Merge UI config over defaults - this.config = { - general: { - name: uiConfig.name, - id: node.id, // node.id is for the child registration process - unit: flowUnit, - logging: { - enabled: uiConfig.enableLog, - logLevel: uiConfig.logLevel - } - }, - asset: { - uuid: uiConfig.uuid || uiConfig.assetUuid || null, - tagCode: uiConfig.tagCode || uiConfig.assetTagCode || null, - supplier: uiConfig.supplier, - category: uiConfig.category, //add later to define as the software type - type: uiConfig.assetType, - model: uiConfig.model, - unit: flowUnit - }, - functionality: { - positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified - } - }; + // Build config: base sections handle general, asset, functionality + const cfgMgr = new configManager(); + this.config = cfgMgr.buildConfig(this.name, resolvedUiConfig, node.id); // Utility for formatting outputs this._output = new outputUtils();