diff --git a/src/commands/handlers.js b/src/commands/handlers.js index cf7781e..f402351 100644 --- a/src/commands/handlers.js +++ b/src/commands/handlers.js @@ -5,8 +5,6 @@ // 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)); }; @@ -20,17 +18,15 @@ exports.setRain = (source, msg) => { }; 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?.value); - const unit = msg.payload?.unit; - if (!Number.isFinite(value) || !unit) { - log?.warn?.('data.flow payload must include numeric value and unit.'); + const value = Number(msg.payload); + if (!Number.isFinite(value)) { + log?.warn?.(`data.flow payload must be numeric, got '${JSON.stringify(msg.payload)}'.`); 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' }); + source.handleInput('input_q', { value, unit: msg.unit || 'm3/h' }); }; exports.setMode = (source, msg) => { diff --git a/src/commands/index.js b/src/commands/index.js index f71a5a1..d70bc31 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -32,11 +32,11 @@ module.exports = [ { topic: 'data.flow', aliases: ['input_q'], - payloadSchema: { type: 'object' }, - // Compound payload `{value, unit}` — handler converts internally to m3/h. - // Registry-level normalisation is skipped (the handler reads payload.value / - // payload.unit directly; flattening would break it). - description: 'Push the upstream flow measurement (payload: {value, unit}).', + // any: number, numeric string, or { value, unit } — the registry normalises + // all of them to a number in `unit` (m3/h) before the handler runs. + payloadSchema: { type: 'any' }, + unit: 'm3/h', + description: 'Push the upstream flow measurement (payload: number or {value, unit}).', handler: handlers.dataFlow, }, { diff --git a/wiki/Reference-Contracts.md b/wiki/Reference-Contracts.md index 6870d5b..6032682 100644 --- a/wiki/Reference-Contracts.md +++ b/wiki/Reference-Contracts.md @@ -23,7 +23,7 @@ The registry lives in `src/commands/index.js`. Each descriptor maps a canonical | `cmd.start` | `i_start` | any | — | Trigger / release the sampler start gate. | | `set.schedule` | `monsternametijden` | any | — | Replace the sampling-times schedule. | | `set.rain` | `rain_data` | any | — | Push current rain-event data into the sampler logic. | -| `data.flow` | `input_q` | `object` | — | Push the upstream flow measurement (payload: {value, unit}). | +| `data.flow` | `input_q` | any | `volumeFlowRate` (default `m3/h`) | Push the upstream flow measurement (payload: number or {value, unit}). | | `set.mode` | `setMode` | any | — | Switch the monster between auto / manual modes. | | `set.model-prediction` | `model_prediction` | any | — | Push the upstream rain-prediction snapshot used by the sampler. | | `child.register` | `registerChild` | `string` | — | Register a child node (typically a measurement) with this monster. |