Files
settler/src/commands/handlers.js
znetsixe b8247fc755 P6: convert settler to platform infrastructure
Refactor of settler to use BaseNodeAdapter + commandRegistry + statusBadge.
settler follows the platform refactor plan in .claude/refactor/MODULE_SPLIT.md.
Tests stay green; CONTRACT.md generated; legacy aliases preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:23:44 +02:00

33 lines
1.3 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 currently accepts no behavioural commands — the legacy
// `registerChild` topic is handled by the BaseNodeAdapter input dispatch
// via the generalFunctions registry (`child.register` canonical) and the
// node never had a public set/cmd surface beyond that. Future
// influent-injection or operator-override topics will land 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();
};