P6: convert monster to BaseDomain + BaseNodeAdapter + concern split

Refactor of monster to use the platform infrastructure (BaseDomain, BaseNodeAdapter,
ChildRouter, commandRegistry, statusBadge). Extracts concerns into
focused modules per .claude/refactor/MODULE_SPLIT.md generic template.
Tests stay green; CONTRACT.md generated; legacy aliases preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-10 22:09:25 +02:00
parent 5a43f90569
commit 2a6a0bc34b
12 changed files with 710 additions and 1075 deletions

42
src/commands/handlers.js Normal file
View File

@@ -0,0 +1,42 @@
'use strict';
// Handlers for monster input topics. Each is a pure function over the
// domain (source). Unit conversion for incoming flow happens in the
// handler (the legacy nodeClass did it inline) — anything else inbound
// is passed straight through to source.handleInput.
const { convert } = require('generalFunctions');
exports.cmdStart = (source, msg) => {
source.handleInput('i_start', Boolean(msg.payload));
};
exports.setSchedule = (source, msg) => {
source.handleInput('monsternametijden', msg.payload);
};
exports.setRain = (source, msg) => {
source.handleInput('rain_data', msg.payload);
};
exports.dataFlow = (source, msg, ctx) => {
const log = ctx?.logger || source.logger;
const value = Number(msg.payload?.value);
const unit = msg.payload?.unit;
if (!Number.isFinite(value) || !unit) {
log?.warn?.('data.flow payload must include numeric value and unit.');
return;
}
let converted = value;
try { converted = convert(value).from(unit).to('m3/h'); }
catch (err) { log?.warn?.(`data.flow unit conversion failed: ${err.message}`); return; }
source.handleInput('input_q', { value: converted, unit: 'm3/h' });
};
exports.setMode = (source, msg) => {
if (typeof source.setMode === 'function') source.setMode(msg.payload);
};
exports.setModelPrediction = (source, msg) => {
if (typeof source.setModelPrediction === 'function') source.setModelPrediction(msg.payload);
};