Files
settler/src/commands/handlers.js
znetsixe 2af30c0bd8 fix(commands): restore child.register handler (alias registerChild)
Same fix as monster: P6.6 refactor dropped the case 'registerChild'
branch when extracting commands. Settler registers reactor + measurement
children — without this, Port 2 inbound handshakes were silently
ignored.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 16:04:32 +02:00

46 lines
1.9 KiB
JavaScript

'use strict';
// Handler functions for settler commands. Each handler receives:
// source: the Settler domain instance.
// msg: the Node-RED input message.
// ctx: { node, RED, send, logger } — provided by BaseNodeAdapter.
//
// Settler accepts `child.register` (alias `registerChild`) on Port 0 input
// to register measurement / reactor children, plus `data.influent` for
// manual override. BaseNodeAdapter dispatches msg.topic through the
// per-node registry — there is no implicit `child.register` handler in
// the base, so it must be listed explicitly here.
function _logger(source, ctx) {
return ctx?.logger || source?.logger || null;
}
// Allows operators / upstream nodes to push an influent stream directly,
// bypassing the reactor stateChange path. Payload mirrors the reactor's
// `getEffluent` shape: { F, C } where C is the 13-species concentration
// vector. Either field may be omitted to update only the other.
exports.dataInfluent = (source, msg, ctx) => {
const log = _logger(source, ctx);
const p = msg?.payload;
if (!p || typeof p !== 'object' || Array.isArray(p)) {
log?.warn?.(`data.influent expects an object {F, C}; got ${typeof p}`);
return;
}
if (typeof p.F === 'number' && Number.isFinite(p.F)) source.F_in = p.F;
if (Array.isArray(p.C)) source.Cs_in = [...p.C];
source.notifyOutputChanged();
};
// Inbound child registration from a measurement (or reactor) child.
// Ported from the legacy `case 'registerChild'` branch in nodeClass.
exports.childRegister = (source, msg, ctx) => {
const log = _logger(source, ctx);
const childId = msg.payload;
const childObj = ctx?.RED?.nodes?.getNode?.(childId);
if (!childObj?.source) {
log?.warn?.(`child.register skipped: missing child/source for id=${childId}`);
return;
}
source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent, msg.distance);
};