node-red-contrib-mobius-flow-base 2.5.86-beta.8 → 2.5.87
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
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
# node-red-contrib-mobius-flow-base
|
|
2
|
-

|
|
3
2
|
|
|
4
|
-
Copyright 2016 [
|
|
3
|
+
Copyright 2016 [iaconnects](http://www.iaconnects.co.uk).
|
|
5
4
|
|
|
6
|
-
[Node-RED](http://nodered.org) nodes to interact with
|
|
5
|
+
[Node-RED](http://nodered.org) nodes to interact with MOBiUSFlow.
|
|
7
6
|
|
|
8
|
-
|
|
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.
|
|
7
|
+
This module currently requires access to the iaconnects private NPM repository.
|
|
14
8
|
|
|
15
9
|
## Nodes
|
|
16
10
|
|
|
@@ -33,4 +27,4 @@ Clears the specified priority of resource.
|
|
|
33
27
|
Subscribe to change of value events for an object
|
|
34
28
|
|
|
35
29
|
### Resource COV Node
|
|
36
|
-
Subscribe to change of value events for a resource
|
|
30
|
+
Subscribe to change of value events for a resource
|
|
@@ -520,30 +520,6 @@ module.exports = function (RED) {
|
|
|
520
520
|
node.updateObjectInServiceConfig = function (hid, sid, pid, ins, config, callback) {
|
|
521
521
|
node.service.srvcAPI.updateObjectInServiceConfig(hid, sid, pid, ins, config, callback);
|
|
522
522
|
};
|
|
523
|
-
|
|
524
|
-
node.getNodeConfig = function (hid) {
|
|
525
|
-
return new Promise((resolve, reject) => {
|
|
526
|
-
node.service.srvcAPI.getNodeConfig(hid, (err, response) => {
|
|
527
|
-
if (!err) {
|
|
528
|
-
resolve(response);
|
|
529
|
-
} else {
|
|
530
|
-
reject(err);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
node.getServiceConfigProm = function (hid, sid) {
|
|
537
|
-
return new Promise((resolve, reject) => {
|
|
538
|
-
node.service.srvcAPI.getServiceConfig(hid, sid, (err, response) => {
|
|
539
|
-
if (!err) {
|
|
540
|
-
resolve(response);
|
|
541
|
-
} else {
|
|
542
|
-
reject(err);
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
};
|
|
547
523
|
}
|
|
548
524
|
|
|
549
525
|
RED.nodes.registerType('mobius connection', MobiusConnectionNode);
|
|
@@ -604,42 +580,4 @@ module.exports = function (RED) {
|
|
|
604
580
|
}
|
|
605
581
|
}
|
|
606
582
|
);
|
|
607
|
-
|
|
608
|
-
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
609
|
-
RED.httpAdmin.get('/mdiscover', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
610
|
-
let conn = RED.nodes.getNode(req.query.mobius);
|
|
611
|
-
let uri = req.query.uri;
|
|
612
|
-
if (conn === null || !conn.service.connected) {
|
|
613
|
-
RED.log.error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
614
|
-
throw new Error('Discover services failed - could not to connect to MOBiUS hub.');
|
|
615
|
-
} else {
|
|
616
|
-
uiDeviceDiscovery
|
|
617
|
-
.discover(conn, uri)
|
|
618
|
-
.then((response) => {
|
|
619
|
-
res.json(response);
|
|
620
|
-
})
|
|
621
|
-
.catch((err) => {
|
|
622
|
-
throw err;
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
628
|
-
RED.httpAdmin.get('/mgetservices', RED.auth.needsPermission('serial.read'), function (req, res) {
|
|
629
|
-
let conn = RED.nodes.getNode(req.query.mobius);
|
|
630
|
-
let hid = req.query.hid;
|
|
631
|
-
if (conn === null || !conn.service.connected) {
|
|
632
|
-
RED.log.error('Get services failed - could not to connect to MOBiUS hub.');
|
|
633
|
-
throw new Error('Get services failed - could not to connect to MOBiUS hub.');
|
|
634
|
-
} else {
|
|
635
|
-
uiDeviceDiscovery
|
|
636
|
-
.getServiceList(conn, hid)
|
|
637
|
-
.then((response) => {
|
|
638
|
-
res.json(response);
|
|
639
|
-
})
|
|
640
|
-
.catch((err) => {
|
|
641
|
-
RED.log.warn(`Get services failed - ${err}`);
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
583
|
};
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
const _ = require('lodash');
|
|
30
30
|
|
|
31
31
|
module.exports = {
|
|
32
|
-
async discover(connection, uri) {
|
|
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(RED, connection, hid, spids, pid) {
|
|
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,17 +54,12 @@ 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 (
|
|
58
|
-
services.value[srvcLoop].status === 'online' &&
|
|
59
|
-
(spids.length === 0 || spids.includes(services.value[srvcLoop].spid))
|
|
60
|
-
) {
|
|
57
|
+
if (services.value[srvcLoop].status === 'online' && (spids.length === 0 || spids.includes(services.value[srvcLoop].spid))) {
|
|
61
58
|
let insURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}`;
|
|
62
59
|
try {
|
|
63
60
|
let instances = await this.discover(connection, insURI);
|
|
64
61
|
for (let insLoop = 0; insLoop < instances.value.length; insLoop++) {
|
|
65
|
-
let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${
|
|
66
|
-
instances.value[insLoop]
|
|
67
|
-
}`;
|
|
62
|
+
let deviceURI = `${hid}/${services.value[srvcLoop].id.split('/')[1]}/${pid}/${instances.value[insLoop]}`;
|
|
68
63
|
let device = await this.discover(connection, deviceURI);
|
|
69
64
|
let resourcesByName = _.keyBy(device.value[0].resources, 'name');
|
|
70
65
|
let deviceName = resourcesByName['name'].pv;
|
|
@@ -84,7 +79,7 @@ module.exports = {
|
|
|
84
79
|
});
|
|
85
80
|
},
|
|
86
81
|
|
|
87
|
-
async discoverServicesBySPID(RED, connection, hid, spid) {
|
|
82
|
+
async discoverServicesBySPID (RED, connection, hid, spid) {
|
|
88
83
|
if (!hid || hid === '') {
|
|
89
84
|
hid = connection.service.srvcAPI.status.hubId;
|
|
90
85
|
}
|
|
@@ -104,104 +99,5 @@ module.exports = {
|
|
|
104
99
|
return new Promise((resolve) => {
|
|
105
100
|
resolve(srvcs);
|
|
106
101
|
});
|
|
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
|
-
console.log(nodeConfig);
|
|
119
|
-
const servicesFromConfig = nodeConfig.value.services;
|
|
120
|
-
let services = [];
|
|
121
|
-
for (let i = 0; i < servicesFromConfig.length; i++) {
|
|
122
|
-
services.push({
|
|
123
|
-
id: servicesFromConfig.id,
|
|
124
|
-
spid: servicesFromConfig.id.split('/')[0],
|
|
125
|
-
sid: servicesFromConfig.id.split('/')[1],
|
|
126
|
-
uri: `${nodeConfig.uri}/${servicesFromConfig.id.split('/')[1]}`,
|
|
127
|
-
name: servicesFromConfig.name,
|
|
128
|
-
enabled: servicesFromConfig.enabled,
|
|
129
|
-
runAtStart: servicesFromConfig.runAtStart,
|
|
130
|
-
registered: null,
|
|
131
|
-
lastConnected: null,
|
|
132
|
-
status: null,
|
|
133
|
-
statusText: null,
|
|
134
|
-
mobiusSettings: null,
|
|
135
|
-
customSettings: null,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
console.log('Following get node config');
|
|
140
|
-
console.log(services);
|
|
141
|
-
|
|
142
|
-
// Fetch information from each service config
|
|
143
|
-
for (i = 0; i < services.length; i++) {
|
|
144
|
-
const fullServiceConfig = await connection.getServiceConfigProm(hid, services[i].sid);
|
|
145
|
-
services[i].mobiusSettings = fullServiceConfig.value.serviceConfig.settings;
|
|
146
|
-
services[i].customSettings = fullServiceConfig.value.serviceConfig.custom;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
console.log('Following service node configs');
|
|
150
|
-
console.log(services);
|
|
151
|
-
|
|
152
|
-
// Fetch information from discovered services
|
|
153
|
-
const discoveryResponse = await this.discover(connection, hid);
|
|
154
|
-
const servicesFromDiscovery = discoveryResponse.value;
|
|
155
|
-
for (i = 0; i < servicesFromDiscovery.length; i++) {
|
|
156
|
-
let serviceFound = false;
|
|
157
|
-
for (j = 0; j < services.length; j++) {
|
|
158
|
-
if (servicesFromDiscovery[i].id === services[j].id) {
|
|
159
|
-
serviceFound = true;
|
|
160
|
-
services[j].registered = servicesFromDiscovery[i].registered;
|
|
161
|
-
services[j].lastConnected = servicesFromDiscovery[i].lastconnected;
|
|
162
|
-
j = services.length;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (!serviceFound) {
|
|
166
|
-
services.push({
|
|
167
|
-
id: servicesFromDiscovery[i].id,
|
|
168
|
-
spid: servicesFromDiscovery[i].id.split('/')[0],
|
|
169
|
-
sid: servicesFromDiscovery[i].id.split('/')[1],
|
|
170
|
-
uri: `${nodeConfig.uri}/${servicesFromDiscovery[i].id.split('/')[1]}`,
|
|
171
|
-
name: null,
|
|
172
|
-
enabled: null,
|
|
173
|
-
runAtStart: null,
|
|
174
|
-
registered: servicesFromDiscovery[i].registered,
|
|
175
|
-
lastConnected: servicesFromDiscovery[i].lastconnected,
|
|
176
|
-
status: null,
|
|
177
|
-
statusText: null,
|
|
178
|
-
mobiusSettings: null,
|
|
179
|
-
customSettings: null,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
console.log('Following discover');
|
|
185
|
-
console.log(services);
|
|
186
|
-
|
|
187
|
-
// Fetch status object from all services
|
|
188
|
-
for (i = 0; i < services.length; i++) {
|
|
189
|
-
const statusObjectResponse = await this.discover(
|
|
190
|
-
connection,
|
|
191
|
-
`${hid}/${services[i].sid}/0001/0001`
|
|
192
|
-
);
|
|
193
|
-
const statusObject = statusObjectResponse.value;
|
|
194
|
-
services[i].status = statusObject.resources[1].pv;
|
|
195
|
-
services[i].statusText = `${statusObject.resources[2].pv}`;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
console.log('Complete');
|
|
199
|
-
console.log(services);
|
|
200
|
-
|
|
201
|
-
resolve(services);
|
|
202
|
-
} catch (err) {
|
|
203
|
-
reject(err);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
},
|
|
102
|
+
}
|
|
207
103
|
};
|