working
This commit is contained in:
@@ -87,8 +87,6 @@ class nodeClass {
|
||||
}
|
||||
};
|
||||
|
||||
console.log(`position vs child for ${this.name} is ${this.config.functionality.positionVsParent} the distance is ${this.config.functionality.distance}`);
|
||||
|
||||
// Utility for formatting outputs
|
||||
this._output = new outputUtils();
|
||||
}
|
||||
@@ -154,17 +152,34 @@ class nodeClass {
|
||||
*/
|
||||
_attachInputHandler() {
|
||||
this.node.on('input', (msg, send, done) => {
|
||||
switch (msg.topic) {
|
||||
case 'simulator': this.source.toggleSimulation(); break;
|
||||
case 'outlierDetection': this.source.toggleOutlierDetection(); break;
|
||||
case 'calibrate': this.source.calibrate(); break;
|
||||
case 'measurement':
|
||||
if (typeof msg.payload === 'number') {
|
||||
this.source.inputValue = parseFloat(msg.payload);
|
||||
}
|
||||
break;
|
||||
try {
|
||||
switch (msg.topic) {
|
||||
case 'simulator':
|
||||
this.source.toggleSimulation();
|
||||
break;
|
||||
case 'outlierDetection':
|
||||
this.source.toggleOutlierDetection();
|
||||
break;
|
||||
case 'calibrate':
|
||||
this.source.calibrate();
|
||||
break;
|
||||
case 'measurement':
|
||||
if (typeof msg.payload === 'number' || (typeof msg.payload === 'string' && msg.payload.trim() !== '')) {
|
||||
const parsed = Number(msg.payload);
|
||||
if (!Number.isNaN(parsed)) {
|
||||
this.source.inputValue = parsed;
|
||||
} else {
|
||||
this.source.logger?.warn(`Invalid numeric measurement payload: ${msg.payload}`);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.source.logger?.warn(`Unknown topic: ${msg.topic}`);
|
||||
}
|
||||
} catch (error) {
|
||||
this.source.logger?.error(`Input handler failure: ${error.message}`);
|
||||
}
|
||||
done();
|
||||
if (typeof done === 'function') done();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -175,7 +190,7 @@ class nodeClass {
|
||||
this.node.on('close', (done) => {
|
||||
clearInterval(this._tickInterval);
|
||||
//clearInterval(this._statusInterval);
|
||||
done();
|
||||
if (typeof done === 'function') done();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
const EventEmitter = require('events');
|
||||
const {logger,configUtils,configManager,MeasurementContainer} = require('generalFunctions');
|
||||
|
||||
/**
|
||||
* Measurement domain model.
|
||||
* Handles scaling, smoothing, outlier filtering and emits normalized measurement output.
|
||||
*/
|
||||
class Measurement {
|
||||
constructor(config={}) {
|
||||
|
||||
@@ -506,7 +510,10 @@ class Measurement {
|
||||
}
|
||||
|
||||
toggleOutlierDetection() {
|
||||
this.config.outlierDetection = !this.config.outlierDetection;
|
||||
// Keep the outlier configuration shape stable and only toggle the enabled flag.
|
||||
const currentState = Boolean(this.config?.outlierDetection?.enabled);
|
||||
this.config.outlierDetection = this.config.outlierDetection || {};
|
||||
this.config.outlierDetection.enabled = !currentState;
|
||||
}
|
||||
|
||||
getOutput() {
|
||||
@@ -586,4 +593,4 @@ function changeInput(){
|
||||
//m.inputValue = 5;
|
||||
}
|
||||
|
||||
// */
|
||||
// */
|
||||
|
||||
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict');
|
||||
const NodeClass = require('../../src/nodeClass');
|
||||
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
|
||||
|
||||
test('measurement topic ignores non-number payloads (current behavior)', () => {
|
||||
test('measurement topic accepts numeric strings and ignores non-numeric objects', () => {
|
||||
const inst = Object.create(NodeClass.prototype);
|
||||
const node = makeNodeStub();
|
||||
const calls = [];
|
||||
@@ -24,5 +24,5 @@ test('measurement topic ignores non-number payloads (current behavior)', () => {
|
||||
onInput({ topic: 'measurement', payload: '42' }, () => {}, () => {});
|
||||
onInput({ topic: 'measurement', payload: { value: 42 } }, () => {}, () => {});
|
||||
|
||||
assert.equal(calls.length, 0);
|
||||
assert.deepEqual(calls, [42]);
|
||||
});
|
||||
|
||||
@@ -3,10 +3,12 @@ const assert = require('node:assert/strict');
|
||||
|
||||
const { makeMeasurementInstance } = require('../helpers/factories');
|
||||
|
||||
test('toggleOutlierDetection currently converts config object to boolean (known gap)', () => {
|
||||
test('toggleOutlierDetection toggles enabled flag while preserving config object', () => {
|
||||
const m = makeMeasurementInstance();
|
||||
|
||||
assert.equal(typeof m.config.outlierDetection, 'object');
|
||||
const before = Boolean(m.config.outlierDetection.enabled);
|
||||
m.toggleOutlierDetection();
|
||||
assert.equal(typeof m.config.outlierDetection, 'boolean');
|
||||
assert.equal(typeof m.config.outlierDetection, 'object');
|
||||
assert.equal(Boolean(m.config.outlierDetection.enabled), !before);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user