P11.5 + B2.1/B2.2: per-command units + description (where applicable)

Adds  to scalar setters whose payloads are
plain numbers OR {value, unit}. Skipped where payload is compound or
mode-dependent (control-%, {F, C: [...]}, etc.) — documented inline.
Every command gains a description field for wikiGen consumption.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-11 17:41:07 +02:00
parent ef81013e96
commit 5f1c9ae2ff
5 changed files with 107 additions and 88 deletions

View File

@@ -75,10 +75,12 @@ test('canonical topics dispatch to their handlers', async () => {
await reg.dispatch({ topic: 'cmd.calibrate.level', payload: 1.25 }, source, makeCtx());
assert.deepEqual(calls.calibratePredictedLevel, [1.25]);
// Registry normalises to the descriptor's `units.default` (m3/h) before
// the handler runs. 0.5 m3/s -> 1800 m3/h.
await reg.dispatch({ topic: 'set.inflow', payload: 0.5, unit: 'm3/s' }, source, makeCtx());
assert.equal(calls.setManualInflow.length, 1);
assert.equal(calls.setManualInflow[0].v, 0.5);
assert.equal(calls.setManualInflow[0].u, 'm3/s');
assert.equal(calls.setManualInflow[0].v, 1800);
assert.equal(calls.setManualInflow[0].u, 'm3/h');
await reg.dispatch({ topic: 'set.demand', payload: 100 }, source, makeCtx());
assert.deepEqual(calls.forwardDemandToChildren, [100]);
@@ -140,11 +142,16 @@ test('set.inflow accepts number payload and { value, unit, timestamp } object pa
const { source, calls } = makeSource();
const reg = makeRegistry(makeLogger());
// After registry units-normalisation the handler always sees a number in
// the descriptor's default unit (m3/h). 0.5 m3/s -> 1800 m3/h.
await reg.dispatch({ topic: 'set.inflow', payload: 0.5, unit: 'm3/s', timestamp: 1000 }, source, makeCtx());
assert.deepEqual(calls.setManualInflow[0], { v: 0.5, ts: 1000, u: 'm3/s' });
assert.deepEqual(calls.setManualInflow[0], { v: 1800, ts: 1000, u: 'm3/h' });
// Object payload `{ value, unit }` is flattened to a number; 2 m3/h stays
// 2 m3/h. The timestamp travels on the msg envelope after normalisation
// (the per-payload `timestamp` field is not preserved by the flatten).
await reg.dispatch(
{ topic: 'set.inflow', payload: { value: 2, unit: 'm3/h', timestamp: 2000 } },
{ topic: 'set.inflow', payload: { value: 2, unit: 'm3/h' }, timestamp: 2000 },
source,
makeCtx()
);