@flecoufle/node-red-linky 1.0.0 → 1.2.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.
- package/CHANGELOG.md +9 -0
- package/README.md +0 -5
- package/linky/linky-config.html +32 -0
- package/linky/linky-config.js +14 -0
- package/linky/linky.html +21 -16
- package/linky/linky.js +63 -71
- package/package.json +6 -4
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -3,11 +3,6 @@ Retreive linky power consumption and production from <a href="https://github.com
|
|
|
3
3
|
|
|
4
4
|
See Enedis API documentation on <a href="https://datahub-enedis.fr/services-api/data-connect/documentation/">data-connect</a>
|
|
5
5
|
|
|
6
|
-
Note this package needs to use an older version of got, need help to use <b>got 12</b> (native ESM), feel free to submit a PR<br/>
|
|
7
|
-
<code>
|
|
8
|
-
"got": "^11.X.X"
|
|
9
|
-
</code>
|
|
10
|
-
|
|
11
6
|
## consumption usage
|
|
12
7
|
- <b>Récupération de la consommation énergétique quotidienne</b>: <code>daily_consumption</code>
|
|
13
8
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('linky-api-config', {
|
|
3
|
+
category: 'config',
|
|
4
|
+
defaults: {
|
|
5
|
+
name: { value: "", required: false },
|
|
6
|
+
prm: { value: "", required: true },
|
|
7
|
+
token: { value: "", required: true},
|
|
8
|
+
},
|
|
9
|
+
credentials: {
|
|
10
|
+
prm: { type: "text" },
|
|
11
|
+
token: { type: "password" }
|
|
12
|
+
},
|
|
13
|
+
label: function () {
|
|
14
|
+
return this.name || 'PRM:' + this.prm;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script type="text/html" data-template-name="linky-api-config">
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
22
|
+
<input type="text" id="node-config-input-name" placeholder="Name">
|
|
23
|
+
</div>
|
|
24
|
+
<div class="form-row">
|
|
25
|
+
<label for="node-config-input-token"><i class="fa fa-lock"></i> Token</label>
|
|
26
|
+
<input type="password" id="node-config-input-token" placeholder="your token">
|
|
27
|
+
</div>
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-config-input-prm"><i class="fa fa-wave-pulse"></i> PRM</label>
|
|
30
|
+
<input type="text" id="node-config-input-prm" placeholder="your PRM">
|
|
31
|
+
</div>
|
|
32
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = function (RED) {
|
|
2
|
+
function LinkyConfigNode(config) {
|
|
3
|
+
RED.nodes.createNode(this, config);
|
|
4
|
+
var node = this;
|
|
5
|
+
this.prm = node.credentials.prm;
|
|
6
|
+
this.token = node.credentials.token;
|
|
7
|
+
}
|
|
8
|
+
RED.nodes.registerType("linky-api-config", LinkyConfigNode, {
|
|
9
|
+
credentials: {
|
|
10
|
+
prm: { type: "text" },
|
|
11
|
+
token: { type: "password" }
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
package/linky/linky.html
CHANGED
|
@@ -3,10 +3,10 @@ Copyright 2023, François Lecoufle
|
|
|
3
3
|
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
5
|
this software and associated documentation files(the "Software"), to deal in
|
|
6
|
-
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
7
|
use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of
|
|
8
8
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
-
|
|
9
|
+
subject to the following conditions:
|
|
10
10
|
|
|
11
11
|
The above copyright notice and this permission notice shall be included in all
|
|
12
12
|
copies or substantial portions of the Software.
|
|
@@ -20,23 +20,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
<script type="text/javascript">
|
|
23
|
-
RED.nodes.registerType('linky-api',{
|
|
23
|
+
RED.nodes.registerType('linky-api', {
|
|
24
24
|
category: 'linky',
|
|
25
25
|
color: '#a6bbcf',
|
|
26
26
|
defaults: {
|
|
27
|
-
name: {value: "", required: false},
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
name: { value: "", required: false },
|
|
28
|
+
config: { value: "", required: false, type: "linky-api-config" },
|
|
29
|
+
prm: { value: "", required: false },
|
|
30
|
+
token: { value: "", required: false }
|
|
30
31
|
},
|
|
31
32
|
credentials: {
|
|
32
|
-
prm: {type: "text"},
|
|
33
|
-
token: {type: "password"}
|
|
33
|
+
prm: { type: "text" },
|
|
34
|
+
token: { type: "password" }
|
|
34
35
|
},
|
|
35
|
-
inputs:1,
|
|
36
|
-
outputs:1,
|
|
36
|
+
inputs: 1,
|
|
37
|
+
outputs: 1,
|
|
37
38
|
icon: 'font-awesome/fa-tachometer',
|
|
38
|
-
paletteLabel:'linky',
|
|
39
|
-
label: function() {
|
|
39
|
+
paletteLabel: 'linky',
|
|
40
|
+
label: function () {
|
|
40
41
|
return this.name || "linky";
|
|
41
42
|
}
|
|
42
43
|
});
|
|
@@ -45,15 +46,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
45
46
|
<script type="text/html" data-template-name="linky-api">
|
|
46
47
|
<div class="form-row">
|
|
47
48
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
48
|
-
<input type="text" id="node-input-name"
|
|
49
|
+
<input type="text" id="node-input-name">
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-config"><i class="fa fa-globe"></i> Config</label>
|
|
53
|
+
<input type="text" id="node-input-config">
|
|
49
54
|
</div>
|
|
50
55
|
<div class="form-row">
|
|
51
56
|
<label for="node-input-token"><i class="fa fa-lock"></i> Token</label>
|
|
52
|
-
<input type="password" id="node-input-token" placeholder="
|
|
57
|
+
<input type="password" id="node-input-token" placeholder="your token or in payload"/>
|
|
53
58
|
</div>
|
|
54
59
|
<div class="form-row">
|
|
55
60
|
<label for="node-input-prm"><i class="fa fa-wave-pulse"></i> PRM</label>
|
|
56
|
-
<input type="text" id="node-input-prm" placeholder="
|
|
61
|
+
<input type="text" id="node-input-prm" placeholder="your PRM or in payload"/>
|
|
57
62
|
</div>
|
|
58
63
|
</script>
|
|
59
64
|
|
|
@@ -150,4 +155,4 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
150
155
|
|
|
151
156
|
<h3>References</h3>
|
|
152
157
|
<ul><li>Node repository <a href="https://github.com/flecoufle/node-red-contrib-linky">flecoufle/node-red-contrib-linky</a></li></ul>
|
|
153
|
-
</script>
|
|
158
|
+
</script>
|
package/linky/linky.js
CHANGED
|
@@ -21,8 +21,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
21
21
|
|
|
22
22
|
"use strict";
|
|
23
23
|
|
|
24
|
-
module.exports = function (RED) {
|
|
25
|
-
const got =
|
|
24
|
+
module.exports = async function (RED) {
|
|
25
|
+
const { got } = await import('got');
|
|
26
26
|
|
|
27
27
|
const nodeStatus = {
|
|
28
28
|
WAIT: "Waiting...",
|
|
@@ -35,22 +35,25 @@ module.exports = function (RED) {
|
|
|
35
35
|
RED.nodes.createNode(this, config);
|
|
36
36
|
var node = this;
|
|
37
37
|
|
|
38
|
+
// config node
|
|
39
|
+
node.config = RED.nodes.getNode(config.config);
|
|
40
|
+
|
|
38
41
|
node.on('input', function (msg, send, done) {
|
|
39
42
|
const _p = {
|
|
40
|
-
"type": msg.payload
|
|
41
|
-
"token": msg.payload
|
|
42
|
-
"prm": msg.payload
|
|
43
|
-
"start": msg.payload
|
|
44
|
-
"end": msg.payload
|
|
45
|
-
"options_retry_limit": msg.payload
|
|
46
|
-
"options_timeout_lookup": msg.payload
|
|
47
|
-
"options_timeout_connect": msg.payload
|
|
48
|
-
"options_timeout_secureconnect": msg.payload
|
|
49
|
-
"options_timeout_socket": msg.payload
|
|
50
|
-
"options_timeout_send": msg.payload
|
|
51
|
-
"options_timeout_response": msg.payload
|
|
52
|
-
"random_delay"
|
|
53
|
-
"endpoint": msg.payload
|
|
43
|
+
"type": msg.payload?.type || '',
|
|
44
|
+
"token": msg.payload?.token || node.credentials?.token || node.config?.token || '',
|
|
45
|
+
"prm": msg.payload?.prm || node.credentials?.prm || node.config?.prm || '',
|
|
46
|
+
"start": msg.payload?.start || '',
|
|
47
|
+
"end": msg.payload?.end || '',
|
|
48
|
+
"options_retry_limit": msg.payload?.options_retry_limit || 2,
|
|
49
|
+
"options_timeout_lookup": msg.payload?.options_timeout_lookup || 500,
|
|
50
|
+
"options_timeout_connect": msg.payload?.options_timeout_connect || 500,
|
|
51
|
+
"options_timeout_secureconnect": msg.payload?.options_timeout_secureconnect || 500,
|
|
52
|
+
"options_timeout_socket": msg.payload?.options_timeout_socket || 5000,
|
|
53
|
+
"options_timeout_send": msg.payload?.options_timeout_send || 10000,
|
|
54
|
+
"options_timeout_response": msg.payload?.options_timeout_response || 10000,
|
|
55
|
+
"random_delay": msg.payload?.random_delay || 5000,
|
|
56
|
+
"endpoint": msg.payload?.endpoint || 'https://conso.boris.sh/api/'
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
const options = {
|
|
@@ -74,71 +77,60 @@ module.exports = function (RED) {
|
|
|
74
77
|
}
|
|
75
78
|
};
|
|
76
79
|
|
|
80
|
+
_p.type || node.error('api type not set (ex. daily_consumption) see documentation');
|
|
77
81
|
_p.token || node.error('token not set');
|
|
78
82
|
_p.prm || node.error('PRM not set');
|
|
79
83
|
_p.start || node.error('start not set');
|
|
80
84
|
_p.end || node.error('end not set');
|
|
85
|
+
if (_p.type && _p.token && _p.prm && _p.start && _p.end) {
|
|
86
|
+
let wait = Math.floor(Math.random() * _p.random_delay);
|
|
87
|
+
let msg_wait = nodeStatus.WAIT + Math.ceil(wait / 1000) + 's';
|
|
88
|
+
node.status({ fill: 'grey', shape: 'ring', text: msg_wait });
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
node.status({ fill: 'grey', shape: 'ring', text: nodeStatus.FETCH });
|
|
91
|
+
let request = `${_p.endpoint}${_p.type}?prm=${_p.prm}&start=${_p.start}&end=${_p.end}`;
|
|
92
|
+
got(request, options)
|
|
93
|
+
.then(res => {
|
|
94
|
+
if (res.statusCode == '200') {
|
|
95
|
+
try {
|
|
96
|
+
msg.payload = JSON.parse(res.body);
|
|
97
|
+
node.send(msg);
|
|
98
|
+
node.status({ fill: 'blue', shape: 'dot', text: 'OK' });
|
|
81
99
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
node.status({});
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
node.status({});
|
|
102
|
+
if (done) {
|
|
103
|
+
done();
|
|
104
|
+
}
|
|
105
|
+
}, 1000);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
108
|
+
if (done) {
|
|
109
|
+
done('parsing ' + err);
|
|
110
|
+
} else {
|
|
111
|
+
node.error('parsing ' + err, msg);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
node.status({ fill: 'red', shape: 'ring', text: res.statusCode });
|
|
98
116
|
if (done) {
|
|
99
|
-
done();
|
|
117
|
+
done(`statusCode ${res.statusCode}`);
|
|
118
|
+
} else {
|
|
119
|
+
node.error(`statusCode ${res.statusCode}`, msg);
|
|
100
120
|
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.catch(err => {
|
|
103
124
|
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
125
|
+
|
|
104
126
|
if (done) {
|
|
105
|
-
done(
|
|
127
|
+
done(err);
|
|
106
128
|
} else {
|
|
107
|
-
node.error(
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (done) {
|
|
113
|
-
done(`statusCode ${res.statusCode}`);
|
|
114
|
-
} else {
|
|
115
|
-
node.error(`statusCode ${res.statusCode}`, msg);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
.catch(err => {
|
|
120
|
-
if (err instanceof got.HTTPError) {
|
|
121
|
-
node.warn(request);
|
|
122
|
-
if (err.response.statusCode == '400') {
|
|
123
|
-
node.error('Bad request: Check token and PRM or dates format');
|
|
124
|
-
} else if (err.response.statusCode == '401') {
|
|
125
|
-
node.error('Unauthorized: Check token and PRM');
|
|
126
|
-
} else if (err.response.statusCode == '403') {
|
|
127
|
-
node.error('Forbidden: Check token and PRM');
|
|
128
|
-
} else if (err.response.statusCode == '404') {
|
|
129
|
-
node.error('Not found: Check token and PRM or dates values');
|
|
130
|
-
}
|
|
131
|
-
} else if (err instanceof got.TimeoutError) {
|
|
132
|
-
node.warn('TimeoutError: adjust payload.options_timeout_*');
|
|
133
|
-
}
|
|
134
|
-
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
135
|
-
if (done) {
|
|
136
|
-
done(err);
|
|
137
|
-
} else {
|
|
138
|
-
node.error(err, msg);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}, wait);
|
|
129
|
+
node.error(err, msg);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}, wait);
|
|
133
|
+
}
|
|
142
134
|
})
|
|
143
135
|
}
|
|
144
136
|
RED.nodes.registerType("linky-api", LinkyMetering, {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flecoufle/node-red-linky",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Retrieve Linky power consumption",
|
|
5
5
|
"main": "linky/linky.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=14.0.0"
|
|
11
11
|
},
|
|
12
12
|
"contributors": [
|
|
13
13
|
{
|
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
"node-red": {
|
|
22
22
|
"version": ">=0.17.0",
|
|
23
23
|
"nodes": {
|
|
24
|
-
"linky-api": "linky/linky.js"
|
|
24
|
+
"linky-api": "linky/linky.js",
|
|
25
|
+
"linky-api-config": "linky/linky-config.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"linky",
|
|
30
|
+
"api",
|
|
29
31
|
"node-red",
|
|
30
32
|
"power",
|
|
31
33
|
"consumption",
|
|
@@ -38,6 +40,6 @@
|
|
|
38
40
|
},
|
|
39
41
|
"homepage": "https://github.com/flecoufle/node-red-linky#readme",
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"got": "
|
|
43
|
+
"got": "13.0.0"
|
|
42
44
|
}
|
|
43
45
|
}
|