node-red-contrib-mobius-flow-base 2.5.85 → 2.5.86-beta.100

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,10 +1,16 @@
1
1
  # node-red-contrib-mobius-flow-base
2
+ ![Version](https://img.shields.io/badge/Version-v1.0.12-blue.svg)
2
3
 
3
- Copyright 2016 [iaconnects](http://www.iaconnects.co.uk).
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 MOBiUSFlow.
6
+ [Node-RED](http://nodered.org) nodes to interact with Interior Automation's MOBiUS Flow.
6
7
 
7
- This module currently requires access to the iaconnects private NPM repository.
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
@@ -193,6 +193,91 @@ module.exports = function (RED) {
193
193
  });
194
194
  };
195
195
 
196
+ /**
197
+ * Select status text and colour of node status based on last active time
198
+ * @param {number} lastActiveTime - The node's last active time
199
+ * @returns Object containing status text and status colour
200
+ */
201
+ node.buildLastActiveTimeStatus = function (lastActiveTime) {
202
+ let response = {
203
+ text: 'Unknown',
204
+ colour: 'green',
205
+ };
206
+ const timeSinceLastActive = Date.now() - lastActiveTime;
207
+ if (timeSinceLastActive < 15 * 60000) {
208
+ response.text = 'Active less than 15 minutes ago';
209
+ }
210
+ if (timeSinceLastActive >= 15 * 60000 && timeSinceLastActive < 3 * 60 * 60000) {
211
+ response.text = 'Active less than 3 hours ago';
212
+ }
213
+ if (timeSinceLastActive >= 3 * 60 * 60000 && timeSinceLastActive < 12 * 60 * 60000) {
214
+ response.text = 'Active less than 12 hours ago';
215
+ }
216
+ if (timeSinceLastActive >= 12 * 60 * 60000 && timeSinceLastActive < 24 * 60 * 60000) {
217
+ response.text = 'Active less than 24 hours ago';
218
+ }
219
+ if (timeSinceLastActive > 24 * 60 * 60000 && lastActiveTime > 0) {
220
+ response.colour = 'grey';
221
+ response.text = 'Active more than 24 hours ago';
222
+ }
223
+ if (lastActiveTime === 0) {
224
+ response.colour = 'grey';
225
+ response.text = 'Never Active';
226
+ }
227
+ return {
228
+ fill: response.colour,
229
+ shape: 'dot',
230
+ text: response.text,
231
+ };
232
+ };
233
+
234
+ /**
235
+ * Update a given node's node status based on last active time
236
+ * @param {Object} mobiusNode - The node whos status is to be updated
237
+ */
238
+ node.updateNodeStatus = function (mobiusNode) {
239
+ node.users[mobiusNode.id] = mobiusNode;
240
+ let newStatus = {
241
+ fill: 'green',
242
+ shape: 'dot',
243
+ text: 'Connected',
244
+ };
245
+ switch (node.users[mobiusNode.id].statusType) {
246
+ case 'timeSinceLastActive':
247
+ newStatus = node.buildLastActiveTimeStatus(node.users[mobiusNode.id].lastActiveTime);
248
+ case 'lastUri':
249
+ const uri = node.users[mobiusNode.id].latestUri;
250
+ if (uri !== '') {
251
+ newStatus = {
252
+ fill: 'green',
253
+ shape: 'dot',
254
+ text: uri,
255
+ };
256
+ }
257
+ }
258
+ node.users[mobiusNode.id].status(newStatus);
259
+ };
260
+
261
+ /**
262
+ * Update a given node's node latest URI record
263
+ * @param {Object} mobiusNode - The node whos last URI record is to be updated
264
+ */
265
+ node.updateLatestUri = function (mobiusNode, uri) {
266
+ node.users[mobiusNode.id] = mobiusNode;
267
+ node.users[mobiusNode.id].latestUri = uri;
268
+ node.updateNodeStatus(mobiusNode);
269
+ };
270
+
271
+ /**
272
+ * Update a given node's node last active time
273
+ * @param {Object} mobiusNode - The node whos last active time is to be updated
274
+ */
275
+ node.updateLastActiveTime = function (mobiusNode) {
276
+ node.users[mobiusNode.id] = mobiusNode;
277
+ node.users[mobiusNode.id].lastActiveTime = Date.now();
278
+ node.updateNodeStatus(mobiusNode);
279
+ };
280
+
196
281
  /**
197
282
  * Register a new Mobius node with this config node
198
283
  * @param {Object} mobiusNode - The new node to register
@@ -206,6 +291,12 @@ module.exports = function (RED) {
206
291
  text: 'Connected',
207
292
  });
208
293
  }
294
+ node.users[mobiusNode.id].lastActiveTime = 0;
295
+ node.users[mobiusNode.id].statusCheckLoop = setInterval(() => {
296
+ if (node.connected) {
297
+ node.updateNodeStatus(mobiusNode);
298
+ }
299
+ }, 60000);
209
300
  };
210
301
 
211
302
  /**
@@ -214,6 +305,7 @@ module.exports = function (RED) {
214
305
  * @param {Function} done - A callback to be run by the node after it has been deregistered
215
306
  */
216
307
  node.deregister = function (mobiusNode, done) {
308
+ clearInterval(node.users[mobiusNode.id].statusCheckLoop);
217
309
  delete node.users[mobiusNode.id];
218
310
  if (node.service) {
219
311
  try {
@@ -53,6 +53,13 @@ POSSIBILITY OF SUCH DAMAGE.
53
53
  <label for="node-input-detailedOutput" style="width: 70%;"> Use detailed outputs</label>
54
54
  </div>
55
55
  <hr>
56
+ <div class="form-row">
57
+ <label for="node-input-statusType" ><i class="fa fa-bars"></i> Status </label>
58
+ <select type="text" id="node-input-statusType" style="display: inline-block; width: auto; vertical-align: center;">
59
+ <option value="timeSinceLastActive">Show time since last active</option>
60
+ <option value="lastUri">Show last URI</option>
61
+ </select>
62
+ </div>
56
63
  <div class="form-row">
57
64
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
58
65
  <input type="text" id="node-input-name" placeholder="Name">
@@ -64,6 +71,7 @@ POSSIBILITY OF SUCH DAMAGE.
64
71
  category: 'mobius',
65
72
  defaults: {
66
73
  name: {value:""},
74
+ statusType: {value:"timeSinceLastActive"},
67
75
  detailedOutput: {value:false},
68
76
  format: {value: "name", required: true},
69
77
  include: {value: "changed", required: true},
@@ -29,29 +29,30 @@
29
29
  var _ = require('lodash');
30
30
 
31
31
  module.exports = function (RED) {
32
- function MobiusObjectCovNode (n) {
32
+ function MobiusObjectCovNode(n) {
33
33
  RED.nodes.createNode(this, n);
34
34
  this.detailedOutput = n.detailedOutput;
35
35
  this.object = n.object;
36
36
  this.format = n.format;
37
37
  this.include = n.include;
38
38
  this.serviceConn = RED.nodes.getNode(n.connection);
39
+ this.latestUri = '';
40
+ this.statusType = n.statusType;
39
41
  var node = this;
40
42
 
41
43
  if (node.serviceConn) {
42
44
  node.status({
43
45
  fill: 'red',
44
46
  shape: 'ring',
45
- text: 'Disconnected'
47
+ text: 'Disconnected',
46
48
  });
47
-
48
49
  node.serviceConn.subscribeToObjectCOV(node.object, this.id, (response) => {
49
- node.status({
50
- fill: 'green',
51
- shape: 'dot',
52
- text: JSON.stringify(response.uri)
53
- });
54
- let allResources = _.keyBy(response.value.resources, node.format === 'name' ? 'name' : 'rid');
50
+ node.serviceConn.updateLatestUri(node, response.uri);
51
+ node.serviceConn.updateLastActiveTime(node);
52
+ let allResources = _.keyBy(
53
+ response.value.resources,
54
+ node.format === 'name' ? 'name' : 'rid'
55
+ );
55
56
  if (node.include === 'changed') {
56
57
  allResources = _.pickBy(allResources, (res) => {
57
58
  return response.changed.includes(res.rid);
@@ -61,7 +62,7 @@ module.exports = function (RED) {
61
62
  node.send([
62
63
  { topic: response.uri, payload: allResources },
63
64
  { topic: response.uri, payload: response.value },
64
- { topic: response.uri, payload: { response: response } }
65
+ { topic: response.uri, payload: { response: response } },
65
66
  ]);
66
67
  } else {
67
68
  node.send({ topic: response.uri, payload: allResources });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-mobius-flow-base",
3
- "version": "2.5.85",
3
+ "version": "2.5.86-beta.100",
4
4
  "description": "Node-RED base nodes for Mobius Flow",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",