node-red-contrib-mobius-flow-base 2.5.86-beta.4 → 2.5.86-beta.40
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/dist/nodes/mobius-connection.js +72 -0
- package/dist/nodes/mobius-discover-object-list.html +266 -6
- package/dist/nodes/mobius-get-multi-object.html +278 -7
- package/dist/nodes/mobius-get-object.html +270 -5
- package/dist/nodes/mobius-get-object.js +13 -10
- package/dist/nodes/mobius-object-cov.html +270 -5
- package/dist/nodes/mobius-object-cov.js +10 -7
- package/dist/nodes/node-red-ui-discover-devices.js +136 -6
- package/package.json +1 -1
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
const _ = require('lodash');
|
|
31
31
|
|
|
32
32
|
module.exports = function (RED) {
|
|
33
|
-
function MobiusGetObjectNode
|
|
33
|
+
function MobiusGetObjectNode(n) {
|
|
34
34
|
RED.nodes.createNode(this, n);
|
|
35
35
|
this.detailedOutput = n.detailedOutput;
|
|
36
36
|
this.format = n.format;
|
|
37
|
-
this.
|
|
37
|
+
this.instance = n.instance;
|
|
38
38
|
this.serviceConn = RED.nodes.getNode(n.connection);
|
|
39
39
|
var node = this;
|
|
40
40
|
|
|
@@ -42,11 +42,11 @@ module.exports = function (RED) {
|
|
|
42
42
|
node.status({
|
|
43
43
|
fill: 'red',
|
|
44
44
|
shape: 'ring',
|
|
45
|
-
text: 'Disconnected'
|
|
45
|
+
text: 'Disconnected',
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
node.on('input', function (msg) {
|
|
49
|
-
let uri = node.
|
|
49
|
+
let uri = node.instance;
|
|
50
50
|
if (msg.hasOwnProperty('topic') && require('./validateURI')(msg.topic, 4)) {
|
|
51
51
|
uri = msg.topic;
|
|
52
52
|
}
|
|
@@ -54,32 +54,35 @@ 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
|
node.serviceConn.readObject(uri, (err, response) => {
|
|
60
60
|
if (err) {
|
|
61
61
|
node.status({
|
|
62
62
|
fill: 'yellow',
|
|
63
63
|
shape: 'dot',
|
|
64
|
-
text: 'Error: ' + JSON.stringify(err.code)
|
|
64
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
65
65
|
});
|
|
66
66
|
node.error('Mobius error reading object ' + JSON.stringify(err));
|
|
67
67
|
if (node.detailedOutput === true) {
|
|
68
|
-
node.send([null, null, {topic: uri, payload: { error: true, response: err }}]);
|
|
68
|
+
node.send([null, null, { topic: uri, payload: { error: true, response: err } }]);
|
|
69
69
|
}
|
|
70
70
|
} else {
|
|
71
71
|
node.status({
|
|
72
72
|
fill: 'green',
|
|
73
73
|
shape: 'dot',
|
|
74
|
-
text: JSON.stringify(response.uri)
|
|
74
|
+
text: JSON.stringify(response.uri),
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
let allResources = _.keyBy(
|
|
77
|
+
let allResources = _.keyBy(
|
|
78
|
+
response.value.resources,
|
|
79
|
+
node.format === 'name' ? 'name' : 'rid'
|
|
80
|
+
);
|
|
78
81
|
if (node.detailedOutput === true) {
|
|
79
82
|
node.send([
|
|
80
83
|
{ topic: uri, payload: allResources },
|
|
81
84
|
{ topic: uri, payload: response.value },
|
|
82
|
-
{ topic: uri, payload: { error: false, response: response } }
|
|
85
|
+
{ topic: uri, payload: { error: false, response: response } },
|
|
83
86
|
]);
|
|
84
87
|
} else {
|
|
85
88
|
node.send({ topic: uri, payload: allResources });
|
|
@@ -29,9 +29,35 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
29
29
|
<label for="node-input-connection"><i class="fa fa-globe"></i> MOBiUS</label>
|
|
30
30
|
<input type="text" id="node-input-connection">
|
|
31
31
|
</div>
|
|
32
|
-
<div class="form-row">
|
|
33
|
-
<
|
|
34
|
-
|
|
32
|
+
<div id="instance-message-row" class="form-row hidden" style="color:#ff0000" align="center">
|
|
33
|
+
<p>To select a configured object from a drop-down list, <br/>
|
|
34
|
+
please create a MOBiUS connection, deploy the flow, and <br />
|
|
35
|
+
ensure that the node-red-connector service is running. <br />
|
|
36
|
+
Click the Confirm Deploy button if asked.</p>
|
|
37
|
+
</div>
|
|
38
|
+
<div id="instance-row">
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-instance"><i class="fa fa-tasks"></i> URI</label>
|
|
41
|
+
<input type="text" id="node-input-instance" style="width:61%;" placeholder="HID/SID/PID/INS (optional name)">
|
|
42
|
+
<a id="node-lookup-instance" class="searchbutton" style="vertical-align: middle"><i id="node-lookup-instance-icon" class="fa fa-search"></i></a>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<div id="instance-search-row">
|
|
46
|
+
<div class="form-row">
|
|
47
|
+
<label for="instance-search-sid"><i class="fa fa-tasks"></i> URI</label>
|
|
48
|
+
<input type="text" id="instance-search-hid" style="width:15%;" placeholder="HID">
|
|
49
|
+
<input type="text" id="instance-search-sid" style="width:10%;" placeholder="SID">
|
|
50
|
+
<input type="text" id="instance-search-pid" style="width:10%;" placeholder="PID">
|
|
51
|
+
<input type="text" id="instance-search-ins" style="width:10%;" placeholder="INS">
|
|
52
|
+
<a id="node-search-return" class="searchbutton" style="vertical-align: middle"><i id="node-search-return-icon" class="fa fa-arrow-left"></i></a>
|
|
53
|
+
<a id="node-search-accept" class="searchbutton" style="vertical-align: middle"><i id="node-search-accept-icon" class="fa fa-check"></i></a>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
<div id="wildcard-alert-row" class="form-row hidden" style="color:#555555" align="center">
|
|
57
|
+
<p>Please note: The selection of wildcard '+'
|
|
58
|
+
means a search for a specific instance or resource
|
|
59
|
+
cannot be performed. As such, enter the
|
|
60
|
+
INS manually.</p>
|
|
35
61
|
</div>
|
|
36
62
|
<div class="form-row">
|
|
37
63
|
<label for="node-input-include"><i class="fa fa-bars"></i> Include</label>
|
|
@@ -67,7 +93,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
67
93
|
detailedOutput: {value:false},
|
|
68
94
|
format: {value: "name", required: true},
|
|
69
95
|
include: {value: "changed", required: true},
|
|
70
|
-
|
|
96
|
+
instance: {value:"", validate:function(v) {
|
|
71
97
|
if(v === '') { return true; }
|
|
72
98
|
let parts = v.split('/');
|
|
73
99
|
for(let lp = 0; lp < parts.length; lp++) {
|
|
@@ -94,12 +120,251 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
94
120
|
if(this.name) {
|
|
95
121
|
return this.name;
|
|
96
122
|
} else {
|
|
97
|
-
return this.
|
|
123
|
+
return this.instance ? `ObjCOV - ${this.instance}` : "object cov";
|
|
98
124
|
}
|
|
99
125
|
},
|
|
100
126
|
labelStyle: function() {
|
|
101
127
|
return this.name ? "node_label_italic":"";
|
|
102
128
|
},
|
|
129
|
+
oneditprepare: function () {
|
|
130
|
+
|
|
131
|
+
var node = this;
|
|
132
|
+
let mobiusSrvc = $("#node-input-connection").val();
|
|
133
|
+
|
|
134
|
+
$("#instance-search-row").hide();
|
|
135
|
+
|
|
136
|
+
function doesMobiusServiceExist() {
|
|
137
|
+
let srvc = $("#node-input-mobius").val();
|
|
138
|
+
if (srvc === '_ADD_') {
|
|
139
|
+
$("#node-lookup-instance").hide();
|
|
140
|
+
$("#instance-message-row").show();
|
|
141
|
+
} else {
|
|
142
|
+
$("#instance-message-row").hide();
|
|
143
|
+
$("#node-lookup-instance").show();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
doesMobiusServiceExist();
|
|
147
|
+
|
|
148
|
+
$("#node-search-return").addClass('disabled');
|
|
149
|
+
|
|
150
|
+
// *** MOBSEARCH *** //
|
|
151
|
+
|
|
152
|
+
//Inital setup
|
|
153
|
+
$("#instance-search-row").hide();
|
|
154
|
+
$("#wildcard-alert-row").hide();
|
|
155
|
+
$("#node-search-return").addClass('disabled');
|
|
156
|
+
$.getJSON(`mgethid?mobius=${mobiusSrvc}`, function (response) {
|
|
157
|
+
$("#instance-search-hid").val(response);
|
|
158
|
+
})
|
|
159
|
+
let readyToAccept = false;
|
|
160
|
+
let searchObject = {
|
|
161
|
+
hid: $("#instance-search-hid").val(),
|
|
162
|
+
sid: $("#instance-search-sid").val(),
|
|
163
|
+
pid: $("#instance-search-pid").val(),
|
|
164
|
+
ins: $("#instance-search-ins").val(),
|
|
165
|
+
objects: []
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//Function to search for INSs
|
|
169
|
+
function insSearch (objects, pid) {
|
|
170
|
+
let inss = ['#'];
|
|
171
|
+
for (let i = 0; i < objects.length; i++) {
|
|
172
|
+
if (objects[i].pid === pid) {
|
|
173
|
+
const name = objects[i].resources[1].pv;
|
|
174
|
+
if (name === '') {
|
|
175
|
+
inss.push(objects[i].ins);
|
|
176
|
+
} else {
|
|
177
|
+
inss.push(`${objects[i].ins} - ${name}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
$("#instance-search-ins").autocomplete({
|
|
182
|
+
source: inss,
|
|
183
|
+
minLength: 0,
|
|
184
|
+
close: function (event, ui) {
|
|
185
|
+
acceptCheck();
|
|
186
|
+
$("#instance-search-ins").autocomplete('destroy');
|
|
187
|
+
if ($("#instance-search-ins").val().length > 4) {
|
|
188
|
+
$("#instance-search-ins").val($("#instance-search-ins").val().substring(0, 4))
|
|
189
|
+
}
|
|
190
|
+
searchObject.ins = $("#instance-search-ins").val();
|
|
191
|
+
}
|
|
192
|
+
}).autocomplete('search', '');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//Function to search for PIDs
|
|
196
|
+
function pidsSearch(objects) {
|
|
197
|
+
searchObject.objects = objects;
|
|
198
|
+
let pids = ['#', '+'];
|
|
199
|
+
for (let i = 0; i < objects.length; i++) {
|
|
200
|
+
pids.push(`${objects[i].pid} - ${objects[i].profileName}`);
|
|
201
|
+
}
|
|
202
|
+
pids = [...new Set(pids)];
|
|
203
|
+
$("#instance-search-pid").autocomplete({
|
|
204
|
+
source: pids,
|
|
205
|
+
minLength: 0,
|
|
206
|
+
close: function (event, ui) {
|
|
207
|
+
acceptCheck();
|
|
208
|
+
$("#instance-search-pid").autocomplete('destroy');
|
|
209
|
+
if ($("#instance-search-pid").val().length > 4) {
|
|
210
|
+
$("#instance-search-pid").val($("#instance-search-pid").val().substring(0, 4))
|
|
211
|
+
}
|
|
212
|
+
searchObject.pid = $("#instance-search-pid").val();
|
|
213
|
+
}
|
|
214
|
+
}).autocomplete('search', '');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//Function to search for SIDs, and then fetch child objects based on selection
|
|
218
|
+
function serviceSearch(response) {
|
|
219
|
+
let services = ['#', '+'];
|
|
220
|
+
for (let i = 0; i < response.length; i++) {
|
|
221
|
+
if (response[i].sid !== '009') {
|
|
222
|
+
services.push(`${response[i].sid} - ${response[i].name}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
$("#instance-search-sid").autocomplete({
|
|
226
|
+
source: services,
|
|
227
|
+
minLength: 0,
|
|
228
|
+
close: function (event, ui) {
|
|
229
|
+
acceptCheck();
|
|
230
|
+
$("#instance-search-sid").autocomplete('destroy');
|
|
231
|
+
if ($("#instance-search-sid").val().length > 3) {
|
|
232
|
+
$("#instance-search-sid").val($("#instance-search-sid").val().substring(0, 3))
|
|
233
|
+
}
|
|
234
|
+
searchObject.sid = $("#instance-search-sid").val();
|
|
235
|
+
if (searchObject.sid === '+') {
|
|
236
|
+
for (let i = 2; i < services.length; i++) {
|
|
237
|
+
$.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${services[i].substring(0, 3)}`, (objects) => {
|
|
238
|
+
searchObject.objects = searchObject.objects.concat(objects);
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
$.getJSON(`mgetobjects?mobius=${mobiusSrvc}&hid=${searchObject.hid}&sid=${searchObject.sid}`, (objects) => {
|
|
243
|
+
searchObject.objects = objects;
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}).autocomplete('search', '');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//Start a new search
|
|
251
|
+
function startSearch() {
|
|
252
|
+
$("#wildcard-alert-row").hide();
|
|
253
|
+
$("#instance-search-sid").val('');
|
|
254
|
+
$("#instance-search-pid").val('');
|
|
255
|
+
$("#instance-search-ins").val('');
|
|
256
|
+
searchObject.hid = $("#instance-search-hid").val()
|
|
257
|
+
searchObject.sid = '';
|
|
258
|
+
searchObject.pid = '';
|
|
259
|
+
searchObject.ins = '';
|
|
260
|
+
if (/((^([0-9A-F]){6}$)|^$)/.test(searchObject.hid)) {
|
|
261
|
+
$.getJSON(`mgetservices?mobius=${mobiusSrvc}&hid=${searchObject.hid}`, serviceSearch)
|
|
262
|
+
.fail((err) => {
|
|
263
|
+
console.log('Some kind of html failure message on service discovery');
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
//Finish a search
|
|
269
|
+
function finishSearch() {
|
|
270
|
+
$("#wildcard-alert-row").hide();
|
|
271
|
+
let uri = `${searchObject.hid}/${searchObject.sid}/${searchObject.pid}/${searchObject.ins}`
|
|
272
|
+
if (uri.includes('#')) {
|
|
273
|
+
uri = uri.substring(0,uri.indexOf('#') + 1)
|
|
274
|
+
}
|
|
275
|
+
$("#node-input-instance").val(uri);
|
|
276
|
+
$("#node-search-accept").css('color', '#CCCCCC');
|
|
277
|
+
readyToAccept = false;
|
|
278
|
+
$("#node-search-return").addClass('disabled');
|
|
279
|
+
$("#node-search-accept").addClass('disabled');
|
|
280
|
+
$("#node-lookup-instance").removeClass('disabled');
|
|
281
|
+
$("#instance-search-row").hide();
|
|
282
|
+
$("#instance-row").show();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//Function to update if accept button is grade out and functions based on conditions of fields
|
|
286
|
+
function acceptCheck() {
|
|
287
|
+
if (($("#instance-search-hid").val() !== '' && $("#instance-search-sid").val() !== '' && $("#instance-search-pid").val() !== '' && $("#instance-search-ins").val() !== '') ||
|
|
288
|
+
$("#instance-search-sid").val() === '#' || $("#instance-search-pid").val() === '#' || $("#instance-search-ins").val() === '#') {
|
|
289
|
+
$("#node-search-accept").css('color', '#555555');
|
|
290
|
+
readyToAccept = true;
|
|
291
|
+
} else {
|
|
292
|
+
$("#node-search-accept").css('color', '#CCCCCC');
|
|
293
|
+
readyToAccept = false;
|
|
294
|
+
}
|
|
295
|
+
if ($("#instance-search-sid").val() !== '+' && $("#instance-search-pid").val() !== '+') {
|
|
296
|
+
$("#wildcard-alert-row").hide();
|
|
297
|
+
} else {
|
|
298
|
+
$("#wildcard-alert-row").show();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Respond to clicks
|
|
303
|
+
$("#node-lookup-instance").click(function () { //When search button is clicked
|
|
304
|
+
$("#instance-search-sid").val('');
|
|
305
|
+
$("#instance-search-pid").val('');
|
|
306
|
+
$("#instance-search-ins").val('');
|
|
307
|
+
$("#node-lookup-instance").addClass('disabled');
|
|
308
|
+
$("#node-search-return").removeClass('disabled');
|
|
309
|
+
$("#node-search-accept").removeClass('disabled');
|
|
310
|
+
$("#instance-row").hide();
|
|
311
|
+
$("#instance-search-row").show();
|
|
312
|
+
});
|
|
313
|
+
$("#instance-search-sid").click(function () { //SID field clicked
|
|
314
|
+
$("#instance-search-pid").val('')
|
|
315
|
+
$("#instance-search-ins").val('')
|
|
316
|
+
searchObject.pid = '';
|
|
317
|
+
searchObject.ins = '';
|
|
318
|
+
searchObject.objects = [];
|
|
319
|
+
startSearch();
|
|
320
|
+
})
|
|
321
|
+
$("#instance-search-pid").click(function () { //PID field clicked
|
|
322
|
+
$("#instance-search-ins").val('')
|
|
323
|
+
searchObject.ins = '';
|
|
324
|
+
if (searchObject.sid !== '') {
|
|
325
|
+
pidsSearch(searchObject.objects);
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
$("#instance-search-ins").click(function () { //INS field clicked
|
|
329
|
+
if (searchObject.pid !== '' && searchObject.pid !== '+' && searchObject.sid !== '+') {
|
|
330
|
+
insSearch(searchObject.objects, searchObject.pid);
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
$("#node-search-return").click(function () { //Return/Back button clicked
|
|
334
|
+
$("#node-search-return").addClass('disabled');
|
|
335
|
+
$("#node-search-accept").addClass('disabled');
|
|
336
|
+
$("#node-lookup-instance").removeClass('disabled');
|
|
337
|
+
$("#instance-search-row").hide();
|
|
338
|
+
$("#instance-row").show();
|
|
339
|
+
});
|
|
340
|
+
$("#node-search-accept").click(function () { //Accept button clicked
|
|
341
|
+
if (readyToAccept) {
|
|
342
|
+
finishSearch();
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Respond to search field changes
|
|
347
|
+
$("#instance-search-hid").change(function () {
|
|
348
|
+
acceptCheck();
|
|
349
|
+
$("#instance-search-sid").val('');
|
|
350
|
+
$("#instance-search-pid").val('');
|
|
351
|
+
$("#instance-search-ins").val('');
|
|
352
|
+
});
|
|
353
|
+
$("#instance-search-sid").change(function () {
|
|
354
|
+
searchObject.sid = $("#instance-search-sid").val()
|
|
355
|
+
acceptCheck();
|
|
356
|
+
});
|
|
357
|
+
$("#instance-search-pid").change(function () {
|
|
358
|
+
searchObject.pid = $("#instance-search-pid").val()
|
|
359
|
+
acceptCheck();
|
|
360
|
+
});
|
|
361
|
+
$("#instance-search-ins").change(function () {
|
|
362
|
+
searchObject.ins = $("#instance-search-ins").val()
|
|
363
|
+
acceptCheck();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// *** MOBSEARCH *** //
|
|
367
|
+
},
|
|
103
368
|
oneditsave: function() {
|
|
104
369
|
if($("#node-input-detailedOutput").prop('checked')) {
|
|
105
370
|
this.outputs = 3;
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
var _ = require('lodash');
|
|
30
30
|
|
|
31
31
|
module.exports = function (RED) {
|
|
32
|
-
function MobiusObjectCovNode
|
|
32
|
+
function MobiusObjectCovNode(n) {
|
|
33
33
|
RED.nodes.createNode(this, n);
|
|
34
34
|
this.detailedOutput = n.detailedOutput;
|
|
35
|
-
this.
|
|
35
|
+
this.instance = n.instance;
|
|
36
36
|
this.format = n.format;
|
|
37
37
|
this.include = n.include;
|
|
38
38
|
this.serviceConn = RED.nodes.getNode(n.connection);
|
|
@@ -42,16 +42,19 @@ module.exports = function (RED) {
|
|
|
42
42
|
node.status({
|
|
43
43
|
fill: 'red',
|
|
44
44
|
shape: 'ring',
|
|
45
|
-
text: 'Disconnected'
|
|
45
|
+
text: 'Disconnected',
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
node.serviceConn.subscribeToObjectCOV(node.
|
|
48
|
+
node.serviceConn.subscribeToObjectCOV(node.instance, this.id, (response) => {
|
|
49
49
|
node.status({
|
|
50
50
|
fill: 'green',
|
|
51
51
|
shape: 'dot',
|
|
52
|
-
text: JSON.stringify(response.uri)
|
|
52
|
+
text: JSON.stringify(response.uri),
|
|
53
53
|
});
|
|
54
|
-
let allResources = _.keyBy(
|
|
54
|
+
let allResources = _.keyBy(
|
|
55
|
+
response.value.resources,
|
|
56
|
+
node.format === 'name' ? 'name' : 'rid'
|
|
57
|
+
);
|
|
55
58
|
if (node.include === 'changed') {
|
|
56
59
|
allResources = _.pickBy(allResources, (res) => {
|
|
57
60
|
return response.changed.includes(res.rid);
|
|
@@ -61,7 +64,7 @@ module.exports = function (RED) {
|
|
|
61
64
|
node.send([
|
|
62
65
|
{ topic: response.uri, payload: allResources },
|
|
63
66
|
{ topic: response.uri, payload: response.value },
|
|
64
|
-
{ topic: response.uri, payload: { response: response } }
|
|
67
|
+
{ topic: response.uri, payload: { response: response } },
|
|
65
68
|
]);
|
|
66
69
|
} else {
|
|
67
70
|
node.send({ topic: response.uri, payload: allResources });
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
const _ = require('lodash');
|
|
30
30
|
|
|
31
31
|
module.exports = {
|
|
32
|
-
async discover
|
|
32
|
+
async discover(connection, uri) {
|
|
33
33
|
return new Promise((resolve, reject) => {
|
|
34
34
|
connection.discover(uri, (err, response) => {
|
|
35
35
|
if (err) {
|
|
@@ -41,7 +41,7 @@ module.exports = {
|
|
|
41
41
|
});
|
|
42
42
|
},
|
|
43
43
|
|
|
44
|
-
async discoverDevicesByPID
|
|
44
|
+
async discoverDevicesByPID(RED, connection, hid, spids, pid) {
|
|
45
45
|
let devices = [];
|
|
46
46
|
if (!hid || hid === '') {
|
|
47
47
|
hid = connection.service.srvcAPI.status.hubId;
|
|
@@ -54,12 +54,17 @@ module.exports = {
|
|
|
54
54
|
throw new Error(`Discover devices failed (${hid}) - ${err.message}`);
|
|
55
55
|
}
|
|
56
56
|
for (let srvcLoop = 0; srvcLoop < services.value.length; srvcLoop++) {
|
|
57
|
-
if (
|
|
57
|
+
if (
|
|
58
|
+
services.value[srvcLoop].status === 'online' &&
|
|
59
|
+
(spids.length === 0 || spids.includes(services.value[srvcLoop].spid))
|
|
60
|
+
) {
|
|
58
61
|
let insURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}`;
|
|
59
62
|
try {
|
|
60
63
|
let instances = await this.discover(connection, insURI);
|
|
61
64
|
for (let insLoop = 0; insLoop < instances.value.length; insLoop++) {
|
|
62
|
-
let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${
|
|
65
|
+
let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${
|
|
66
|
+
instances.value[insLoop]
|
|
67
|
+
}`;
|
|
63
68
|
let device = await this.discover(connection, deviceURI);
|
|
64
69
|
let resourcesByName = _.keyBy(device.value[0].resources, 'name');
|
|
65
70
|
let deviceName = resourcesByName['name'].pv;
|
|
@@ -79,7 +84,7 @@ module.exports = {
|
|
|
79
84
|
});
|
|
80
85
|
},
|
|
81
86
|
|
|
82
|
-
async discoverServicesBySPID
|
|
87
|
+
async discoverServicesBySPID(RED, connection, hid, spid) {
|
|
83
88
|
if (!hid || hid === '') {
|
|
84
89
|
hid = connection.service.srvcAPI.status.hubId;
|
|
85
90
|
}
|
|
@@ -99,5 +104,130 @@ module.exports = {
|
|
|
99
104
|
return new Promise((resolve) => {
|
|
100
105
|
resolve(srvcs);
|
|
101
106
|
});
|
|
102
|
-
}
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
getServiceList(connection, hid) {
|
|
110
|
+
// getNodeConfig -> id, spid, uri, name, enabled, runAtStart
|
|
111
|
+
// For every: getServiceConfig -> mobiusSettings, customSettings
|
|
112
|
+
// discover -> registered, last connected, status + any remaining if new service
|
|
113
|
+
// For every: discover object -/0001/0001 -> status, statusText
|
|
114
|
+
return new Promise(async (resolve, reject) => {
|
|
115
|
+
try {
|
|
116
|
+
// Fetch information from node config
|
|
117
|
+
const nodeConfig = await connection.getNodeConfig(hid);
|
|
118
|
+
const servicesFromConfig = nodeConfig.value.services;
|
|
119
|
+
let services = [];
|
|
120
|
+
for (let i = 0; i < servicesFromConfig.length; i++) {
|
|
121
|
+
services.push({
|
|
122
|
+
id: servicesFromConfig[i].id,
|
|
123
|
+
spid: servicesFromConfig[i].id.split('/')[0],
|
|
124
|
+
sid: servicesFromConfig[i].id.split('/')[1],
|
|
125
|
+
uri: `${nodeConfig.uri}/${servicesFromConfig[i].id.split('/')[1]}`,
|
|
126
|
+
name: servicesFromConfig[i].name,
|
|
127
|
+
enabled: servicesFromConfig[i].enabled,
|
|
128
|
+
runAtStart: servicesFromConfig[i].runAtStart,
|
|
129
|
+
registered: null,
|
|
130
|
+
lastConnected: null,
|
|
131
|
+
status: null,
|
|
132
|
+
statusText: null,
|
|
133
|
+
mobiusSettings: null,
|
|
134
|
+
customSettings: null,
|
|
135
|
+
pids: [],
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Fetch information from each service config
|
|
140
|
+
for (let i = 0; i < services.length; i++) {
|
|
141
|
+
const fullServiceConfig = await connection.getServiceConfigProm(hid, services[i].sid);
|
|
142
|
+
if (fullServiceConfig.value.serviceConfig !== undefined) {
|
|
143
|
+
services[i].mobiusSettings = fullServiceConfig.value.serviceConfig.settings;
|
|
144
|
+
services[i].customSettings = fullServiceConfig.value.serviceConfig.custom;
|
|
145
|
+
} else {
|
|
146
|
+
services[i].mobiusSettings = fullServiceConfig.value.settings;
|
|
147
|
+
services[i].customSettings = fullServiceConfig.value.custom;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Fetch information from discovered services
|
|
152
|
+
const discoveryResponse = await this.discover(connection, hid);
|
|
153
|
+
const servicesFromDiscovery = discoveryResponse.value;
|
|
154
|
+
for (let i = 0; i < servicesFromDiscovery.length; i++) {
|
|
155
|
+
let serviceFound = false;
|
|
156
|
+
for (let j = 0; j < services.length; j++) {
|
|
157
|
+
if (servicesFromDiscovery[i].id === services[j].id) {
|
|
158
|
+
serviceFound = true;
|
|
159
|
+
services[j].registered = servicesFromDiscovery[i].registered;
|
|
160
|
+
services[j].lastConnected = servicesFromDiscovery[i].lastconnected;
|
|
161
|
+
j = services.length;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!serviceFound) {
|
|
165
|
+
services.push({
|
|
166
|
+
id: servicesFromDiscovery[i].id,
|
|
167
|
+
spid: servicesFromDiscovery[i].id.split('/')[0],
|
|
168
|
+
sid: servicesFromDiscovery[i].id.split('/')[1],
|
|
169
|
+
uri: `${nodeConfig.uri}/${servicesFromDiscovery[i].id.split('/')[1]}`,
|
|
170
|
+
name: null,
|
|
171
|
+
enabled: null,
|
|
172
|
+
runAtStart: null,
|
|
173
|
+
registered: servicesFromDiscovery[i].registered,
|
|
174
|
+
lastConnected: servicesFromDiscovery[i].lastconnected,
|
|
175
|
+
status: null,
|
|
176
|
+
statusText: null,
|
|
177
|
+
mobiusSettings: null,
|
|
178
|
+
customSettings: null,
|
|
179
|
+
pids: [],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Fetch pids and status object from all services
|
|
185
|
+
for (let i = 0; i < services.length; i++) {
|
|
186
|
+
if (services[i].sid !== '009') {
|
|
187
|
+
const serviceResponse = await this.discover(connection, `${hid}/${services[i].sid}`);
|
|
188
|
+
services[i].pids = [...new Set(serviceResponse.value)];
|
|
189
|
+
const statusObjectResponse = await this.discover(
|
|
190
|
+
connection,
|
|
191
|
+
`${hid}/${services[i].sid}/0001/0001`
|
|
192
|
+
);
|
|
193
|
+
const statusObject = statusObjectResponse.value[0];
|
|
194
|
+
services[i].status = statusObject.resources[1].pv;
|
|
195
|
+
services[i].statusText = `${statusObject.resources[2].pv}`;
|
|
196
|
+
} else {
|
|
197
|
+
services[i].pids = [];
|
|
198
|
+
services[i].status = 'Unknown';
|
|
199
|
+
services[i].statusText = 'Unknown';
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
resolve(services);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
reject(JSON.stringify(err));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
getObjectList(connection, hid, sid) {
|
|
211
|
+
return new Promise(async (resolve, reject) => {
|
|
212
|
+
try {
|
|
213
|
+
let objectList = [];
|
|
214
|
+
const serviceResponse = await this.discover(connection, `${hid}/${sid}`);
|
|
215
|
+
const pids = [...new Set(serviceResponse.value)];
|
|
216
|
+
for (let i = 0; i < pids.length; i++) {
|
|
217
|
+
const inssResponse = await this.discover(connection, `${hid}/${sid}/${pids[i]}`);
|
|
218
|
+
const inss = inssResponse.value;
|
|
219
|
+
for (let j = 0; j < inss.length; j++) {
|
|
220
|
+
const objResponse = await this.discover(
|
|
221
|
+
connection,
|
|
222
|
+
`${hid}/${sid}/${pids[i]}/${inss[j]}`
|
|
223
|
+
);
|
|
224
|
+
objectList.push(objResponse.value[0]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
resolve(objectList);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
reject(JSON.stringify(err));
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
},
|
|
103
233
|
};
|