43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
|
|
'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.
|
||
|
|
|
||
|
|
const { convert } = require('generalFunctions');
|
||
|
|
|
||
|
|
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) => {
|
||
|
|
const log = ctx?.logger || source.logger;
|
||
|
|
const value = Number(msg.payload?.value);
|
||
|
|
const unit = msg.payload?.unit;
|
||
|
|
if (!Number.isFinite(value) || !unit) {
|
||
|
|
log?.warn?.('data.flow payload must include numeric value and unit.');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
let converted = value;
|
||
|
|
try { converted = convert(value).from(unit).to('m3/h'); }
|
||
|
|
catch (err) { log?.warn?.(`data.flow unit conversion failed: ${err.message}`); return; }
|
||
|
|
source.handleInput('input_q', { value: converted, 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);
|
||
|
|
};
|