node-red-contrib-mobius-flow-base 2.5.87 → 2.5.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/nodes/mobius-discover-object-list.js +66 -56
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# node-red-contrib-mobius-flow-base
|
|
2
|
+

|
|
2
3
|
|
|
3
|
-
Copyright 2016 [
|
|
4
|
+
Copyright 2016 [Interior Automation](http://www.interior-automation.co.uk) under the BSD-3-Clause license.
|
|
4
5
|
|
|
5
|
-
[Node-RED](http://nodered.org) nodes to interact with
|
|
6
|
+
[Node-RED](http://nodered.org) nodes to interact with Interior Automation's MOBiUS Flow.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Install
|
|
9
|
+
Run the following command in the root directory of your Node-RED install:
|
|
10
|
+
|
|
11
|
+
```npm install node-red-contrib-mobius-flow-base```
|
|
12
|
+
|
|
13
|
+
This module currently requires access to Interior Automation's private NPM repository. This will be made public in the future once MOBiUS Flow is ready for public release.
|
|
8
14
|
|
|
9
15
|
## Nodes
|
|
10
16
|
|
|
@@ -27,4 +33,4 @@ Clears the specified priority of resource.
|
|
|
27
33
|
Subscribe to change of value events for an object
|
|
28
34
|
|
|
29
35
|
### Resource COV Node
|
|
30
|
-
Subscribe to change of value events for a resource
|
|
36
|
+
Subscribe to change of value events for a resource
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusFlowNode
|
|
31
|
+
function MobiusFlowNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.subscriptions = n.subscriptions;
|
|
34
34
|
this.sendType = n.send;
|
|
@@ -45,7 +45,7 @@ module.exports = function (RED) {
|
|
|
45
45
|
node.status({
|
|
46
46
|
fill: 'red',
|
|
47
47
|
shape: 'ring',
|
|
48
|
-
text: 'Disconnected'
|
|
48
|
+
text: 'Disconnected',
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
node.serviceConn.register(node);
|
|
@@ -54,54 +54,57 @@ module.exports = function (RED) {
|
|
|
54
54
|
node.status({
|
|
55
55
|
fill: 'green',
|
|
56
56
|
shape: 'ring',
|
|
57
|
-
text: 'Busy'
|
|
57
|
+
text: 'Busy',
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
node
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
node
|
|
61
|
+
.discoverAllObjectURIs(msg)
|
|
62
|
+
.then((objectList) => {
|
|
63
|
+
if (node.sendType === 'individual') {
|
|
64
|
+
objectList.forEach((mobiusObject) => {
|
|
65
|
+
if (node.outputType === 'uris') {
|
|
66
|
+
node.send({
|
|
67
|
+
topic: mobiusObject.uri,
|
|
68
|
+
payload: mobiusObject.uri,
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
node.send({
|
|
72
|
+
topic: mobiusObject.uri,
|
|
73
|
+
payload: mobiusObject,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
63
78
|
if (node.outputType === 'uris') {
|
|
79
|
+
const uris = [];
|
|
80
|
+
objectList.forEach((mobiusObject) => {
|
|
81
|
+
uris.push(mobiusObject.uri);
|
|
82
|
+
});
|
|
64
83
|
node.send({
|
|
65
|
-
topic:
|
|
66
|
-
payload:
|
|
84
|
+
topic: msg.topic,
|
|
85
|
+
payload: uris,
|
|
67
86
|
});
|
|
68
87
|
} else {
|
|
69
88
|
node.send({
|
|
70
|
-
topic:
|
|
71
|
-
payload:
|
|
89
|
+
topic: msg.topic,
|
|
90
|
+
payload: objectList,
|
|
72
91
|
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
if (node.outputType === 'uris') {
|
|
77
|
-
const uris = [];
|
|
78
|
-
objectList.forEach((mobiusObject) => {
|
|
79
|
-
uris.push(mobiusObject.uri);
|
|
80
|
-
});
|
|
81
|
-
node.send({
|
|
82
|
-
topic: msg.topic,
|
|
83
|
-
payload: uris
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
node.send({
|
|
87
|
-
topic: msg.topic,
|
|
88
|
-
payload: objectList
|
|
89
|
-
});
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
|
|
95
|
+
node.status({
|
|
96
|
+
fill: 'green',
|
|
97
|
+
shape: 'dot',
|
|
98
|
+
text: 'Done',
|
|
99
|
+
});
|
|
100
|
+
})
|
|
101
|
+
.catch(() => {
|
|
102
|
+
node.status({
|
|
103
|
+
fill: 'yellow',
|
|
104
|
+
shape: 'dot',
|
|
105
|
+
text: 'Failed discovery',
|
|
106
|
+
});
|
|
103
107
|
});
|
|
104
|
-
});
|
|
105
108
|
if (done) {
|
|
106
109
|
done();
|
|
107
110
|
}
|
|
@@ -131,27 +134,29 @@ module.exports = function (RED) {
|
|
|
131
134
|
pids: pids,
|
|
132
135
|
rid: node.rid,
|
|
133
136
|
func: node.func,
|
|
134
|
-
limit: node.limit
|
|
137
|
+
limit: node.limit,
|
|
135
138
|
};
|
|
136
139
|
} else {
|
|
137
140
|
discoverParams = {
|
|
138
141
|
uri: serviceURI,
|
|
139
|
-
pids: pids,
|
|
140
|
-
rid: '00',
|
|
141
|
-
func: 'return true;',
|
|
142
|
-
limit: 512
|
|
142
|
+
// pids: pids,
|
|
143
|
+
// rid: '00',
|
|
144
|
+
// func: 'return true;',
|
|
145
|
+
// limit: 512
|
|
143
146
|
};
|
|
144
147
|
}
|
|
145
148
|
try {
|
|
146
149
|
let objects = await discover(node.serviceConn, discoverParams);
|
|
147
150
|
for (let lp = 0; lp < objects.value.length; lp++) {
|
|
148
|
-
objects.value[lp][
|
|
151
|
+
objects.value[lp][
|
|
152
|
+
'uri'
|
|
153
|
+
] = `${serviceURI}/${objects.value[lp].pid}/${objects.value[lp].ins}`;
|
|
149
154
|
objectList.push(objects.value[lp]);
|
|
150
155
|
}
|
|
151
156
|
} catch (err) {
|
|
152
157
|
node.warn(`Discover object failed for service (${serviceURI}) - ${err.message}`);
|
|
153
158
|
}
|
|
154
|
-
}
|
|
159
|
+
}
|
|
155
160
|
|
|
156
161
|
if (objectList.length === 0) {
|
|
157
162
|
throw new Error('No discovery data found');
|
|
@@ -176,23 +181,28 @@ module.exports = function (RED) {
|
|
|
176
181
|
let profiles = await discover(serviceConn, `${hid}/${sid}`);
|
|
177
182
|
let pids = [];
|
|
178
183
|
for (const pid of profiles.value) {
|
|
179
|
-
if (
|
|
184
|
+
if (
|
|
185
|
+
isIncluded(`${hid}/${sid}/${pid}/#`, subscriptions) &&
|
|
186
|
+
!isExcluded(`${hid}/${sid}/${pid}/#`, subscriptions)
|
|
187
|
+
) {
|
|
180
188
|
pids.push(pid);
|
|
181
|
-
}
|
|
189
|
+
}
|
|
182
190
|
}
|
|
183
191
|
if (pids.length > 0) {
|
|
184
192
|
discoveredProfiles.set(`${hid}/${sid}`, pids);
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
} else {
|
|
188
|
-
RED.log.warn(
|
|
196
|
+
RED.log.warn(
|
|
197
|
+
`Failed to discover objects for service ${service.id.split('/')[1]} as it is offline.`
|
|
198
|
+
);
|
|
189
199
|
}
|
|
190
200
|
}
|
|
191
201
|
resolve(discoveredProfiles);
|
|
192
202
|
});
|
|
193
203
|
}
|
|
194
204
|
|
|
195
|
-
async function discover
|
|
205
|
+
async function discover(serviceConn, params) {
|
|
196
206
|
return new Promise((resolve, reject) => {
|
|
197
207
|
serviceConn.discover(params, (err, response) => {
|
|
198
208
|
if (err) {
|
|
@@ -202,7 +212,7 @@ module.exports = function (RED) {
|
|
|
202
212
|
}
|
|
203
213
|
});
|
|
204
214
|
});
|
|
205
|
-
}
|
|
215
|
+
}
|
|
206
216
|
|
|
207
217
|
function isIncluded(uri, subscriptions) {
|
|
208
218
|
let include = false;
|
|
@@ -216,7 +226,7 @@ module.exports = function (RED) {
|
|
|
216
226
|
return include;
|
|
217
227
|
}
|
|
218
228
|
|
|
219
|
-
function isExcluded
|
|
229
|
+
function isExcluded(uri, subscriptions) {
|
|
220
230
|
let exclude = false;
|
|
221
231
|
for (const subscription of subscriptions) {
|
|
222
232
|
if (subscription.type === 'exclude' && validateSubscription(subscription.uri)) {
|
|
@@ -228,7 +238,7 @@ module.exports = function (RED) {
|
|
|
228
238
|
return exclude;
|
|
229
239
|
}
|
|
230
240
|
|
|
231
|
-
function validateSubscription
|
|
241
|
+
function validateSubscription(uri) {
|
|
232
242
|
let parts = uri.split('/');
|
|
233
243
|
for (let lp = 0; lp < parts.length; lp++) {
|
|
234
244
|
if (parts[lp] === null || parts[lp] === '') {
|
|
@@ -244,11 +254,11 @@ module.exports = function (RED) {
|
|
|
244
254
|
return false;
|
|
245
255
|
}
|
|
246
256
|
|
|
247
|
-
function matchTopic
|
|
257
|
+
function matchTopic(filter, topic) {
|
|
248
258
|
const filterArray = filter.split('/');
|
|
249
259
|
const topicArray = topic.split('/');
|
|
250
260
|
const length = filterArray.length < topicArray.length ? filterArray.length : topicArray.length;
|
|
251
|
-
|
|
261
|
+
|
|
252
262
|
for (let i = 0; i < length; ++i) {
|
|
253
263
|
const left = filterArray[i];
|
|
254
264
|
const right = topicArray[i];
|