From 2c7fe1792f68937f0f9dc3409fd1debd12bd3454 Mon Sep 17 00:00:00 2001 From: znetsixe Date: Thu, 14 May 2026 22:51:42 +0200 Subject: [PATCH] ps: setDemand reads unit-normalised payload from commandRegistry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit generalFunctions' commandRegistry._normaliseUnits now converts {value, unit} or unit-tagged payloads to the descriptor's default unit (m3/h for set.demand) before the handler runs. setDemand just reads Number(payload) — no inline unit-conversion, no scaling state. Matches the same shift done in MGC for unit-self-describing demand commands. Pre-existing test failure: test/integration/basic-dashboard-flow.test.js references examples/basic-dashboard.flow.json which was renamed to 02-Dashboard.json in commit fe5fa35 (feat(pumpingStation): … dashboard example). The 3 stale-path failures are unrelated to this commit — they were broken before this change. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/commands/handlers.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/commands/handlers.js b/src/commands/handlers.js index 32a3ee9..c803948 100644 --- a/src/commands/handlers.js +++ b/src/commands/handlers.js @@ -88,9 +88,14 @@ exports.setOutflow = (source, msg) => { exports.setDemand = (source, msg, ctx) => { const log = _logger(source, ctx); - const demand = Number(msg.payload); + // generalFunctions/commandRegistry's _normaliseUnits has already converted + // msg.payload to m3/h (the descriptor's units.default — see + // commands/index.js). Accepts {value, unit} objects upstream; we just read + // the normalized number here. _manualDemand is stored in m3/h, no further + // conversion needed. + const demand = Number(msg?.payload); if (!Number.isFinite(demand)) { - log?.warn?.(`set.demand: invalid Qd value '${msg.payload}'`); + log?.warn?.(`set.demand: invalid Qd value '${JSON.stringify(msg?.payload)}'`); return; } if (source.mode !== 'manual') {