node-red-contrib-periph-humidity 1.5.1 → 1.5.2

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.
@@ -6,7 +6,7 @@ module.exports = function(RED) {
6
6
 
7
7
  const RESOLUTIONS = { '12/14': [12, 14], '8/12': [8, 12], '10/13': [10, 13], '11/11': [11, 11] };
8
8
 
9
- function Si7021Node(config) {
9
+ function Si7021DeviceNode(config) {
10
10
  RED.nodes.createNode(this, config);
11
11
  const node = this;
12
12
  try {
@@ -26,15 +26,26 @@ module.exports = function(RED) {
26
26
  node.error('Si7021 init failed: ' + e.message);
27
27
  }
28
28
 
29
+ node.on('close', function() {
30
+ if (node.connection) node.connection.close();
31
+ });
32
+ }
33
+ RED.nodes.registerType('si7021-device', Si7021DeviceNode);
34
+
35
+ function Si7021ReadNode(config) {
36
+ RED.nodes.createNode(this, config);
37
+ const node = this;
38
+ const deviceNode = RED.nodes.getNode(config.device) || {};
39
+
29
40
  node.on('input', async function(msg, send, done) {
30
- if (!node.driver) {
41
+ if (!deviceNode.driver) {
31
42
  node.error('Si7021 not initialised', msg);
32
43
  done();
33
44
  return;
34
45
  }
35
46
  try {
36
- await node.ready;
37
- const [temperature_c, humidity_pct] = await node.driver.read();
47
+ await deviceNode.ready;
48
+ const [temperature_c, humidity_pct] = await deviceNode.driver.read();
38
49
  msg.payload = { temperature_c, humidity_pct };
39
50
  send(msg);
40
51
  done();
@@ -42,10 +53,6 @@ module.exports = function(RED) {
42
53
  done(e);
43
54
  }
44
55
  });
45
-
46
- node.on('close', function() {
47
- if (node.connection) node.connection.close();
48
- });
49
56
  }
50
- RED.nodes.registerType('periph-si7021', Si7021Node);
57
+ RED.nodes.registerType('si7021', Si7021ReadNode);
51
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-humidity",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Node-RED nodes for humidity sensor chips",
5
5
  "keywords": [
6
6
  "node-red",
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- module.exports = function(RED) {
5
- const nodesDir = path.join(__dirname, 'nodes');
6
- if (!fs.existsSync(nodesDir)) return;
7
- fs.readdirSync(nodesDir).forEach(function(chip) {
8
- const nodeFile = path.join(nodesDir, chip, chip + '.js');
9
- if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
10
- });
11
- };