@flecoufle/node-red-linky 1.1.0 → 1.3.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 +12 -0
- package/linky/linky-config.html +32 -0
- package/linky/linky-config.js +14 -0
- package/linky/linky.html +23 -17
- package/linky/linky.js +89 -74
- package/package.json +5 -3
package/CHANGELOG.md
ADDED
|
@@ -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
|
|
|
@@ -111,7 +116,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
111
116
|
"options_timeout_send": got option in ms(default 1000)
|
|
112
117
|
"options_timeout_response": got option in ms(default 1000)
|
|
113
118
|
"random_delay": fetch after a random delay in ms (default 5000)
|
|
114
|
-
"endpoint": endpoint api (default "https://conso.boris.sh/api/)
|
|
119
|
+
"endpoint": endpoint api (default "https://conso.boris.sh/api/")
|
|
120
|
+
"debug": debug mode (default false)
|
|
115
121
|
</code></pre></p>
|
|
116
122
|
Available types are: <code>"daily_consumption"</code>, <code>"consumption_load_curve"</code>, <code>"consumption_max_power"</code> in consumption<br/>
|
|
117
123
|
<code>"daily_production"</code>, <code>"production_load_curve"</code> in production
|
|
@@ -150,4 +156,4 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
150
156
|
|
|
151
157
|
<h3>References</h3>
|
|
152
158
|
<ul><li>Node repository <a href="https://github.com/flecoufle/node-red-contrib-linky">flecoufle/node-red-contrib-linky</a></li></ul>
|
|
153
|
-
</script>
|
|
159
|
+
</script>
|
package/linky/linky.js
CHANGED
|
@@ -35,22 +35,26 @@ module.exports = async 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/',
|
|
57
|
+
"debug": msg.payload?.debug === true || msg.payload?.debug == "true"
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
const options = {
|
|
@@ -74,71 +78,82 @@ module.exports = async function (RED) {
|
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
|
|
77
|
-
_p.
|
|
78
|
-
_p.
|
|
79
|
-
_p.
|
|
80
|
-
_p.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
node.status({ fill: 'grey', shape: 'ring', text:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
!_p.type ? (done ? done('api type not set (ex. daily_consumption) see documentation') : node.error('api type not set (ex. daily_consumption) see documentation')) : null;
|
|
82
|
+
!_p.token ? (done ? done('token not set') : node.error('token not set')) : null;
|
|
83
|
+
!_p.prm ? (done ? done('PRM not set') : node.error('PRM not set')) : null;
|
|
84
|
+
!_p.start ? (done ? done('start not set') : node.error('start not set')) : null;
|
|
85
|
+
!_p.end ? (done ? done('end not set') : node.error('end not set')) : null;
|
|
86
|
+
|
|
87
|
+
if (_p.type && _p.token && _p.prm && _p.start && _p.end) {
|
|
88
|
+
let wait = Math.floor(Math.random() * _p.random_delay);
|
|
89
|
+
let msg_wait = nodeStatus.WAIT + Math.ceil(wait / 1000) + 's';
|
|
90
|
+
node.status({ fill: 'grey', shape: 'ring', text: msg_wait });
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
node.status({ fill: 'grey', shape: 'ring', text: nodeStatus.FETCH });
|
|
93
|
+
let request;
|
|
94
|
+
try {
|
|
95
|
+
let url = new URL(_p.endpoint);
|
|
96
|
+
url.pathname += _p.type;
|
|
97
|
+
url.search = new URLSearchParams({
|
|
98
|
+
prm: _p.prm,
|
|
99
|
+
start: _p.start,
|
|
100
|
+
end: _p.end
|
|
101
|
+
}).toString();
|
|
102
|
+
request = url.toString();
|
|
103
|
+
} catch (err) {
|
|
104
|
+
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
105
|
+
if (done) {
|
|
106
|
+
done('url ' + err);
|
|
107
|
+
} else {
|
|
108
|
+
node.error('url ' + err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_p.debug && request && node.warn('Request URL:' + request);
|
|
113
|
+
_p.debug && options && node.warn('Options:' + JSON.stringify(options));
|
|
114
|
+
|
|
115
|
+
request && options && got(request, options)
|
|
116
|
+
.then(res => {
|
|
117
|
+
if (res.statusCode == '200') {
|
|
118
|
+
try {
|
|
119
|
+
msg.payload = JSON.parse(res.body);
|
|
120
|
+
node.send(msg);
|
|
121
|
+
node.status({ fill: 'blue', shape: 'dot', text: 'OK' });
|
|
122
|
+
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
node.status({});
|
|
125
|
+
if (done) {
|
|
126
|
+
done();
|
|
127
|
+
}
|
|
128
|
+
}, 1000);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
131
|
+
if (done) {
|
|
132
|
+
done('parsing ' + err);
|
|
133
|
+
} else {
|
|
134
|
+
node.error('parsing ' + err, msg);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
node.status({ fill: 'red', shape: 'ring', text: res.statusCode });
|
|
98
139
|
if (done) {
|
|
99
|
-
done();
|
|
140
|
+
done(`statusCode ${res.statusCode}`);
|
|
141
|
+
} else {
|
|
142
|
+
node.error(`statusCode ${res.statusCode}`, msg);
|
|
100
143
|
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
.catch(err => {
|
|
103
147
|
node.status({ fill: 'red', shape: 'ring', text: 'error' });
|
|
148
|
+
|
|
104
149
|
if (done) {
|
|
105
|
-
done(
|
|
150
|
+
done(err);
|
|
106
151
|
} 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);
|
|
152
|
+
node.error(err, msg);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}, wait);
|
|
156
|
+
}
|
|
142
157
|
})
|
|
143
158
|
}
|
|
144
159
|
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.3.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",
|