iobroker.ebus 3.6.2 → 3.6.3

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/main.js CHANGED
@@ -1,4 +1,5 @@
1
- /*
1
+ /* eslint-disable prefer-template */
2
+ /*
2
3
  * ebus adapter für iobroker
3
4
  *
4
5
  * Created: 15.09.2016 21:31:28
@@ -7,19 +8,19 @@
7
8
 
8
9
  */
9
10
 
10
- /* jshint -W097 */// jshint strict:false
11
+ /* jshint -W097 */ // jshint strict:false
11
12
  /*jslint node: true */
12
13
  "use strict";
13
14
 
14
-
15
-
16
-
17
15
  const utils = require("@iobroker/adapter-core");
18
- const os = require('os');
19
- const { exec } = require("child_process");
20
- const { spawn } = require("child_process")
21
- const fs = require('fs');
22
- const path = require('path');
16
+ const os = require("os");
17
+ //const { exec } = require("child_process");
18
+ const { spawn } = require("child_process");
19
+ const fs = require("fs");
20
+ const path = require("path");
21
+ const axios = require("axios");
22
+ const net = require("net");
23
+ const { PromiseSocket } = require("promise-socket");
23
24
 
24
25
  const ebusdMinVersion = [25, 1];
25
26
  const ebusdVersion = [0, 0];
@@ -36,16 +37,14 @@ function startAdapter(options) {
36
37
  try {
37
38
  //adapter.log.debug('start');
38
39
  main();
39
- }
40
- catch (e) {
41
- adapter.log.error("exception catch after ready [" + e + "]");
40
+ } catch (e) {
41
+ adapter.log.error(`exception catch after ready [${ e }]`);
42
42
  }
43
43
  },
44
44
  //#######################################
45
45
  // is called when adapter shuts down
46
46
  unload: function (callback) {
47
47
  try {
48
-
49
48
  if (intervalID != null) {
50
49
  clearInterval(intervalID);
51
50
  }
@@ -56,6 +55,7 @@ function startAdapter(options) {
56
55
  //to do stop intervall
57
56
  callback();
58
57
  } catch (e) {
58
+ adapter.log.error(`exception catch after unload [${e}]`);
59
59
  callback();
60
60
  }
61
61
  },
@@ -65,7 +65,7 @@ function startAdapter(options) {
65
65
  },
66
66
  //#######################################
67
67
  //
68
- message: async (obj) => {
68
+ message: async obj => {
69
69
  if (obj) {
70
70
  switch (obj.command) {
71
71
  case "findParams":
@@ -90,11 +90,11 @@ function startAdapter(options) {
90
90
  await CheckVersion("supported", obj);
91
91
  break;
92
92
  default:
93
- adapter.log.error("unknown message " + obj.command);
93
+ adapter.log.error(`unknown message ${ obj.command}`);
94
94
  break;
95
95
  }
96
96
  }
97
- }
97
+ },
98
98
  //#######################################
99
99
  //
100
100
  });
@@ -103,16 +103,10 @@ function startAdapter(options) {
103
103
  return adapter;
104
104
  }
105
105
 
106
-
107
- const axios = require("axios");
108
- const net = require("net");
109
- const { PromiseSocket } = require("promise-socket");
110
-
111
- let intervalID=null;
112
- let updateTimerID=null;
106
+ let intervalID = null;
107
+ let updateTimerID = null;
113
108
 
114
109
  async function main() {
115
-
116
110
  adapter.log.debug("start with interface ebusd ");
117
111
 
118
112
  FillPolledVars();
@@ -127,18 +121,16 @@ async function main() {
127
121
  if (parseInt(adapter.config.readInterval) > 0) {
128
122
  readInterval = adapter.config.readInterval;
129
123
  }
130
- adapter.log.debug("read every " + readInterval + " minutes");
124
+ adapter.log.debug(`read every ${ readInterval } minutes`);
131
125
  intervalID = setInterval(Do, readInterval * 60 * 1000);
132
126
 
133
127
  //read at adapterstart
134
128
  await Do();
135
-
136
129
  }
137
130
 
138
131
  let requestRunning = false;
139
132
 
140
133
  async function DoRequest() {
141
-
142
134
  adapter.log.debug("DoRequest ");
143
135
 
144
136
  if (!requestRunning) {
@@ -146,30 +138,23 @@ async function DoRequest() {
146
138
  await ebusd_ReadValues();
147
139
 
148
140
  await ebusd_ReceiveData();
149
- }
150
- else {
141
+ } else {
151
142
  adapter.log.debug("DoRequest: do nothing already running ");
152
143
  }
153
144
  requestRunning = false;
154
145
  }
155
146
 
156
147
  async function Do() {
157
-
158
- adapter.log.debug("starting ... " );
148
+ adapter.log.debug("starting ... ");
159
149
 
160
150
  await ebusd_Command();
161
151
 
162
152
  await DoRequest();
163
-
164
153
  }
165
154
 
166
-
167
155
  async function HandleStateChange(id, state) {
168
-
169
-
170
156
  if (state != null && state.ack !== true) {
171
-
172
- adapter.log.debug("handle state change " + id);
157
+ adapter.log.debug(`handle state change ${ id}`);
173
158
  const ids = id.split(".");
174
159
 
175
160
  if (ids[2] === "cmd") {
@@ -177,20 +162,16 @@ async function HandleStateChange(id, state) {
177
162
  StartDataRequest();
178
163
  //see issue #77: only one request possible
179
164
  //await Do();
180
- }
181
- //unhandled state change ebus.0.find
182
- else if (ids[2] === "find") {
165
+ } else if (ids[2] === "find") {
166
+ //unhandled state change ebus.0.find
183
167
  await ebusd_find();
184
- }
185
- else {
186
- adapter.log.warn("unhandled state change " + id);
168
+ } else {
169
+ adapter.log.warn(`unhandled state change ${ id}`);
187
170
  }
188
171
  }
189
172
  }
190
173
 
191
-
192
174
  function StartDataRequest() {
193
-
194
175
  if (updateTimerID != null) {
195
176
  //already running
196
177
  clearTimeout(updateTimerID);
@@ -201,7 +182,6 @@ function StartDataRequest() {
201
182
  adapter.log.debug("StartDataRequest");
202
183
  }
203
184
 
204
-
205
185
  async function DataRequest() {
206
186
  adapter.log.debug("get data after command and timeout");
207
187
  if (updateTimerID != null) {
@@ -211,12 +191,14 @@ async function DataRequest() {
211
191
  await DoRequest();
212
192
  }
213
193
 
214
-
215
194
  const oPolledVars = [];
216
195
  function FillPolledVars() {
217
-
218
196
  try {
219
- if (adapter.config.PolledDPs !== undefined && adapter.config.PolledDPs != null && adapter.config.PolledDPs.length > 0) {
197
+ if (
198
+ adapter.config.PolledDPs !== undefined &&
199
+ adapter.config.PolledDPs != null &&
200
+ adapter.config.PolledDPs.length > 0
201
+ ) {
220
202
  adapter.log.debug("use new object list for polled vars");
221
203
 
222
204
  //2023-02-10 only active vars
@@ -225,24 +207,21 @@ function FillPolledVars() {
225
207
  oPolledVars.push(adapter.config.PolledDPs[i]);
226
208
  }
227
209
  }
228
-
229
- }
230
- else {
210
+ } else {
231
211
  //make it compatible to old versions
232
- adapter.log.debug("check old comma separeted list for polled vars " + adapter.config.PolledValues);
212
+ adapter.log.debug(`check old comma separeted list for polled vars ${ adapter.config.PolledValues}`);
233
213
 
234
214
  if (adapter.config.PolledValues !== undefined && typeof adapter.config.PolledValues == "string") {
235
215
  const oPolled = adapter.config.PolledValues.split(",");
236
216
 
237
217
  if (oPolled.length > 0) {
238
-
239
218
  for (let i = 0; i < oPolled.length; i++) {
240
219
  if (oPolled[i].length > 0) {
241
220
  //console.log('add ' + oPolled[i]);
242
221
  const value = {
243
222
  circuit: "",
244
223
  name: oPolled[i],
245
- parameter: ""
224
+ parameter: "",
246
225
  };
247
226
  oPolledVars.push(value);
248
227
  }
@@ -250,33 +229,32 @@ function FillPolledVars() {
250
229
  }
251
230
  }
252
231
  }
232
+ } catch (e) {
233
+ adapter.log.error(`exception in FillPolledVars [${ e }]`);
253
234
  }
254
- catch (e) {
255
- adapter.log.error("exception in FillPolledVars [" + e + "]");
256
- }
257
-
258
- adapter.log.info("list of polled vars " + JSON.stringify(oPolledVars));
259
235
 
236
+ adapter.log.debug(`list of polled vars ${ JSON.stringify(oPolledVars)}`);
260
237
  }
261
238
 
262
239
  let oHistoryVars = [];
263
240
  function FillHistoryVars() {
264
-
265
241
  try {
266
- if (adapter.config.HistoryDPs !== undefined && adapter.config.HistoryDPs != null && adapter.config.HistoryDPs.length > 0) {
242
+ if (
243
+ adapter.config.HistoryDPs !== undefined &&
244
+ adapter.config.HistoryDPs != null &&
245
+ adapter.config.HistoryDPs.length > 0
246
+ ) {
267
247
  adapter.log.debug("use new object list for history vars");
268
248
  oHistoryVars = adapter.config.HistoryDPs;
269
- }
270
- else if (adapter.config.HistoryValues !== undefined && typeof adapter.config.HistoryValues === "string") {
249
+ } else if (adapter.config.HistoryValues !== undefined && typeof adapter.config.HistoryValues === "string") {
271
250
  //make it compatible to old versions
272
251
  adapter.log.debug("check old comma separeted list for history vars");
273
252
  const oHistory = adapter.config.HistoryValues.split(",");
274
253
 
275
254
  if (oHistory.length > 0) {
276
-
277
255
  for (let i = 0; i < oHistory.length; i++) {
278
256
  if (oHistory[i].length > 0) {
279
- console.log("add " + oHistory[i]);
257
+ console.log(`add ${ oHistory[i]}`);
280
258
  const value = {
281
259
  name: oHistory[i],
282
260
  };
@@ -285,26 +263,24 @@ function FillHistoryVars() {
285
263
  }
286
264
  }
287
265
  }
288
- }
289
- catch (e) {
290
- adapter.log.error("exception in function FillHistoryVars [" + e + "]");
266
+ } catch (e) {
267
+ adapter.log.error(`exception in function FillHistoryVars [${ e }]`);
291
268
  }
292
269
  }
293
270
 
294
271
  let oHTTPParamsVars = [];
295
272
  function FillHTTPParamsVars() {
296
- if (adapter.config.HTTPparameter !== undefined && adapter.config.HTTPparameter != null && adapter.config.HTTPparameter.length > 0) {
297
-
273
+ if (
274
+ adapter.config.HTTPparameter !== undefined &&
275
+ adapter.config.HTTPparameter != null &&
276
+ adapter.config.HTTPparameter.length > 0
277
+ ) {
298
278
  oHTTPParamsVars = adapter.config.HTTPparameter;
299
279
 
300
- adapter.log.debug("use optionally HTTP parameter " + JSON.stringify(oHTTPParamsVars));
280
+ adapter.log.debug(`use optionally HTTP parameter ${ JSON.stringify(oHTTPParamsVars)}`);
301
281
  }
302
282
  }
303
283
 
304
-
305
-
306
-
307
-
308
284
  //===================================================================================================
309
285
  // ebusd interface
310
286
 
@@ -314,9 +290,9 @@ async function ebusd_Command() {
314
290
  if (obj !== undefined && obj != null) {
315
291
  const cmds = obj.val;
316
292
  if (cmds !== "") {
317
- adapter.log.debug("got command(s): " + cmds);
293
+ adapter.log.debug(`got command(s): ${ cmds}`);
318
294
 
319
- adapter.log.debug("connect telnet to IP " + adapter.config.targetIP + " port " + parseInt(adapter.config.targetTelnetPort));
295
+ adapter.log.debug(`connect telnet to IP ${ adapter.config.targetIP } port ${ parseInt(adapter.config.targetTelnetPort)}`);
320
296
 
321
297
  try {
322
298
  const socket = new net.Socket();
@@ -331,47 +307,43 @@ async function ebusd_Command() {
331
307
  if (oCmds.length > 0) {
332
308
  let received = "";
333
309
  for (let n = 0; n < oCmds.length; n++) {
334
-
335
- adapter.log.debug("send " + oCmds[n]);
336
- await promiseSocket.write(oCmds[n] + "\n");
310
+ adapter.log.debug(`send ${ oCmds[n]}`);
311
+ await promiseSocket.write(`${oCmds[n] }\n`);
337
312
 
338
313
  const data = await promiseSocket.read();
339
314
 
340
315
  if (data.includes("ERR")) {
341
- adapter.log.warn("sent " + oCmds[n] + ", received " + data + " please check ebusd logs for details!");
342
- }
343
- else {
344
- adapter.log.debug("received " + data);
316
+ adapter.log.warn(`sent ${ oCmds[n] }, received ${ data } please check ebusd logs for details!`);
317
+
318
+ } else {
319
+ adapter.log.debug(`received ${ data}`);
345
320
  }
346
321
  received += data.toString();
347
322
  received += ", ";
348
323
  }
349
324
 
350
325
  //see issue #78: remove CR, LF and last comma
351
- received = received.replace(/\r?\n|\r/g,"");
326
+ received = received.replace(/\r?\n|\r/g, "");
352
327
  received = received.slice(0, -2);
353
328
 
354
- //set result to cmdResult
329
+ //set result to cmdResult
355
330
  await adapter.setStateAsync("cmdResult", { ack: true, val: received });
356
- }
357
- else {
358
- adapter.log.warn("no commands in list " + cmds + " " + JSON.stringify(oCmds));
331
+ } else {
332
+ adapter.log.warn(`no commands in list ${ cmds } ${ JSON.stringify(oCmds)}`);
359
333
  }
360
334
  await adapter.setStateAsync("cmd", { ack: true, val: "" });
361
335
 
362
336
  promiseSocket.destroy();
363
-
364
337
  } catch (e) {
365
- adapter.log.error("exception from tcp socket" + "[" + e + "]");
338
+ adapter.log.error(`exception from tcp socket` + `[${ e }]`);
366
339
  }
367
340
  }
368
- }
369
- else {
370
- adapter.log.debug("object cmd not found " + JSON.stringify(obj));
341
+ } else {
342
+ adapter.log.debug(`object cmd not found ${ JSON.stringify(obj)}`);
371
343
  }
372
344
  }
373
345
 
374
- async function ebusd_find(){
346
+ async function ebusd_find() {
375
347
  try {
376
348
  const socket = new net.Socket();
377
349
  const promiseSocket = new PromiseSocket(socket);
@@ -385,17 +357,15 @@ async function ebusd_find(){
385
357
  const data = await promiseSocket.read();
386
358
 
387
359
  if (data.includes("ERR")) {
388
- adapter.log.warn("received error! sent find, received " + data + " please check ebusd logs for details!");
389
- }
390
- else {
391
- adapter.log.debug("received " + typeof data + " " + data);
360
+ adapter.log.warn(`received error! sent find, received ${ data } please check ebusd logs for details!`);
361
+ } else {
362
+ adapter.log.debug(`received ${ typeof data } ${ data}`);
392
363
  }
393
364
 
394
- const str = new TextDecoder().decode(data);
365
+ const str = new TextDecoder().decode(data);
395
366
  const datas = str.split(/\r?\n/);
396
367
 
397
368
  for (let i = 0; i < datas.length; i++) {
398
-
399
369
  //adapter.log.debug(JSON.stringify(datas[i]));
400
370
 
401
371
  const names = datas[i].split(",");
@@ -403,32 +373,26 @@ async function ebusd_find(){
403
373
  //circuit,name,comment
404
374
  await UpdateDP(names[0], names[1], names[2]);
405
375
 
406
- let cmd = "read -f -c " + names[0] + " " + names[1] ;
376
+ let cmd = `read -f -c ${ names[0] } ${ names[1]}` ;
407
377
 
408
- adapter.log.debug("send cmd " + cmd);
378
+ adapter.log.debug(`send cmd ${ cmd}`);
409
379
 
410
380
  cmd += "\n";
411
381
  await promiseSocket.write(cmd);
412
382
 
413
383
  const result = await promiseSocket.read();
414
384
 
415
- adapter.log.debug("received " + typeof result + " " + result);
385
+ adapter.log.debug(`received ${ typeof result } ${ result}`);
416
386
  }
417
-
418
387
 
419
388
  promiseSocket.destroy();
420
-
421
389
  } catch (e) {
422
- adapter.log.error("exception from tcp socket in ebusd_find" + "[" + e + "]");
390
+ adapter.log.error(`exception from tcp socket in ebusd_find` + `[${ e }]`);
423
391
  }
424
-
425
392
  }
426
393
 
427
-
428
-
429
394
  //just call http://192.168.0.123:8889/data
430
395
 
431
-
432
396
  /*
433
397
  http://localhost:8080/data/mc?verbose&since=1483890000&exact
434
398
 
@@ -452,7 +416,6 @@ async function ebusd_find(){
452
416
 
453
417
  */
454
418
 
455
-
456
419
  async function subscribeVars() {
457
420
  adapter.subscribeStates("cmd");
458
421
 
@@ -462,21 +425,20 @@ async function subscribeVars() {
462
425
  }
463
426
 
464
427
  async function CreateObject(key, obj) {
465
-
466
428
  const obj_new = await adapter.getObjectAsync(key);
467
429
  //adapter.log.warn("got object " + JSON.stringify(obj_new));
468
430
 
469
431
  if (obj_new != null) {
470
-
471
- if ((obj_new.common.role != obj.common.role
472
- || obj_new.common.type != obj.common.type
473
- || (obj_new.common.unit != obj.common.unit && obj.common.unit != null)
474
- || obj_new.common.read != obj.common.read
475
- || obj_new.common.write != obj.common.write
476
- || obj_new.common.name != obj.common.name)
477
- && obj.type === "state"
432
+ if (
433
+ (obj_new.common.role != obj.common.role ||
434
+ obj_new.common.type != obj.common.type ||
435
+ (obj_new.common.unit != obj.common.unit && obj.common.unit != null) ||
436
+ obj_new.common.read != obj.common.read ||
437
+ obj_new.common.write != obj.common.write ||
438
+ obj_new.common.name != obj.common.name) &&
439
+ obj.type === "state"
478
440
  ) {
479
- adapter.log.warn("change object " + JSON.stringify(obj) + " " + JSON.stringify(obj_new));
441
+ adapter.log.warn(`change object ${ JSON.stringify(obj) } ${ JSON.stringify(obj_new)}`);
480
442
  await adapter.extendObject(key, {
481
443
  common: {
482
444
  name: obj.common.name,
@@ -484,61 +446,51 @@ async function CreateObject(key, obj) {
484
446
  type: obj.common.type,
485
447
  unit: obj.common.unit,
486
448
  read: obj.common.read,
487
- write: obj.common.write
488
- }
449
+ write: obj.common.write,
450
+ },
489
451
  });
490
452
  }
491
- }
492
- else {
453
+ } else {
493
454
  await adapter.setObjectNotExistsAsync(key, obj);
494
455
  }
495
456
  }
496
457
 
497
-
498
458
  //circuit,name,comment
499
459
  async function UpdateDP(circuit, name, comment) {
500
-
501
- const key = circuit + ".messages." + name;
502
- adapter.log.debug("update check for " + key);
503
-
460
+ const key = `${circuit }.messages.${ name}`;
461
+ adapter.log.debug(`update check for ${ key}`);
504
462
 
505
463
  // ehp.messages.Injection
506
464
  //ebus.0.ehp.messages.Injection
507
465
 
508
466
  const obj = await adapter.getObjectAsync(key);
509
- adapter.log.debug("update check got " + JSON.stringify(obj));
510
-
467
+ adapter.log.debug(`update check got ${ JSON.stringify(obj)}`);
511
468
 
512
469
  //update check got null
513
470
 
514
471
  if (obj != null) {
515
-
516
472
  if (obj.common.name != comment) {
517
- adapter.log.debug("update " + key + " " + comment);
473
+ adapter.log.debug(`update ${ key } ${ comment}`);
518
474
  await adapter.extendObject(key, {
519
475
  common: {
520
476
  name: comment,
521
477
  read: true,
522
- write: false
523
- }
478
+ write: false,
479
+ },
524
480
  });
525
481
  }
526
- }
527
- else {
482
+ } else {
528
483
  await adapter.setObjectNotExistsAsync(key, {
529
484
  type: "channel",
530
485
  common: {
531
486
  name: comment,
532
487
  read: true,
533
- write: false
534
- }
488
+ write: false,
489
+ },
535
490
  });
536
491
  }
537
-
538
492
  }
539
493
 
540
-
541
-
542
494
  async function checkVariables() {
543
495
  adapter.log.debug("init variables ");
544
496
 
@@ -546,15 +498,15 @@ async function checkVariables() {
546
498
  let obj;
547
499
 
548
500
  key = "cmd";
549
- obj= {
501
+ obj = {
550
502
  type: "state",
551
503
  common: {
552
504
  name: "ebusd command",
553
505
  type: "string",
554
506
  role: "text",
555
507
  read: true,
556
- write: true
557
- }
508
+ write: true,
509
+ },
558
510
  };
559
511
  await CreateObject(key, obj);
560
512
 
@@ -566,8 +518,8 @@ async function checkVariables() {
566
518
  type: "string",
567
519
  role: "text",
568
520
  read: true,
569
- write: false
570
- }
521
+ write: false,
522
+ },
571
523
  };
572
524
  await CreateObject(key, obj);
573
525
 
@@ -579,27 +531,23 @@ async function checkVariables() {
579
531
  type: "boolean",
580
532
  role: "button",
581
533
  read: false,
582
- write: true
583
- }
534
+ write: true,
535
+ },
584
536
  };
585
537
  await CreateObject(key, obj);
586
538
 
539
+ adapter.log.debug(`init common variables and ${ oHistoryVars.length } history DP's`);
587
540
 
588
-
589
- adapter.log.debug("init common variables and " + oHistoryVars.length + " history DP's");
590
-
591
541
  if (oHistoryVars.length > 0) {
592
-
593
542
  if (oHistoryVars.length > 4) {
594
- adapter.log.warn("too many history values " + oHistoryVars.length + " -> maximum is 4");
543
+ adapter.log.warn(`too many history values ${ oHistoryVars.length } -> maximum is 4`);
595
544
  }
596
545
 
597
546
  for (let n = 1; n <= oHistoryVars.length; n++) {
598
-
599
547
  if (oHistoryVars[n - 1].name.length > 0) {
600
- const name = "history value " + n + " as JSON " + oHistoryVars[n - 1].name;
601
- key = "history.value" + n;
602
- obj= {
548
+ const name = `history value ${ n } as JSON ${ oHistoryVars[n - 1].name}`;
549
+ key = `history.value${ n}`;
550
+ obj = {
603
551
  type: "state",
604
552
  common: {
605
553
  name: name,
@@ -607,19 +555,18 @@ async function checkVariables() {
607
555
  role: "value",
608
556
  unit: "",
609
557
  read: true,
610
- write: false
558
+ write: false,
611
559
  },
612
- native: { location: key }
560
+ native: { location: key },
613
561
  };
614
562
  await CreateObject(key, obj);
615
- }
616
- else {
617
- adapter.log.warn("ignoring history value " + n + " (invalid name)");
563
+ } else {
564
+ adapter.log.warn(`ignoring history value ${ n } (invalid name)`);
618
565
  }
619
566
  }
620
567
 
621
568
  key = "history.date";
622
- obj= {
569
+ obj = {
623
570
  type: "state",
624
571
  common: {
625
572
  name: "ebus history date / time as JSON",
@@ -627,16 +574,16 @@ async function checkVariables() {
627
574
  role: "value",
628
575
  unit: "",
629
576
  read: true,
630
- write: false
577
+ write: false,
631
578
  },
632
579
  native: {
633
- location: key
634
- }
580
+ location: key,
581
+ },
635
582
  };
636
583
  await CreateObject(key, obj);
637
584
  }
638
585
  key = "history.error";
639
- obj= {
586
+ obj = {
640
587
  type: "state",
641
588
  common: {
642
589
  name: "ebus error",
@@ -644,32 +591,37 @@ async function checkVariables() {
644
591
  role: "value",
645
592
  unit: "",
646
593
  read: true,
647
- write: false
594
+ write: false,
648
595
  },
649
- native: { location: key }
596
+ native: { location: key },
650
597
  };
651
598
  await CreateObject(key, obj);
652
599
  }
653
600
 
654
-
655
601
  function VersionCheck() {
656
-
657
- if (ebusdVersion[0] > 0 ) {
658
- if (ebusdVersion[0] < ebusdMinVersion[0] || (ebusdVersion[0] == ebusdMinVersion[0] && ebusdVersion[1] < ebusdMinVersion[1])) {
659
- adapter.log.info("please update ebusd, old version found: " + ebusdVersion[0] + "." + ebusdVersion[1] + " supported version is " + ebusdMinVersion[0] + "." + ebusdMinVersion[1]);
602
+ if (ebusdVersion[0] > 0) {
603
+ if (
604
+ ebusdVersion[0] < ebusdMinVersion[0] ||
605
+ (ebusdVersion[0] == ebusdMinVersion[0] && ebusdVersion[1] < ebusdMinVersion[1])
606
+ ) {
607
+ adapter.log.info(`please update ebusd, old version found: ${ ebusdVersion[0] }.${ ebusdVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
660
608
  }
661
- if (ebusdVersion[0] > ebusdMinVersion[0] || (ebusdVersion[0] >= ebusdMinVersion[0] && ebusdVersion[1] > ebusdMinVersion[1])) {
662
- adapter.log.info("unsupported ebusd version found (too new): " + ebusdVersion[0] + "." + ebusdVersion[1] + " supported version is " + ebusdMinVersion[0] + "." + ebusdMinVersion[1]);
609
+ if (
610
+ ebusdVersion[0] > ebusdMinVersion[0] ||
611
+ (ebusdVersion[0] >= ebusdMinVersion[0] && ebusdVersion[1] > ebusdMinVersion[1])
612
+ ) {
613
+ adapter.log.info(`unsupported ebusd version found (too new): ${ ebusdVersion[0] }.${ ebusdVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
663
614
  }
664
615
  }
665
616
 
666
617
  if (ebusdUpdateVersion[0] > 0 && ebusdVersion[0] > 0) {
667
-
668
- if (ebusdUpdateVersion[0] > ebusdVersion[0] || (ebusdUpdateVersion[0] == ebusdVersion[0] && ebusdUpdateVersion[1] > ebusdVersion[1])) {
669
- adapter.log.info("new ebusd version found: " + ebusdUpdateVersion[0] + "." + ebusdUpdateVersion[1] + " supported version is " + ebusdMinVersion[0] + "." + ebusdMinVersion[1]);
618
+ if (
619
+ ebusdUpdateVersion[0] > ebusdVersion[0] ||
620
+ (ebusdUpdateVersion[0] == ebusdVersion[0] && ebusdUpdateVersion[1] > ebusdVersion[1])
621
+ ) {
622
+ adapter.log.info(`new ebusd version found: ${ ebusdUpdateVersion[0] }.${ ebusdUpdateVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
670
623
 
671
624
  }
672
-
673
625
  }
674
626
  }
675
627
 
@@ -677,6 +629,226 @@ function VersionCheck() {
677
629
  //https://github.com/john30/ebusd/wiki/3.2.-HTTP-client
678
630
 
679
631
  async function ebusd_ReceiveData() {
632
+ try {
633
+ let sUrl = `http://${ adapter.config.targetIP }:${ parseInt(adapter.config.targetHTTPPort) }/data`;
634
+
635
+ //Erweiterung mit optionalen parametern
636
+ var paramsCnt = 0;
637
+ if (oHTTPParamsVars !== undefined && oHTTPParamsVars != null && oHTTPParamsVars.length > 0) {
638
+ for (let i = 0; i < oHTTPParamsVars.length; i++) {
639
+ if (oHTTPParamsVars[i].active) {
640
+ if (paramsCnt == 0) {
641
+ sUrl += "?";
642
+ } else {
643
+ sUrl += "&";
644
+ }
645
+ sUrl += `${oHTTPParamsVars[i].name }=${ oHTTPParamsVars[i].value}`;
646
+ paramsCnt++;
647
+ }
648
+ }
649
+ }
650
+
651
+ adapter.log.debug(`request data from ${ sUrl}`);
652
+ const buffer = await axios.get(sUrl);
653
+
654
+ adapter.log.debug(`got data ${ typeof buffer.data } ${ JSON.stringify(buffer.data)}`);
655
+
656
+ const flattenObject = (obj, delimiter = ".", prefix = "") =>
657
+ Object.keys(obj).reduce((acc, k) => {
658
+ const pre = prefix.length ? `${prefix}${delimiter}` : "";
659
+ if (typeof obj[k] === "object" && obj[k] !== null && Object.keys(obj[k]).length > 0) {
660
+ Object.assign(acc, flattenObject(obj[k], delimiter, pre + k));
661
+ } else {
662
+ acc[pre + k] = obj[k];
663
+ }
664
+ return acc;
665
+ }, {});
666
+
667
+ let data = flattenObject(buffer.data, ".");
668
+
669
+ const historyvalues = [];
670
+ const historydates = [];
671
+
672
+ const oToday = new Date();
673
+ const month = oToday.getMonth() + 1;
674
+
675
+ historydates.push({
676
+ date: `${oToday.getDate() }.${ month }.${ oToday.getFullYear()}`,
677
+ time: `${oToday.getHours() }:${ oToday.getMinutes() }:${ oToday.getSeconds()}`
678
+ });
679
+
680
+ let sError = "none";
681
+
682
+ for (let key in data) {
683
+ const subnames = key.split(".");
684
+ //const namelength = subnames.length;
685
+ let value = data[key];
686
+
687
+ //adapter.log.debug("key " + key);
688
+
689
+ if (key.includes("[") || key.includes("]")) {
690
+ adapter.log.debug(`found unsupported chars in ${ key}`);
691
+ const start = key.indexOf("[");
692
+ const end = key.lastIndexOf("]");
693
+
694
+ if (start > 0 && end > 0) {
695
+ const toReplace = key.slice(start, end + 1);
696
+ key = key.replace(toReplace, "");
697
+ }
698
+ //adapter.log.warn("new key is " + key);
699
+ }
700
+
701
+ //======== version check
702
+ if (key.includes("global.version")) {
703
+ //adapter.log.info("in version, value " + value);
704
+ const versionInfo = value.split(".");
705
+ if (versionInfo.length > 1) {
706
+ adapter.log.info(`installed ebusd version is ${ versionInfo[0] }.${ versionInfo[1]}`);
707
+
708
+ ebusdVersion[0] = versionInfo[0];
709
+ ebusdVersion[1] = versionInfo[1];
710
+
711
+ VersionCheck();
712
+ }
713
+ }
714
+
715
+ if (key.includes("global.updatecheck")) {
716
+ //revision v21.2 available
717
+ value = value.replace("revision v", "");
718
+ value = value.replace(" available", "");
719
+
720
+ const versionInfo = value.split(".");
721
+ if (versionInfo.length > 1) {
722
+ adapter.log.info(`found ebusd update version ${ versionInfo[0] }.${ versionInfo[1]}`);
723
+
724
+ ebusdUpdateVersion[0] = versionInfo[0];
725
+ ebusdUpdateVersion[1] = versionInfo[1];
726
+
727
+ VersionCheck();
728
+ }
729
+ }
730
+
731
+ //============ type check
732
+ let type = typeof value;
733
+
734
+ if (adapter.config.useBoolean4Onoff) {
735
+ if (type == "string" && (value == "on" || value == "off")) {
736
+ adapter.log.debug(`Key ${ key } change to boolean ${ value}`);
737
+ //Key mc.messages.Status.fields.1.value could be boolean off
738
+
739
+ type = "boolean";
740
+
741
+ if (value == "on") {
742
+ value = true;
743
+ } else {
744
+ value = false;
745
+ }
746
+ }
747
+ }
748
+
749
+ //EVU Sperrzeit
750
+ if (key.includes(".hcmode2.value") || key.includes(".hcmode.value")) {
751
+ if (parseInt(value) === 0) {
752
+ adapter.log.info(`${key }in hcmode2 with value 0: off`);
753
+ value = "off";
754
+ } else if (parseInt(value) === 5) {
755
+ adapter.log.info(`${key } with value 5: EVU Sperrzeit`);
756
+ value = "EVU Sperrzeit";
757
+ } else {
758
+ adapter.log.debug(`in hcmode2, value ${ value}`);
759
+ }
760
+ type = typeof value;
761
+ }
762
+
763
+ //lastup umrechnen
764
+ if (key.includes(".lastup")) {
765
+ if (parseInt(value) > 0) {
766
+ //adapter.log.debug('Key : ' + key + ', Value : ' + newData[key] + " name " + name);
767
+
768
+ //umrechnen...
769
+ const oDate = new Date(value * 1000);
770
+ //const nDate = oDate.getDate();
771
+ //const nMonth = oDate.getMonth() + 1;
772
+ //const nYear = oDate.getFullYear();
773
+ //const nHours = oDate.getHours();
774
+ //const nMinutes = oDate.getMinutes();
775
+ //const nSeconds = oDate.getSeconds();
776
+
777
+ const sDate = oDate.toLocaleString();
778
+
779
+ value = sDate;
780
+ type = typeof value;
781
+
782
+ const oToday = new Date();
783
+
784
+ let bSkip = false;
785
+
786
+ if (
787
+ subnames[0].includes("scan") ||
788
+ subnames[0].includes("Scan") ||
789
+ subnames[0].includes("ehp") ||
790
+ (subnames.length > 2 && subnames[2].includes("currenterror")) ||
791
+ adapter.config.DisableTimeUpdateCheck
792
+ ) {
793
+ bSkip = true;
794
+ }
795
+
796
+ //adapter.log.debug("_______________size " + temp);
797
+ if (subnames.length > 2 && subnames[2].includes("Timer")) {
798
+ bSkip = true;
799
+ }
800
+
801
+ if (!bSkip && Math.abs(oDate.getTime() - oToday.getTime()) > 1 * 60 * 60 * 1000) {
802
+ const sError1 = `no update since ${ sDate } ${ key } `;
803
+ if (sError.includes("none")) {
804
+ sError = `ebus: ${ sError1}`;
805
+ } else {
806
+ sError += sError1;
807
+ }
808
+ adapter.log.warn(sError1);
809
+ }
810
+ }
811
+ }
812
+
813
+ //add and update data
814
+ await AddObject(key, type);
815
+ await UpdateObject(key, value);
816
+
817
+ //push to history
818
+
819
+ for (let ii = 0; ii < oHistoryVars.length; ii++) {
820
+ if (key === oHistoryVars[ii].name) {
821
+ const sTemp = '{"' + key + '": "' + value + '"}';
822
+ adapter.log.debug("push history " + sTemp);
823
+ historyvalues[ii] = [];
824
+ historyvalues[ii].push(JSON.parse(sTemp));
825
+ //adapter.log.debug(JSON.stringify(historyvalues));
826
+ }
827
+ }
828
+ }
829
+
830
+ await adapter.setStateAsync("history.error", { ack: true, val: sError });
831
+
832
+ //adapter.log.debug(JSON.stringify(historyvalues));
833
+
834
+ adapter.log.info("all http done");
835
+
836
+ if (historyvalues.length > 0 && historydates.length > 0) {
837
+ if (adapter.config.History4Vis2) {
838
+ await UpdateHistory_Vis2(historyvalues, historydates);
839
+ } else {
840
+ await UpdateHistory(historyvalues, historydates);
841
+ }
842
+ }
843
+ } catch (e) {
844
+ adapter.log.error(`exception in ebusd_ReceiveData [${ e }]`);
845
+
846
+ await adapter.setStateAsync("history.error", { ack: true, val: "exception in receive" });
847
+ }
848
+ }
849
+
850
+ /*
851
+ async function ebusd_ReceiveData_old() {
680
852
 
681
853
  let sUrl = "http://" + adapter.config.targetIP + ":" + parseInt(adapter.config.targetHTTPPort) + "/data";
682
854
 
@@ -722,13 +894,11 @@ async function ebusd_ReceiveData() {
722
894
 
723
895
  //adapter.log.debug("000 " + typeof oData + JSON.stringify(oData));
724
896
 
725
- //adapter.log.debug("oData " + oData);
897
+ adapter.log.debug("oData " + oData);
726
898
 
727
- const flatten = require("flat");
899
+ const newData = flatten.flattenDeep(oData);
728
900
 
729
- const newData = flatten(oData);
730
-
731
- //adapter.log.debug("111 " + JSON.stringify(newData));
901
+ adapter.log.debug("111 " + JSON.stringify(newData));
732
902
 
733
903
  const keys = Object.keys(newData);
734
904
 
@@ -925,15 +1095,6 @@ async function ebusd_ReceiveData() {
925
1095
 
926
1096
  if (!bSkip && Math.abs(oDate.getTime() - oToday.getTime()) > 1 * 60 * 60 * 1000) {
927
1097
 
928
-
929
-
930
- /*2024-11-20
931
- ebus: no update since 19.11.2024, 21:11:14 Scan.15.messages.Id.lastup no update since 19.11.2024, 21:11:19 Scan.23.messages.Id.lastup no update since 19.11.2024, 21:10:34 Scan.25.messages.Id.lastup no update since 19.11.2024, 21:12:04 Scan.50.messages.Id.lastup
932
-
933
- */
934
-
935
-
936
-
937
1098
  const sError1 = "no update since " + sDate + " " + key + " ";
938
1099
  if (sError.includes("none")) {
939
1100
  sError = "ebus: " + sError1;
@@ -981,29 +1142,30 @@ async function ebusd_ReceiveData() {
981
1142
  //});
982
1143
  }
983
1144
 
1145
+ */
1146
+
984
1147
  async function UpdateHistory_Vis2(values, dates) {
985
- adapter.log.debug("start history 4 VIS-2 " + JSON.stringify(values) + " " + JSON.stringify(dates));
1148
+ adapter.log.debug(`start history 4 VIS-2 ${ JSON.stringify(values) } ${ JSON.stringify(dates)}`);
986
1149
 
987
1150
  //not used anymore
988
1151
  await adapter.setStateAsync("history.date", { ack: true, val: "" });
989
1152
 
990
1153
  for (let s = 0; s < values.length; s++) {
991
-
992
1154
  const values1 = values[s];
993
1155
  //adapter.log.debug(s + " " + JSON.stringify(values1));
994
1156
 
995
1157
  let val2Write = [];
996
1158
  const ctr = s + 1;
997
1159
 
998
- const obj = await adapter.getStateAsync("history.value" + ctr);
1160
+ const obj = await adapter.getStateAsync(`history.value${ ctr}`);
999
1161
 
1000
1162
  if (obj === null || obj === undefined) {
1001
- adapter.log.warn("history.value" + ctr + " not found, creating DP " + JSON.stringify(obj));
1002
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: "[]" });
1163
+ adapter.log.warn(`history.value${ ctr } not found, creating DP ${ JSON.stringify(obj)}`);
1164
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1003
1165
  }
1004
1166
 
1005
1167
  val2Write = JSON.parse(obj.val);
1006
- adapter.log.debug("history.value" + ctr + " got " + JSON.stringify(val2Write));
1168
+ adapter.log.debug(`history.value${ ctr } got ${ JSON.stringify(val2Write)}`);
1007
1169
 
1008
1170
  for (let ss = 0; ss < values1.length; ss++) {
1009
1171
  const values2 = values1[ss];
@@ -1012,7 +1174,6 @@ async function UpdateHistory_Vis2(values, dates) {
1012
1174
  let d = 0;
1013
1175
 
1014
1176
  for (const n in values2) {
1015
-
1016
1177
  const val = values2[n];
1017
1178
  const time = dates[d]["time"];
1018
1179
  const date = dates[d]["date"];
@@ -1029,35 +1190,23 @@ async function UpdateHistory_Vis2(values, dates) {
1029
1190
 
1030
1191
  const oDate = new Date(year, month, day, hours, minutes, 0, 0);
1031
1192
 
1032
- adapter.log.debug(n + " " + val + " " + oDate.toLocaleString());
1193
+ adapter.log.debug(`${n } ${ val } ${ oDate.toLocaleString()}`);
1033
1194
 
1034
- val2Write.push(
1035
- [
1036
- oDate,
1037
- val
1038
- ]
1039
- );
1195
+ val2Write.push([oDate, val]);
1040
1196
 
1041
1197
  if (val2Write.length > 200) {
1042
-
1043
1198
  for (let i = val2Write.length; i > 200; i--) {
1044
1199
  //adapter.log.debug("delete");
1045
1200
  val2Write.shift();
1046
1201
  }
1047
1202
  }
1048
-
1049
1203
  }
1050
1204
  }
1051
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: JSON.stringify(val2Write) });
1205
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: JSON.stringify(val2Write) });
1052
1206
  }
1053
1207
  }
1054
1208
 
1055
-
1056
-
1057
-
1058
-
1059
1209
  async function UpdateHistory(values, dates) {
1060
-
1061
1210
  if (oHistoryVars.length > 0) {
1062
1211
  //prüfen ob alle json gleich lang sind
1063
1212
  let NoOfDates = -1;
@@ -1071,13 +1220,10 @@ async function UpdateHistory(values, dates) {
1071
1220
  oEbusDates = JSON.parse(obj.val);
1072
1221
  //adapter.log.debug("after parse " + JSON.stringify(oEbusDates));
1073
1222
 
1074
-
1075
-
1076
1223
  oEbusDates.push(dates);
1077
1224
  //adapter.log.debug("after push " + JSON.stringify(oEbusDates));
1078
1225
  //limit length of object...
1079
1226
  if (oEbusDates.length > 200) {
1080
-
1081
1227
  for (let i = oEbusDates.length; i > 200; i--) {
1082
1228
  //adapter.log.debug("delete");
1083
1229
  oEbusDates.shift();
@@ -1085,22 +1231,19 @@ async function UpdateHistory(values, dates) {
1085
1231
  }
1086
1232
  NoOfDates = oEbusDates.length;
1087
1233
  await adapter.setStateAsync("history.date", { ack: true, val: JSON.stringify(oEbusDates) });
1088
- }
1089
- catch (e) {
1090
- adapter.log.error("exception in UpdateHistory part1 [" + e + "]");
1234
+ } catch (e) {
1235
+ adapter.log.error(`exception in UpdateHistory part1 [${ e }]`);
1091
1236
  await adapter.setStateAsync("history.date", { ack: true, val: "[]" });
1092
1237
  NoOfDates = 0;
1093
1238
  }
1094
- }
1095
- else {
1239
+ } else {
1096
1240
  adapter.log.warn("history.date not found, creating DP ");
1097
1241
  await adapter.setStateAsync("history.date", { ack: true, val: "[]" });
1098
1242
  NoOfDates = 0;
1099
1243
  }
1100
-
1244
+
1101
1245
  if (oHistoryVars.length > 0) {
1102
1246
  for (let ctr = 1; ctr <= oHistoryVars.length; ctr++) {
1103
-
1104
1247
  if (oHistoryVars[ctr - 1].name.length > 0) {
1105
1248
  const ctrOkay = await UpdateHistoryValues(values, ctr, NoOfDates);
1106
1249
 
@@ -1109,28 +1252,22 @@ async function UpdateHistory(values, dates) {
1109
1252
  NoOfDates = 0;
1110
1253
  adapter.log.warn("reset history date too");
1111
1254
  }
1112
- }
1113
- else {
1114
- adapter.log.debug("ignoring history value " + ctr);
1255
+ } else {
1256
+ adapter.log.debug(`ignoring history value ${ ctr}`);
1115
1257
  }
1116
1258
  }
1117
1259
 
1118
1260
  adapter.log.info("all history done");
1119
1261
  }
1120
- }
1121
- else {
1262
+ } else {
1122
1263
  adapter.log.debug("nothing to do for history");
1123
1264
  }
1124
1265
  }
1125
1266
 
1126
-
1127
-
1128
1267
  async function UpdateHistoryValues(values, ctr, curDateCtr) {
1129
-
1130
-
1131
1268
  let bRet = true;
1132
1269
 
1133
- const obj = await adapter.getStateAsync("history.value" + ctr);
1270
+ const obj = await adapter.getStateAsync(`history.value${ ctr}`);
1134
1271
 
1135
1272
  if (obj !== undefined && obj != null) {
1136
1273
  try {
@@ -1152,39 +1289,32 @@ async function UpdateHistoryValues(values, ctr, curDateCtr) {
1152
1289
  //adapter.log.debug("after push cnt " + oEbusValues.length);
1153
1290
  //limit length of object...
1154
1291
  if (oEbusValues.length > 200) {
1155
-
1156
1292
  for (let i = oEbusValues.length; i > 200; i--) {
1157
1293
  //adapter.log.debug("delete");
1158
1294
  oEbusValues.shift();
1159
1295
  }
1160
1296
  }
1161
1297
 
1162
- const key = "history.value" + ctr;
1163
- adapter.log.debug("update history " + key);
1298
+ const key = `history.value${ ctr}`;
1299
+ adapter.log.debug(`update history ${ key}`);
1164
1300
 
1165
1301
  if (curDateCtr != oEbusValues.length) {
1166
1302
  bRet = false;
1167
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: "[]" });
1168
- adapter.log.warn("reset history " + key + " because number of values different to date values");
1169
-
1170
- }
1171
- else {
1303
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1304
+ adapter.log.warn(`reset history ${ key } because number of values different to date values`);
1305
+ } else {
1172
1306
  await adapter.setStateAsync(key, { ack: true, val: JSON.stringify(oEbusValues) });
1173
1307
  }
1174
-
1175
-
1176
- }
1177
- catch (e) {
1178
- adapter.log.error("exception in UpdateHistory part2 [" + e + "]");
1179
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: "[]" });
1308
+ } catch (e) {
1309
+ adapter.log.error(`exception in UpdateHistory part2 [${ e }]`);
1310
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1180
1311
  if (curDateCtr > 0) {
1181
1312
  bRet = false;
1182
1313
  }
1183
1314
  }
1184
- }
1185
- else {
1186
- adapter.log.warn("history.value" + ctr + " not found, creating DP " + JSON.stringify(obj));
1187
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: "[]" });
1315
+ } else {
1316
+ adapter.log.warn(`history.value${ ctr } not found, creating DP ${ JSON.stringify(obj)}`);
1317
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1188
1318
  if (curDateCtr > 0) {
1189
1319
  bRet = false;
1190
1320
  }
@@ -1193,8 +1323,6 @@ async function UpdateHistoryValues(values, ctr, curDateCtr) {
1193
1323
  return bRet;
1194
1324
  }
1195
1325
 
1196
-
1197
-
1198
1326
  async function AddObject(key, type) {
1199
1327
  //adapter.log.debug("addObject " + key);
1200
1328
 
@@ -1203,19 +1331,17 @@ async function AddObject(key, type) {
1203
1331
 
1204
1332
  if (obj != null) {
1205
1333
  //adapter.log.debug(" got Object " + JSON.stringify(obj));
1206
- if (obj.common.role != "value"
1207
- || obj.common.type != type) {
1208
- adapter.log.debug(" !!! need to extend for " + key);
1334
+ if (obj.common.role != "value" || obj.common.type != type) {
1335
+ adapter.log.debug(` !!! need to extend for ${ key}`);
1209
1336
  await adapter.extendObject(key, {
1210
1337
  common: {
1211
1338
  type: type,
1212
1339
  role: "value",
1213
- }
1340
+ },
1214
1341
  });
1215
1342
  }
1216
- }
1217
- else {
1218
- adapter.log.warn(" !!! does not exist, creating now " + key );
1343
+ } else {
1344
+ adapter.log.warn(` !!! does not exist, creating now ${ key}` );
1219
1345
 
1220
1346
  await adapter.setObjectNotExistsAsync(key, {
1221
1347
  type: "state",
@@ -1225,38 +1351,34 @@ async function AddObject(key, type) {
1225
1351
  role: "value",
1226
1352
  unit: "",
1227
1353
  read: true,
1228
- write: false
1354
+ write: false,
1229
1355
  },
1230
1356
  native: {
1231
- location: key
1232
- }
1357
+ location: key,
1358
+ },
1233
1359
  });
1234
1360
  }
1235
-
1236
1361
  } catch (e) {
1237
- adapter.log.error("exception in AddObject " + "[" + e + "]");
1362
+ adapter.log.error(`exception in AddObject ` + `[${ e }]`);
1238
1363
  }
1239
1364
  }
1240
1365
 
1241
1366
  async function UpdateObject(key, value) {
1242
1367
  try {
1243
1368
  if (value === undefined) {
1244
- adapter.log.warn("updateObject: not updated " + key + " value: " + value + " " + typeof value);
1245
- }
1246
- else if (value == null ) {
1247
- adapter.log.debug("updateObject: update to null " + key + " value: " + value);
1369
+ adapter.log.warn(`updateObject: not updated ${ key } value: ${ value } ${ typeof value}`);
1370
+ } else if (value == null ) {
1371
+ adapter.log.debug(`updateObject: update to null ${ key } value: ${ value}`);
1248
1372
  await adapter.setStateAsync(key, { ack: true, val: null });
1249
- }
1250
- else {
1251
- adapter.log.debug("updateObject " + key + " : " + value);
1373
+ } else {
1374
+ //adapter.log.debug("updateObject " + key + " : " + value);
1252
1375
  await adapter.setStateAsync(key, { ack: true, val: value });
1253
- }
1376
+ }
1254
1377
  } catch (e) {
1255
- adapter.log.error("exception in UpdateObject " + "[" + e + "]");
1378
+ adapter.log.error(`exception in UpdateObject ` + `[${ e }]`);
1256
1379
  }
1257
1380
  }
1258
1381
 
1259
-
1260
1382
  //telnet client to write to ebusd
1261
1383
  //https://github.com/john30/ebusd/wiki/3.1.-TCP-client-commands
1262
1384
  /*
@@ -1273,37 +1395,33 @@ read -f YieldTotal,read LegioProtectionEnabled,read -f -c broadcast outsidetemp
1273
1395
 
1274
1396
  */
1275
1397
 
1276
-
1277
1398
  //this function just triggers ebusd to read data; result will not be parsed; we just take the values from http result
1278
1399
  //here we need a loop over all configured read data in admin-page
1279
1400
  async function ebusd_ReadValues() {
1280
-
1281
1401
  if (oPolledVars.length > 0) {
1282
-
1283
- adapter.log.debug("to poll ctr " + oPolledVars.length + " vals: " + JSON.stringify(oPolledVars));
1402
+ adapter.log.debug(`to poll ctr ${ oPolledVars.length } vals: ${ JSON.stringify(oPolledVars)}`);
1284
1403
 
1285
1404
  try {
1286
1405
  const socket = new net.Socket();
1287
1406
  const promiseSocket = new PromiseSocket(socket);
1288
1407
 
1289
1408
  await promiseSocket.connect(parseInt(adapter.config.targetTelnetPort), adapter.config.targetIP);
1290
- adapter.log.debug("telnet connected to poll variables " + adapter.config.targetIP + " port " + adapter.config.targetTelnetPort);
1409
+ adapter.log.debug(`telnet connected to poll variables ${ adapter.config.targetIP } port ${ adapter.config.targetTelnetPort}`);
1291
1410
  promiseSocket.setTimeout(5000);
1292
1411
 
1293
1412
  let retries = 0;
1294
1413
  for (let nCtr = 0; nCtr < oPolledVars.length; nCtr++) {
1295
-
1296
1414
  let circuit = "";
1297
1415
  let params = "";
1298
1416
  if (oPolledVars[nCtr].circuit != null && oPolledVars[nCtr].circuit.length > 0) {
1299
- circuit = "-c " + oPolledVars[nCtr].circuit + " ";
1417
+ circuit = `-c ${ oPolledVars[nCtr].circuit } `;
1300
1418
  }
1301
1419
  if (oPolledVars[nCtr].parameter != null && oPolledVars[nCtr].parameter.length > 0) {
1302
- params = " " + oPolledVars[nCtr].parameter;
1420
+ params = ` ${ oPolledVars[nCtr].parameter}`;
1303
1421
  }
1304
- let cmd = "read -f " + circuit + oPolledVars[nCtr].name + params;
1422
+ let cmd = `read -f ${ circuit }${oPolledVars[nCtr].name }${params}`;
1305
1423
 
1306
- adapter.log.debug("send cmd " + cmd);
1424
+ adapter.log.debug(`send cmd ${ cmd}`);
1307
1425
 
1308
1426
  cmd += "\n";
1309
1427
  await promiseSocket.write(cmd);
@@ -1312,56 +1430,44 @@ async function ebusd_ReadValues() {
1312
1430
 
1313
1431
  //received ERR: arbitration lost for YieldThisYear
1314
1432
  if (data.includes("ERR")) {
1315
- adapter.log.warn("sent " + cmd + ", received " + data + " for " + JSON.stringify(oPolledVars[nCtr]) + " please check ebusd logs for details!");
1433
+ adapter.log.warn(`sent ${ cmd }, received ${ data } for ${ JSON.stringify(oPolledVars[nCtr]) } please check ebusd logs for details!`);
1316
1434
 
1317
1435
  /*
1318
- * sent read -f YieldLastYear, received ERR: arbitration lost for {"circuit":"","name":"YieldLastYear","parameter":""}
1319
- * */
1436
+ * sent read -f YieldLastYear, received ERR: arbitration lost for {"circuit":"","name":"YieldLastYear","parameter":""}
1437
+ * */
1320
1438
  if (data.includes("arbitration lost")) {
1321
-
1322
1439
  retries++;
1323
1440
  if (retries > adapter.config.maxretries) {
1324
- adapter.log.error("max retries, skip cmd " + cmd);
1441
+ adapter.log.error(`max retries, skip cmd ${ cmd}`);
1325
1442
  retries = 0;
1326
- }
1327
- else {
1443
+ } else {
1328
1444
  nCtr--;
1329
1445
  adapter.log.debug("retry to send data ");
1330
1446
  }
1331
1447
  }
1332
- }
1333
- else {
1334
- adapter.log.debug("received " + data + " for " + JSON.stringify(oPolledVars[nCtr]));
1448
+ } else {
1449
+ adapter.log.debug(`received ${ data } for ${ JSON.stringify(oPolledVars[nCtr])}`);
1335
1450
  }
1336
1451
  }
1337
1452
  promiseSocket.destroy();
1338
1453
  adapter.log.debug("telnet disonnected");
1339
-
1340
1454
  } catch (e) {
1341
- adapter.log.error("exception from tcp socket in ebusd_ReadValues " + "[" + e + "]");
1455
+ adapter.log.error(`exception from tcp socket in ebusd_ReadValues ` + `[${ e }]`);
1342
1456
  }
1343
-
1344
-
1345
- }
1346
- else {
1457
+ } else {
1347
1458
  adapter.log.debug("nothing to poll; skip telnet");
1348
1459
  }
1349
-
1350
1460
  }
1351
1461
 
1352
-
1353
1462
  async function FindParams(obj) {
1354
-
1355
- adapter.log.debug("FindParams " + JSON.stringify(obj) + " " + JSON.stringify(obj.message) + " " + JSON.stringify(obj.message.circuit));
1463
+ adapter.log.debug(`FindParams ${ JSON.stringify(obj) } ${ JSON.stringify(obj.message) } ${ JSON.stringify(obj.message.circuit)}`);
1356
1464
 
1357
1465
  const list = [];
1358
-
1359
1466
 
1360
1467
  try {
1361
1468
  //FindParams {"command":"findParams","message":{"circuit":"cc"},"from":"system.adapter.admin.0","callback":{"message":{"circuit":"cc"},"id":90,"ack":false,"time":1733690088670},"_id":39690903}
1362
1469
 
1363
1470
  if (obj.message != null) {
1364
-
1365
1471
  const circuit = obj.message.circuit;
1366
1472
 
1367
1473
  const socket = new net.Socket();
@@ -1371,16 +1477,16 @@ async function FindParams(obj) {
1371
1477
  adapter.log.debug("telnet connected for cmd");
1372
1478
  promiseSocket.setTimeout(5000);
1373
1479
 
1374
- const cmd = "find -c " + circuit + " -F circuit,name\n";
1480
+ const cmd = `find -c ${ circuit } -F circuit,name\n`;
1375
1481
  await promiseSocket.write(cmd);
1376
1482
 
1377
1483
  const data = await promiseSocket.read();
1378
1484
 
1379
1485
  if (data.includes("ERR")) {
1380
- adapter.log.warn("received error! sent find, received " + data + " please check ebusd logs for details! " + cmd);
1381
- }
1382
- else {
1383
- adapter.log.debug("received " + typeof data + " " + data + " " + + cmd);
1486
+ adapter.log.warn(`received error! sent find, received ${ data } please check ebusd logs for details! ${ cmd}`);
1487
+
1488
+ } else {
1489
+ adapter.log.debug(`received ${ typeof data } ${ data } ${ + cmd}`);
1384
1490
  }
1385
1491
  /*
1386
1492
  received object ehp,AccelerationTestModeehp,AccelerationTestModeehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerPercentageehp,ActualEnvironmentPowerPercentageehp,ApplianceCodeehp,ApplianceCodeehp,Backupehp,Backupehp,BackupHoursehp,BackupHoursHcehp,BackupHoursHwcehp,BackupHysteresisehp,BackupIntegralehp,BackupModeHcehp,BackupModeHwcehp,BackupPowerCutehp,BackupStartsehp,BackupStartsHcehp,BackupStartsHwcehp,BackupTypeehp,BivalentTempehp,Bleedingehp,Bleedingehp,CirPumpehp,CirPumpehp,Code1ehp,Code1Code2Validehp,Code2ehp,Compehp,Compehp,CompControlStateehp,CompCutPressHighCountehp,CompCutPressLowCountehp,CompCutTempCountehp,CompDemandehp,CompHoursehp,CompHoursHcehp,CompHoursHwcehp,CompHysteresisehp,CompIntegralehp,CompPressHighehp,CompPressHighehp,CompPressLowehp,CompPressLowehp,CompStartsehp,CompStartsHcehp,CompStartsHwcehp,CompStateehp,CondensorTempehp,CondensorTempehp,currenterrorehp,Dateehp,DateTimeehp,DeltaTempT6T7ehp,ElectricWiringDiagramehp,ElectricWiringDiagramehp,EnergyBalancingReleaseehp,errorhistoryehp,FlowTempehp,FlowTempehp,FlowtempCoolingMinehp,FlowTempOffsetehp,Hc1Pumpehp,Hc1Pumpehp,Hc1PumpHoursehp,Hc1PumpPortehp,Hc1PumpStartsehp,Hc2Pumpehp,Hc2PumpHoursehp,HcFlowTempehp,HcFlowTempOffsetehp,HcModeDemandHoursehp,HcModeFulfilledHoursehp,HcParallelStorageFillingEnabledehp,HcPressehp,HcReturnTempehp,HcReturnTempehp,HcReturnTempOffsetehp,HeatPumpStatusehp,HeatPumpStatusehp,HeatpumpTypeehp,HwcHcValveehp,HwcHcValveehp,HwcHcValveStartsehp,HwcLaggingTimeehp,HwcLoadingDelayehp,HwcModeDemandHoursehp,HwcModeFulfilledHoursehp,HwcPumpStartsehp,HwcSwitchehp,HwcTempehp,HwcTempehp,HwcTempOffsetehp,HydraulicSchemeehp,ICLOutehp,ICLOutehp,Injectionehp,Integralehp,Mixer1DutyCycleehp,NumberCompStartsehp,OutsideTempehp,OutsideTempOffsetehp,OverpressureThresholdehp,PhaseOrderehp,PhaseOrderehp,PhaseStatusehp,PhaseStatusehp,PowerCutehp,PowerCutPreloadingehp,PressSwitchehp,PressSwitchehp,RebootCounterehp,ReturnTempMaxehp,SetModeehp,SoftwareCodeehp,Source2PumpHoursehp,Sourceehp,Sourceehp,SourceHoursehp,SourcePortehp,SourcePressehp,SourcePumpPrerunTimeehp,SourceStartsehp,SourceSwitchehp,SourceSwitchehp,SourceTempInputehp,SourceTempInputehp,SourceTempInputOffsetehp,SourceTempOutputehp,SourceTempOutputehp,SourceTempOutputOffsetehp,SourceTempOutputT8Minehp,StateSoftwareCodeehp,StateSoftwareCodeehp,Status01ehp,Status02ehp,Status16ehp,Statusehp,StatusCirPumpehp,StorageTempBottomehp,StorageTempBottomehp,StorageTempBottomOffsetehp,StorageTempTopehp,StorageTempTopehp,StorageTempTopOffsetehp,Subcoolingehp,Superheatehp,T19MaxToCompOffehp,TempInputehp,TempInputehp,TempInputOffsetehp,TempOutputehp,TempOutputehp,TempOutputOffsetehp,Timeehp,TimeBetweenTwoCompStartsMinehp,TimeCompOffMinehp,TimeCompOnMinehp,TimeOfNextPredictedPowerCutehp,TimeOfNextPredictedPowerCutehp,Weekdayehp,YieldTotalehp,YieldTotal
@@ -1389,7 +1495,6 @@ async function FindParams(obj) {
1389
1495
  const datas = str.split(/\r?\n/);
1390
1496
 
1391
1497
  for (let i = 0; i < datas.length; i++) {
1392
-
1393
1498
  //adapter.log.debug(JSON.stringify(datas[i]));
1394
1499
 
1395
1500
  const names = datas[i].split(",");
@@ -1399,11 +1504,9 @@ async function FindParams(obj) {
1399
1504
 
1400
1505
  if (names[0] == "" || names[1] == "") {
1401
1506
  add = false;
1402
- }
1403
- else {
1507
+ } else {
1404
1508
 
1405
1509
  for (let n = 0; n < list.length; n++) {
1406
-
1407
1510
  if (list[n].circuit == names[0] && list[n].name == names[1]) {
1408
1511
  add = false;
1409
1512
  //already in list
@@ -1415,27 +1518,24 @@ async function FindParams(obj) {
1415
1518
  const entry = {
1416
1519
  active: false,
1417
1520
  circuit: names[0],
1418
- name: names[1]
1521
+ name: names[1],
1419
1522
  };
1420
1523
 
1421
1524
  list.push(entry);
1422
1525
  }
1423
1526
  }
1424
- }
1425
- else {
1527
+ } else {
1426
1528
  adapter.log.error("no circuit defined where to look for parameter, check values!");
1427
1529
  }
1428
1530
  } catch (e) {
1429
- adapter.log.error("exception in FindParams " + "[" + e + "]");
1531
+ adapter.log.error(`exception in FindParams ` + `[${ e }]`);
1430
1532
  }
1431
1533
 
1432
- adapter.log.info("parameters " + JSON.stringify(list));
1433
-
1534
+ adapter.log.info(`parameters ${ JSON.stringify(list)}`);
1434
1535
 
1435
1536
  adapter.sendTo(obj.from, obj.command, list, obj.callback);
1436
1537
  }
1437
1538
 
1438
-
1439
1539
  async function CallExternalScript(script, msg) {
1440
1540
 
1441
1541
 
@@ -1456,7 +1556,7 @@ async function CallExternalScript(script, msg) {
1456
1556
  adapter.sendTo(msg.from, msg.command, { error: 'script folder not found ' + folderName }, msg.callback);
1457
1557
  return;
1458
1558
  }
1459
- else {
1559
+
1460
1560
 
1461
1561
  adapter.log.info("folder exists " + folderName);
1462
1562
 
@@ -1471,8 +1571,7 @@ async function CallExternalScript(script, msg) {
1471
1571
 
1472
1572
  return;
1473
1573
 
1474
- }
1475
- else {
1574
+ } else {
1476
1575
 
1477
1576
  adapter.log.info("file exists " + scriptfile);
1478
1577
 
@@ -1498,9 +1597,8 @@ async function CallExternalScript(script, msg) {
1498
1597
  }, msg.callback);
1499
1598
  });
1500
1599
  }
1501
- }
1502
- }
1503
- else {
1600
+
1601
+ } else {
1504
1602
  adapter.sendTo(msg.from, msg.command, { error: 'possible only on Linux systems, this system is ' + os.platform() }, msg.callback);
1505
1603
  }
1506
1604
  } catch (e) {
@@ -1546,17 +1644,44 @@ async function CallExternalScript(script, msg) {
1546
1644
  }
1547
1645
 
1548
1646
  async function CheckVersion(version, msg) {
1549
-
1550
1647
  if (version == "installable") {
1551
- adapter.sendTo(msg.from, msg.command, ebusdUpdateVersion[0] + "." + ebusdUpdateVersion[1], msg.callback);
1552
- }
1553
- else if (version == "current") {
1554
- adapter.sendTo(msg.from, msg.command, ebusdVersion[0] + "." + ebusdVersion[1], msg.callback);
1555
- }
1556
- else if (version == "supported") {
1557
- adapter.sendTo(msg.from, msg.command, ebusdMinVersion[0] + "." + ebusdMinVersion[1], msg.callback);
1648
+ let version = "unknown";
1649
+
1650
+ if (ebusdUpdateVersion[0] > 0 && ebusdVersion[0] > 0) {
1651
+ version = `${ebusdUpdateVersion[0] }.${ ebusdUpdateVersion[1]}`
1652
+ } else {
1653
+ version = await GetLatestVersionGithub();
1654
+ }
1655
+ adapter.sendTo(msg.from, msg.command, version, msg.callback);
1656
+ } else if (version == "current") {
1657
+ adapter.sendTo(msg.from, msg.command, `${ebusdVersion[0] }.${ ebusdVersion[1]}`, msg.callback);
1658
+ } else if (version == "supported") {
1659
+ adapter.sendTo(msg.from, msg.command, `${ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`, msg.callback);
1558
1660
  }
1661
+ }
1662
+
1663
+ async function GetLatestVersionGithub() {
1664
+ let latestVersion = "unknown";
1665
+
1666
+ try {
1667
+ const url = "https://api.github.com/repos/john30/ebusd/releases/latest";
1668
+ adapter.log.debug(`call ${ url}`);
1669
+
1670
+ let result = await axios.get(url, { timeout: 5000 });
1559
1671
 
1672
+ if (result != null && result.status == 200 && result.data != null) {
1673
+ adapter.log.info(`installable version on github ${ JSON.stringify(result.data.tag_name) } (${ JSON.stringify(result.data.name) })`);
1674
+
1675
+ latestVersion =
1676
+ "on github " + JSON.stringify(result.data.tag_name) + "(" + JSON.stringify(result.data.name) + ")";
1677
+ } else {
1678
+ latestVersion = "unknown / no result";
1679
+ }
1680
+ } catch (e) {
1681
+ adapter.log.error(`exception in GetLatestVersionGithub [${ e }]`);
1682
+ latestVersion = "unknown / error";
1683
+ }
1684
+ return latestVersion;
1560
1685
  }
1561
1686
 
1562
1687
  // If started as allInOne/compact mode => return function to create instance
@@ -1565,4 +1690,4 @@ if (module && module.parent) {
1565
1690
  } else {
1566
1691
  // or start the instance directly
1567
1692
  startAdapter();
1568
- }
1693
+ }