ps: setDemand reads unit-normalised payload from commandRegistry

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) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-14 22:51:42 +02:00
parent 6e89e4916f
commit 2c7fe1792f

View File

@@ -88,9 +88,14 @@ exports.setOutflow = (source, msg) => {
exports.setDemand = (source, msg, ctx) => { exports.setDemand = (source, msg, ctx) => {
const log = _logger(source, 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)) { 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; return;
} }
if (source.mode !== 'manual') { if (source.mode !== 'manual') {