'use strict'; // Handlers for monster input topics. Each is a pure function over the // domain (source). Unit conversion for incoming flow happens in the // handler (the legacy nodeClass did it inline) — anything else inbound // is passed straight through to source.handleInput. exports.cmdStart = (source, msg) => { source.handleInput('i_start', Boolean(msg.payload)); }; exports.setSchedule = (source, msg) => { source.handleInput('monsternametijden', msg.payload); }; exports.setRain = (source, msg) => { source.handleInput('rain_data', msg.payload); }; exports.dataFlow = (source, msg, ctx) => { // The registry has already normalised any accepted shape (number, numeric // string, or { value, unit }) to a number in m3/h and tagged msg.unit. const log = ctx?.logger || source.logger; const value = Number(msg.payload); if (!Number.isFinite(value)) { log?.warn?.(`data.flow payload must be numeric, got '${JSON.stringify(msg.payload)}'.`); return; } source.handleInput('input_q', { value, unit: msg.unit || 'm3/h' }); }; exports.setMode = (source, msg) => { if (typeof source.setMode === 'function') source.setMode(msg.payload); }; exports.setModelPrediction = (source, msg) => { if (typeof source.setModelPrediction === 'function') source.setModelPrediction(msg.payload); }; // Inbound child registration from a measurement (or other) child node. // Ported from the legacy `case 'registerChild'` branch in nodeClass. exports.childRegister = (source, msg, ctx) => { const childId = msg.payload; const childObj = ctx?.RED?.nodes?.getNode?.(childId); if (!childObj?.source) { (ctx?.logger || source.logger)?.warn?.(`child.register skipped: missing child/source for id=${childId}`); return; } source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent, msg.distance); };