@flecoufle/node-red-linky 1.2.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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.3.0 - 20250321
2
+ add debug option
3
+
1
4
  ## 1.2.0 - 20240705
2
5
  add config node
3
6
  fix error handler
package/linky/linky.html CHANGED
@@ -116,7 +116,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
116
116
  "options_timeout_send": got option in ms(default 1000)
117
117
  "options_timeout_response": got option in ms(default 1000)
118
118
  "random_delay": fetch after a random delay in ms (default 5000)
119
- "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)
120
121
  </code></pre></p>
121
122
  Available types are: <code>"daily_consumption"</code>, <code>"consumption_load_curve"</code>, <code>"consumption_max_power"</code> in consumption<br/>
122
123
  <code>"daily_production"</code>, <code>"production_load_curve"</code> in production
package/linky/linky.js CHANGED
@@ -53,7 +53,8 @@ module.exports = async function (RED) {
53
53
  "options_timeout_send": msg.payload?.options_timeout_send || 10000,
54
54
  "options_timeout_response": msg.payload?.options_timeout_response || 10000,
55
55
  "random_delay": msg.payload?.random_delay || 5000,
56
- "endpoint": msg.payload?.endpoint || 'https://conso.boris.sh/api/'
56
+ "endpoint": msg.payload?.endpoint || 'https://conso.boris.sh/api/',
57
+ "debug": msg.payload?.debug === true || msg.payload?.debug == "true"
57
58
  }
58
59
 
59
60
  const options = {
@@ -77,19 +78,41 @@ module.exports = async function (RED) {
77
78
  }
78
79
  };
79
80
 
80
- _p.type || node.error('api type not set (ex. daily_consumption) see documentation');
81
- _p.token || node.error('token not set');
82
- _p.prm || node.error('PRM not set');
83
- _p.start || node.error('start not set');
84
- _p.end || node.error('end not set');
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
+
85
87
  if (_p.type && _p.token && _p.prm && _p.start && _p.end) {
86
88
  let wait = Math.floor(Math.random() * _p.random_delay);
87
89
  let msg_wait = nodeStatus.WAIT + Math.ceil(wait / 1000) + 's';
88
90
  node.status({ fill: 'grey', shape: 'ring', text: msg_wait });
89
91
  setTimeout(() => {
90
92
  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
+ 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)
93
116
  .then(res => {
94
117
  if (res.statusCode == '200') {
95
118
  try {
@@ -122,7 +145,7 @@ module.exports = async function (RED) {
122
145
  })
123
146
  .catch(err => {
124
147
  node.status({ fill: 'red', shape: 'ring', text: 'error' });
125
-
148
+
126
149
  if (done) {
127
150
  done(err);
128
151
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flecoufle/node-red-linky",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Retrieve Linky power consumption",
5
5
  "main": "linky/linky.js",
6
6
  "publishConfig": {