Compare commits
2 Commits
54e1fd0f43
...
cbe868a148
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbe868a148 | ||
|
|
7ea49b8bd9 |
8
examples/README.md
Normal file
8
examples/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# valveGroupControl Example Flows
|
||||||
|
|
||||||
|
Import-ready Node-RED examples for valveGroupControl.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
- basic.flow.json
|
||||||
|
- integration.flow.json
|
||||||
|
- edge.flow.json
|
||||||
6
examples/basic.flow.json
Normal file
6
examples/basic.flow.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{"id":"valveGroupControl_basic_tab","type":"tab","label":"valveGroupControl basic","disabled":false,"info":"valveGroupControl basic example"},
|
||||||
|
{"id":"valveGroupControl_basic_node","type":"valveGroupControl","z":"valveGroupControl_basic_tab","name":"valveGroupControl basic","x":420,"y":180,"wires":[["valveGroupControl_basic_dbg"]]},
|
||||||
|
{"id":"valveGroupControl_basic_inj","type":"inject","z":"valveGroupControl_basic_tab","name":"basic trigger","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"ping","payload":"1","payloadType":"str","x":160,"y":180,"wires":[["valveGroupControl_basic_node"]]},
|
||||||
|
{"id":"valveGroupControl_basic_dbg","type":"debug","z":"valveGroupControl_basic_tab","name":"valveGroupControl basic debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":180,"wires":[]}
|
||||||
|
]
|
||||||
6
examples/edge.flow.json
Normal file
6
examples/edge.flow.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{"id":"valveGroupControl_edge_tab","type":"tab","label":"valveGroupControl edge","disabled":false,"info":"valveGroupControl edge example"},
|
||||||
|
{"id":"valveGroupControl_edge_node","type":"valveGroupControl","z":"valveGroupControl_edge_tab","name":"valveGroupControl edge","x":420,"y":180,"wires":[["valveGroupControl_edge_dbg"]]},
|
||||||
|
{"id":"valveGroupControl_edge_inj","type":"inject","z":"valveGroupControl_edge_tab","name":"unknown topic","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"doesNotExist","payload":"x","payloadType":"str","x":170,"y":180,"wires":[["valveGroupControl_edge_node"]]},
|
||||||
|
{"id":"valveGroupControl_edge_dbg","type":"debug","z":"valveGroupControl_edge_tab","name":"valveGroupControl edge debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":180,"wires":[]}
|
||||||
|
]
|
||||||
6
examples/integration.flow.json
Normal file
6
examples/integration.flow.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{"id":"valveGroupControl_int_tab","type":"tab","label":"valveGroupControl integration","disabled":false,"info":"valveGroupControl integration example"},
|
||||||
|
{"id":"valveGroupControl_int_node","type":"valveGroupControl","z":"valveGroupControl_int_tab","name":"valveGroupControl integration","x":420,"y":180,"wires":[["valveGroupControl_int_dbg"]]},
|
||||||
|
{"id":"valveGroupControl_int_inj","type":"inject","z":"valveGroupControl_int_tab","name":"registerChild","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"registerChild","payload":"example-child-id","payloadType":"str","x":170,"y":180,"wires":[["valveGroupControl_int_node"]]},
|
||||||
|
{"id":"valveGroupControl_int_dbg","type":"debug","z":"valveGroupControl_int_tab","name":"valveGroupControl integration debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":680,"y":180,"wires":[]}
|
||||||
|
]
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "Valve group control module",
|
"description": "Valve group control module",
|
||||||
"main": "valveGroupControl.js",
|
"main": "valveGroupControl.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node valveGroupControl.js"
|
"test": "node --test test/basic/*.test.js test/integration/*.test.js test/edge/*.test.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -169,36 +169,39 @@ class nodeClass {
|
|||||||
async (msg, send, done) => {
|
async (msg, send, done) => {
|
||||||
const vg = this.source;
|
const vg = this.source;
|
||||||
const RED = this.RED;
|
const RED = this.RED;
|
||||||
|
try {
|
||||||
switch (msg.topic) {
|
switch (msg.topic) {
|
||||||
case "registerChild":
|
case "registerChild": {
|
||||||
//console.log(`Registering child in mgc: ${msg.payload}`);
|
|
||||||
const childId = msg.payload;
|
const childId = msg.payload;
|
||||||
const childObj = RED.nodes.getNode(childId);
|
const childObj = RED.nodes.getNode(childId);
|
||||||
vg.childRegistrationUtils.registerChild(
|
if (!childObj || !childObj.source) {
|
||||||
childObj.source,
|
vg.logger.warn(`registerChild skipped: missing child/source for id=${childId}`);
|
||||||
msg.positionVsParent
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
vg.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'setMode':
|
case 'setMode':
|
||||||
vg.setMode(msg.payload);
|
vg.setMode(msg.payload);
|
||||||
break;
|
break;
|
||||||
case 'execSequence':
|
case 'execSequence': {
|
||||||
const { source: seqSource, action: seqAction, parameter } = msg.payload;
|
const { source: seqSource, action: seqAction, parameter } = msg.payload;
|
||||||
vg.handleInput(seqSource, seqAction, parameter);
|
vg.handleInput(seqSource, seqAction, parameter);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'totalFlowChange': // een van valves is van stand veranderd waardoor total flow is veranderd
|
case 'totalFlowChange': {
|
||||||
const { source: tfcSource, action: tfcAction, q} = msg.payload;
|
const { source: tfcSource, action: tfcAction, q} = msg.payload;
|
||||||
vg.handleInput(tfcSource, tfcAction, Number(q));
|
vg.handleInput(tfcSource, tfcAction, Number(q));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// Handle unknown topics if needed
|
|
||||||
vg.logger.warn(`Unknown topic: ${msg.topic}`);
|
vg.logger.warn(`Unknown topic: ${msg.topic}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
done();
|
} catch (error) {
|
||||||
|
vg.logger.error(`Input handler failure: ${error.message}`);
|
||||||
|
}
|
||||||
|
if (typeof done === 'function') done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -210,7 +213,7 @@ class nodeClass {
|
|||||||
this.node.on("close", (done) => {
|
this.node.on("close", (done) => {
|
||||||
clearInterval(this._tickInterval);
|
clearInterval(this._tickInterval);
|
||||||
clearInterval(this._statusInterval);
|
clearInterval(this._statusInterval);
|
||||||
done();
|
if (typeof done === 'function') done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
test/README.md
Normal file
12
test/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# valveGroupControl Test Suite Layout
|
||||||
|
|
||||||
|
Required EVOLV layout:
|
||||||
|
- basic/
|
||||||
|
- integration/
|
||||||
|
- edge/
|
||||||
|
- helpers/
|
||||||
|
|
||||||
|
Baseline structure tests:
|
||||||
|
- basic/structure-module-load.basic.test.js
|
||||||
|
- integration/structure-examples.integration.test.js
|
||||||
|
- edge/structure-examples-node-type.edge.test.js
|
||||||
0
test/basic/.gitkeep
Normal file
0
test/basic/.gitkeep
Normal file
8
test/basic/structure-module-load.basic.test.js
Normal file
8
test/basic/structure-module-load.basic.test.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
|
||||||
|
test('valveGroupControl module load smoke', () => {
|
||||||
|
assert.doesNotThrow(() => {
|
||||||
|
require('../../vgc.js');
|
||||||
|
});
|
||||||
|
});
|
||||||
0
test/edge/.gitkeep
Normal file
0
test/edge/.gitkeep
Normal file
11
test/edge/structure-examples-node-type.edge.test.js
Normal file
11
test/edge/structure-examples-node-type.edge.test.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
const flow = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../examples/basic.flow.json'), 'utf8'));
|
||||||
|
|
||||||
|
test('basic example includes node type valveGroupControl', () => {
|
||||||
|
const count = flow.filter((n) => n && n.type === 'valveGroupControl').length;
|
||||||
|
assert.equal(count >= 1, true);
|
||||||
|
});
|
||||||
0
test/helpers/.gitkeep
Normal file
0
test/helpers/.gitkeep
Normal file
0
test/integration/.gitkeep
Normal file
0
test/integration/.gitkeep
Normal file
23
test/integration/structure-examples.integration.test.js
Normal file
23
test/integration/structure-examples.integration.test.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
const dir = path.resolve(__dirname, '../../examples');
|
||||||
|
|
||||||
|
function loadJson(file) {
|
||||||
|
return JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
test('examples package exists for valveGroupControl', () => {
|
||||||
|
for (const file of ['README.md', 'basic.flow.json', 'integration.flow.json', 'edge.flow.json']) {
|
||||||
|
assert.equal(fs.existsSync(path.join(dir, file)), true, file + ' missing');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('example flows are parseable arrays for valveGroupControl', () => {
|
||||||
|
for (const file of ['basic.flow.json', 'integration.flow.json', 'edge.flow.json']) {
|
||||||
|
const parsed = loadJson(file);
|
||||||
|
assert.equal(Array.isArray(parsed), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user