2026-05-10 22:09:25 +02:00
|
|
|
'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) => {
|
2026-05-29 18:41:33 +02:00
|
|
|
// The registry has already normalised any accepted shape (number, numeric
|
|
|
|
|
// string, or { value, unit }) to a number in m3/h and tagged msg.unit.
|
2026-05-10 22:09:25 +02:00
|
|
|
const log = ctx?.logger || source.logger;
|
2026-05-29 18:41:33 +02:00
|
|
|
const value = Number(msg.payload);
|
|
|
|
|
if (!Number.isFinite(value)) {
|
|
|
|
|
log?.warn?.(`data.flow payload must be numeric, got '${JSON.stringify(msg.payload)}'.`);
|
2026-05-10 22:09:25 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2026-05-29 18:41:33 +02:00
|
|
|
source.handleInput('input_q', { value, unit: msg.unit || 'm3/h' });
|
2026-05-10 22:09:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
};
|
2026-05-11 16:04:29 +02:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
};
|