112 lines
2.1 KiB
JavaScript
112 lines
2.1 KiB
JavaScript
const Measurement = require('../../src/specificClass');
|
|
|
|
function makeUiConfig(overrides = {}) {
|
|
return {
|
|
unit: 'bar',
|
|
enableLog: false,
|
|
logLevel: 'error',
|
|
supplier: 'vendor',
|
|
category: 'sensor',
|
|
assetType: 'pressure',
|
|
model: 'PT-1',
|
|
scaling: true,
|
|
i_min: 0,
|
|
i_max: 100,
|
|
o_min: 0,
|
|
o_max: 10,
|
|
i_offset: 0,
|
|
count: 5,
|
|
smooth_method: 'mean',
|
|
simulator: false,
|
|
positionVsParent: 'atEquipment',
|
|
hasDistance: false,
|
|
distance: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeMeasurementConfig(overrides = {}) {
|
|
return {
|
|
general: {
|
|
id: 'm-test-1',
|
|
name: 'measurement-test',
|
|
unit: 'bar',
|
|
logging: { enabled: false, logLevel: 'error' },
|
|
},
|
|
asset: {
|
|
uuid: '',
|
|
tagCode: '',
|
|
tagNumber: 'PT-001',
|
|
supplier: 'vendor',
|
|
category: 'sensor',
|
|
type: 'pressure',
|
|
model: 'PT-1',
|
|
unit: 'bar',
|
|
},
|
|
scaling: {
|
|
enabled: true,
|
|
inputMin: 0,
|
|
inputMax: 100,
|
|
absMin: 0,
|
|
absMax: 10,
|
|
offset: 0,
|
|
},
|
|
smoothing: {
|
|
smoothWindow: 5,
|
|
smoothMethod: 'mean',
|
|
},
|
|
simulation: {
|
|
enabled: false,
|
|
},
|
|
functionality: {
|
|
positionVsParent: 'atEquipment',
|
|
distance: undefined,
|
|
},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeNodeStub() {
|
|
const handlers = {};
|
|
const sent = [];
|
|
const status = [];
|
|
const warns = [];
|
|
return {
|
|
id: 'm-node-1',
|
|
source: null,
|
|
on(event, cb) { handlers[event] = cb; },
|
|
send(msg) { sent.push(msg); },
|
|
status(s) { status.push(s); },
|
|
warn(w) { warns.push(w); },
|
|
_handlers: handlers,
|
|
_sent: sent,
|
|
_status: status,
|
|
_warns: warns,
|
|
};
|
|
}
|
|
|
|
function makeREDStub(nodeMap = {}) {
|
|
return {
|
|
nodes: {
|
|
getNode(id) {
|
|
return nodeMap[id] || null;
|
|
},
|
|
createNode() {},
|
|
registerType() {},
|
|
},
|
|
httpAdmin: { get() {}, post() {} },
|
|
};
|
|
}
|
|
|
|
function makeMeasurementInstance(overrides = {}) {
|
|
return new Measurement(makeMeasurementConfig(overrides));
|
|
}
|
|
|
|
module.exports = {
|
|
makeUiConfig,
|
|
makeMeasurementConfig,
|
|
makeNodeStub,
|
|
makeREDStub,
|
|
makeMeasurementInstance,
|
|
};
|