node-red-contrib-ruuvi-gateway 0.0.2 → 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ import type NodeRed from 'node-red';
2
+ type NodeAPI = NodeRed.NodeAPI;
3
+ declare function configRuuviGatewayModule(RED: NodeAPI): void;
4
+ export = configRuuviGatewayModule;
@@ -1,19 +1,4 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType('config-ruuvi-gateway',{
3
- category: 'config',
4
- defaults: {
5
- name: { value: "" },
6
- host: { value: "", required: true },
7
- token: { value: ""},
8
- },
9
- label: function() {
10
- return ( this.name || 'Ruuvi gateway config')
11
- }
12
- });
13
- </script>
14
-
15
- <script type="text/html" data-template-name="config-ruuvi-gateway">
16
- <div class="form-row">
1
+ <script type="text/javascript">RED.nodes.registerType("config-ruuvi-gateway",{category:"config",defaults:{name:{value:""},host:{value:"",required:!0},token:{value:""}},label:function(){return this.name||"Ruuvi gateway config"}})</script><script type="text/html" data-template-name="config-ruuvi-gateway"><div class="form-row">
17
2
  <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
18
3
  <input type="text" id="node-config-input-name" placeholder="Name">
19
4
  </div>
@@ -24,10 +9,4 @@
24
9
  <div class="form-row">
25
10
  <label for="node-config-input-token"><i class="fa fa-user-secret"></i> Token</label>
26
11
  <input type="password" id="node-config-input-token" placeholder="password">
27
- </div>
28
- </script>
29
-
30
- <script type="text/markdown" data-help-name="config-ruuvi-gateway">
31
-
32
- todo
33
- </script>
12
+ </div></script><script type="text/markdown" data-help-name="config-ruuvi-gateway">todo</script>
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ function configRuuviGatewayModule(RED) {
3
+ function ConfigRuuviGateway(n) {
4
+ RED.nodes.createNode(this, n);
5
+ this.name = n.name;
6
+ this.host = n.host;
7
+ this.token = n.token;
8
+ }
9
+ RED.nodes.registerType('config-ruuvi-gateway', ConfigRuuviGateway);
10
+ }
11
+ module.exports = configRuuviGatewayModule;
@@ -0,0 +1,4 @@
1
+ import type NodeRed from 'node-red';
2
+ type NodeAPI = NodeRed.NodeAPI;
3
+ declare function ruuviGatewayModule(RED: NodeAPI): void;
4
+ export = ruuviGatewayModule;
@@ -1,25 +1,4 @@
1
- <script type="text/javascript">
2
-
3
- RED.nodes.registerType('Ruuvi gateway',{
4
- category: 'network',
5
- color: '#d4efeb',
6
- defaults: {
7
- name: {value:""},
8
- gateway: {value:"", type: "config-ruuvi-gateway"},
9
- store_in_global_context: {value: false},
10
- verbose: {value: false}
11
- },
12
- icon: "ruuvi-gateway.svg",
13
- inputs:1,
14
- outputs:1,
15
- label: function() {
16
- return (this.name||"Ruuvi gateway")
17
- }
18
- });
19
- </script>
20
-
21
- <script type="text/html" data-template-name="Ruuvi gateway">
22
- <div class="form-row">
1
+ <script type="text/javascript">RED.nodes.registerType("Ruuvi gateway",{category:"network",color:"#d4efeb",defaults:{name:{value:""},gateway:{value:"",type:"config-ruuvi-gateway"},store_in_global_context:{value:!1},verbose:{value:!1}},icon:"ruuvi-gateway.svg",inputs:1,outputs:1,label:function(){return this.name||"Ruuvi gateway"}})</script><script type="text/html" data-template-name="Ruuvi gateway"><div class="form-row">
23
2
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
3
  <input type="text" id="node-input-name" placeholder="Name">
25
4
  </div>
@@ -34,12 +13,7 @@
34
13
  <div class="form-row" style="margin-bottom:0px;">
35
14
  <input type="checkbox" id="node-input-verbose" style="display:inline-block; margin-left:8px; width:auto; vertical-align:top;">
36
15
  <label style="min-width:390px" for="node-input-verbose"> Verbose: show the used <em>url</em> in the debug tab?</label>
37
- </div>
38
- </script>
39
-
40
- <script type="text/markdown" data-help-name="Ruuvi gateway">
41
-
42
- Interface with the [Ruuvi gateway](https://ruuvi.com/gateway/).
16
+ </div></script><script type="text/markdown" data-help-name="Ruuvi gateway">Interface with the [Ruuvi gateway](https://ruuvi.com/gateway/).
43
17
 
44
18
  ### Inputs
45
19
 
@@ -82,5 +56,4 @@ Then copy and paste the token into the configuration of a new Ruuvi gateway.
82
56
 
83
57
  Also fill out the hostname or ip address for the Ruuvi gateway. The easiest way is to
84
58
  enter `ruuvigatewayXXXX.local`, where the `XXXX` match the code, which is printed on the
85
- backside of the Ruuvi gateway.
86
- </script>
59
+ backside of the Ruuvi gateway.</script>
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ const axios_1 = __importDefault(require("axios"));
39
+ const path = __importStar(require("path"));
40
+ function ruuviGatewayModule(RED) {
41
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
42
+ const packageJson = require(path.join(__dirname, '../../', 'package.json'));
43
+ function RuuviGatewayNode(config) {
44
+ RED.nodes.createNode(this, config);
45
+ this.gateway = RED.nodes.getNode(config.gateway);
46
+ const node = this;
47
+ node.on('input', function (msg) {
48
+ const url = msg['url'] ?? `http://${node.gateway?.host}/history`;
49
+ const headers = {
50
+ 'User-Agent': `node-red-contrib-ruuvi-gateway/${packageJson.version}`,
51
+ Authorization: `Bearer ${node.gateway?.token}`,
52
+ };
53
+ axios_1.default.get(url, { headers }).then(function (response) {
54
+ const data = response.data.data;
55
+ msg['payload'] = data;
56
+ if (config.store_in_global_context === true) {
57
+ node.context().global.set(`ruuvi.${data.gw_mac}`, data);
58
+ }
59
+ msg['topic'] = data.gw_mac;
60
+ node.status({ fill: 'green', shape: 'ring', text: 'Ok' });
61
+ node.send(msg);
62
+ }).catch(function (error) {
63
+ if (error.response && error.message) {
64
+ node.status({ fill: 'red', shape: 'dot', text: error.message });
65
+ }
66
+ else {
67
+ node.status({ fill: 'red', shape: 'dot', text: 'Error fetching Ruuvi data' });
68
+ }
69
+ });
70
+ if (config.verbose === true) {
71
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
72
+ const curlirize = require('axios-curlirize');
73
+ curlirize(axios_1.default, (result, err) => {
74
+ if (!err) {
75
+ node.warn(result.command);
76
+ }
77
+ });
78
+ }
79
+ });
80
+ node.on('close', function (done) {
81
+ done();
82
+ });
83
+ }
84
+ RED.nodes.registerType('Ruuvi gateway', RuuviGatewayNode);
85
+ }
86
+ module.exports = ruuviGatewayModule;
package/package.json CHANGED
@@ -1,10 +1,28 @@
1
1
  {
2
2
  "name": "node-red-contrib-ruuvi-gateway",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Poll a Ruuvi gateway",
5
- "main": "ruuvi-gateway.js",
5
+ "main": "dist/nodes/ruuvi-gateway.js",
6
+ "files": [
7
+ "dist/",
8
+ "examples/"
9
+ ],
6
10
  "scripts": {
7
- "test": "standard --fix"
11
+ "build": "npm run build:ts && npm run build:html && npm run build:icons",
12
+ "build:ts": "tsc -p tsconfig.build.json",
13
+ "build:html": "html-minifier-terser src/nodes/ruuvi-gateway.html -o dist/nodes/ruuvi-gateway.html --collapse-whitespace --remove-comments --minify-js true && html-minifier-terser src/nodes/config-ruuvi-gateway.html -o dist/nodes/config-ruuvi-gateway.html --collapse-whitespace --remove-comments --minify-js true",
14
+ "build:icons": "mkdir -p dist/nodes/icons && cp src/nodes/icons/* dist/nodes/icons/",
15
+ "watch": "tsc --watch",
16
+ "test": "jest --forceExit",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "node-red": {
20
+ "version": ">=3.0.2",
21
+ "nodes": {
22
+ "config-ruuvi-gateway": "dist/nodes/config-ruuvi-gateway.js",
23
+ "ruuvi-gateway": "dist/nodes/ruuvi-gateway.js"
24
+ },
25
+ "examples": "examples"
8
26
  },
9
27
  "keywords": [
10
28
  "node-red",
@@ -14,25 +32,37 @@
14
32
  ],
15
33
  "author": "Dirk-Jan Faber <dfaber@victronenergy.com>",
16
34
  "license": "MIT",
17
- "node-red": {
18
- "nodes": {
19
- "config-ruuvi-gateway": "./src/nodes/config-ruuvi-gateway.js",
20
- "ruuvi-gateway": "./src/nodes/ruuvi-gateway.js"
21
- },
22
- "version": ">=3.0.2"
23
- },
24
35
  "repository": {
25
36
  "type": "git",
26
37
  "url": "https://github.com/dirkjanfaber/node-red-contrib-ruuvi-gateway"
27
38
  },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
28
42
  "dependencies": {
29
43
  "axios": "^1.4.0",
30
44
  "axios-curlirize": "^1.3.7"
31
45
  },
32
46
  "devDependencies": {
33
- "standard": "^17.1.0"
47
+ "@types/jest": "^30.0.0",
48
+ "@types/node": "^25.7.0",
49
+ "@types/node-red": "^1.3.4",
50
+ "html-minifier-terser": "^7.2.0",
51
+ "jest": "^30.4.2",
52
+ "node-red": "^4.1.10",
53
+ "node-red-node-test-helper": "^0.3.4",
54
+ "ts-jest": "^29.1.4",
55
+ "typescript": "^6.0.3"
34
56
  },
35
- "engines": {
36
- "node": ">=14.17.4"
57
+ "peerDependencies": {
58
+ "node-red": ">=3.0.2"
59
+ },
60
+ "peerDependenciesMeta": {
61
+ "node-red": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "overrides": {
66
+ "typescript": "^6.0.3"
37
67
  }
38
68
  }
Binary file
@@ -1,10 +0,0 @@
1
- module.exports = function (RED) {
2
- 'use strict'
3
- function ConfigRuuviGateway (n) {
4
- RED.nodes.createNode(this, n)
5
- this.name = n.name
6
- this.host = n.host
7
- this.token = n.token
8
- }
9
- RED.nodes.registerType('config-ruuvi-gateway', ConfigRuuviGateway)
10
- }
@@ -1,48 +0,0 @@
1
- const axios = require('axios')
2
- const curlirize = require('axios-curlirize')
3
- const path = require('path')
4
- const packageJson = require(path.join(__dirname, '../../', 'package.json'))
5
-
6
- module.exports = function (RED) {
7
- function RuuviGatewayNode (config) {
8
- RED.nodes.createNode(this, config)
9
- this.gateway = RED.nodes.getNode(config.gateway)
10
- const node = this
11
-
12
- node.on('input', function (msg) {
13
- const url = msg.url || `http://${node.gateway.host}/history`
14
- const headers = {
15
- 'User-Agent': 'node-red-contrib-ruuvi-gateway/' + packageJson.version,
16
- Authorization: `Bearer ${node.gateway.token}`
17
- }
18
-
19
- axios.get(url, { headers }).then(function (response) {
20
- msg.payload = response.data.data
21
- if (config.store_in_global_context === true) {
22
- const globalContext = node.context().global
23
- globalContext.set('ruuvi.' + response.data.data.gw_mac, response.data.data)
24
- }
25
- msg.topic = response.data.data.gw_mac
26
- node.status({ fill: 'green', shape: 'ring', text: 'Ok' })
27
- node.send(msg)
28
- }).catch(function (error) {
29
- if (error.response && error.message) {
30
- node.status({ fill: 'red', shape: 'dot', text: error.message })
31
- } else {
32
- node.status({ fill: 'red', shape: 'dot', text: 'Error fetching Ruuvi data' })
33
- }
34
- })
35
-
36
- if (config.verbose === true) {
37
- curlirize(axios, (result, err) => {
38
- node.warn(result.command)
39
- })
40
- }
41
- })
42
-
43
- node.on('close', function (done) {
44
- done()
45
- })
46
- }
47
- RED.nodes.registerType('Ruuvi gateway', RuuviGatewayNode)
48
- }
File without changes