iobroker.ebus 3.6.2 → 3.6.6

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,25 +1,26 @@
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
5
6
  * Author: Rene
6
-
7
+ *
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
  }
253
- }
254
- catch (e) {
255
- adapter.log.error("exception in FillPolledVars [" + e + "]");
232
+ } catch (e) {
233
+ adapter.log.error(`exception in FillPolledVars [${ e }]`);
256
234
  }
257
235
 
258
- adapter.log.info("list of polled vars " + JSON.stringify(oPolledVars));
259
-
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,53 @@ function FillHistoryVars() {
285
263
  }
286
264
  }
287
265
  }
266
+ } catch (e) {
267
+ adapter.log.error(`exception in function FillHistoryVars [${e}]`);
288
268
  }
289
- catch (e) {
290
- adapter.log.error("exception in function FillHistoryVars [" + e + "]");
291
- }
269
+
270
+ adapter.log.debug(`list of history vars ${JSON.stringify(oHistoryVars)}`);
271
+
272
+ //add a check, that complete dp without ebus.0 is used 2025-08-20
273
+
274
+ oHistoryVars.forEach((entry, index) => {
275
+ const hasDot = entry.name.includes(".");
276
+ const hasInstance = entry.name.includes("ebus.");
277
+ const hasValue = entry.name.includes("value");
278
+
279
+ adapter.log.debug("checking " + entry.name + " index " + index + " hasDot: " + hasDot + " hasInstance: " + hasInstance + " hasValue: " + hasValue);
280
+
281
+
282
+ if (!hasDot) {
283
+ adapter.log.warn("please check history variable: " + entry.name + " -> should contain the complete DP");
284
+ }
285
+
286
+ if (!hasValue) {
287
+ adapter.log.warn("please check history variable " + entry.name + " -> should contain 'value'");
288
+ }
289
+
290
+ if (hasInstance) {
291
+ adapter.log.warn("please check history variable " + entry.name + " -> should not contain instance name and instance number e.g. 'ebus.0' ");
292
+ }
293
+
294
+ });
295
+
296
+ //list of history vars [{"name":"ActualEnvironmentPower"},{"name":"YieldTotal"},{"name":"SourceTempInput"},{"name":"SourceTempOutput"},{"name":"HwcTemp"}]
297
+
292
298
  }
293
299
 
294
300
  let oHTTPParamsVars = [];
295
301
  function FillHTTPParamsVars() {
296
- if (adapter.config.HTTPparameter !== undefined && adapter.config.HTTPparameter != null && adapter.config.HTTPparameter.length > 0) {
297
-
302
+ if (
303
+ adapter.config.HTTPparameter !== undefined &&
304
+ adapter.config.HTTPparameter != null &&
305
+ adapter.config.HTTPparameter.length > 0
306
+ ) {
298
307
  oHTTPParamsVars = adapter.config.HTTPparameter;
299
308
 
300
- adapter.log.debug("use optionally HTTP parameter " + JSON.stringify(oHTTPParamsVars));
309
+ adapter.log.debug(`use optionally HTTP parameter ${ JSON.stringify(oHTTPParamsVars)}`);
301
310
  }
302
311
  }
303
312
 
304
-
305
-
306
-
307
-
308
313
  //===================================================================================================
309
314
  // ebusd interface
310
315
 
@@ -314,9 +319,9 @@ async function ebusd_Command() {
314
319
  if (obj !== undefined && obj != null) {
315
320
  const cmds = obj.val;
316
321
  if (cmds !== "") {
317
- adapter.log.debug("got command(s): " + cmds);
322
+ adapter.log.debug(`got command(s): ${ cmds}`);
318
323
 
319
- adapter.log.debug("connect telnet to IP " + adapter.config.targetIP + " port " + parseInt(adapter.config.targetTelnetPort));
324
+ adapter.log.debug(`connect telnet to IP ${ adapter.config.targetIP } port ${ parseInt(adapter.config.targetTelnetPort)}`);
320
325
 
321
326
  try {
322
327
  const socket = new net.Socket();
@@ -331,47 +336,43 @@ async function ebusd_Command() {
331
336
  if (oCmds.length > 0) {
332
337
  let received = "";
333
338
  for (let n = 0; n < oCmds.length; n++) {
334
-
335
- adapter.log.debug("send " + oCmds[n]);
336
- await promiseSocket.write(oCmds[n] + "\n");
339
+ adapter.log.debug(`send ${ oCmds[n]}`);
340
+ await promiseSocket.write(`${oCmds[n] }\n`);
337
341
 
338
342
  const data = await promiseSocket.read();
339
343
 
340
344
  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);
345
+ adapter.log.warn(`sent ${ oCmds[n] }, received ${ data } please check ebusd logs for details!`);
346
+
347
+ } else {
348
+ adapter.log.debug(`received ${ data}`);
345
349
  }
346
350
  received += data.toString();
347
351
  received += ", ";
348
352
  }
349
353
 
350
354
  //see issue #78: remove CR, LF and last comma
351
- received = received.replace(/\r?\n|\r/g,"");
355
+ received = received.replace(/\r?\n|\r/g, "");
352
356
  received = received.slice(0, -2);
353
357
 
354
- //set result to cmdResult
358
+ //set result to cmdResult
355
359
  await adapter.setStateAsync("cmdResult", { ack: true, val: received });
356
- }
357
- else {
358
- adapter.log.warn("no commands in list " + cmds + " " + JSON.stringify(oCmds));
360
+ } else {
361
+ adapter.log.warn(`no commands in list ${ cmds } ${ JSON.stringify(oCmds)}`);
359
362
  }
360
363
  await adapter.setStateAsync("cmd", { ack: true, val: "" });
361
364
 
362
365
  promiseSocket.destroy();
363
-
364
366
  } catch (e) {
365
- adapter.log.error("exception from tcp socket" + "[" + e + "]");
367
+ adapter.log.error(`exception from tcp socket` + `[${ e }]`);
366
368
  }
367
369
  }
368
- }
369
- else {
370
- adapter.log.debug("object cmd not found " + JSON.stringify(obj));
370
+ } else {
371
+ adapter.log.debug(`object cmd not found ${ JSON.stringify(obj)}`);
371
372
  }
372
373
  }
373
374
 
374
- async function ebusd_find(){
375
+ async function ebusd_find() {
375
376
  try {
376
377
  const socket = new net.Socket();
377
378
  const promiseSocket = new PromiseSocket(socket);
@@ -385,17 +386,15 @@ async function ebusd_find(){
385
386
  const data = await promiseSocket.read();
386
387
 
387
388
  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);
389
+ adapter.log.warn(`received error! sent find, received ${ data } please check ebusd logs for details!`);
390
+ } else {
391
+ adapter.log.debug(`received ${ typeof data } ${ data}`);
392
392
  }
393
393
 
394
- const str = new TextDecoder().decode(data);
394
+ const str = new TextDecoder().decode(data);
395
395
  const datas = str.split(/\r?\n/);
396
396
 
397
397
  for (let i = 0; i < datas.length; i++) {
398
-
399
398
  //adapter.log.debug(JSON.stringify(datas[i]));
400
399
 
401
400
  const names = datas[i].split(",");
@@ -403,32 +402,26 @@ async function ebusd_find(){
403
402
  //circuit,name,comment
404
403
  await UpdateDP(names[0], names[1], names[2]);
405
404
 
406
- let cmd = "read -f -c " + names[0] + " " + names[1] ;
405
+ let cmd = `read -f -c ${ names[0] } ${ names[1]}` ;
407
406
 
408
- adapter.log.debug("send cmd " + cmd);
407
+ adapter.log.debug(`send cmd ${ cmd}`);
409
408
 
410
409
  cmd += "\n";
411
410
  await promiseSocket.write(cmd);
412
411
 
413
412
  const result = await promiseSocket.read();
414
413
 
415
- adapter.log.debug("received " + typeof result + " " + result);
414
+ adapter.log.debug(`received ${ typeof result } ${ result}`);
416
415
  }
417
-
418
416
 
419
417
  promiseSocket.destroy();
420
-
421
418
  } catch (e) {
422
- adapter.log.error("exception from tcp socket in ebusd_find" + "[" + e + "]");
419
+ adapter.log.error(`exception from tcp socket in ebusd_find` + `[${ e }]`);
423
420
  }
424
-
425
421
  }
426
422
 
427
-
428
-
429
423
  //just call http://192.168.0.123:8889/data
430
424
 
431
-
432
425
  /*
433
426
  http://localhost:8080/data/mc?verbose&since=1483890000&exact
434
427
 
@@ -452,7 +445,6 @@ async function ebusd_find(){
452
445
 
453
446
  */
454
447
 
455
-
456
448
  async function subscribeVars() {
457
449
  adapter.subscribeStates("cmd");
458
450
 
@@ -462,21 +454,20 @@ async function subscribeVars() {
462
454
  }
463
455
 
464
456
  async function CreateObject(key, obj) {
465
-
466
457
  const obj_new = await adapter.getObjectAsync(key);
467
458
  //adapter.log.warn("got object " + JSON.stringify(obj_new));
468
459
 
469
460
  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"
461
+ if (
462
+ (obj_new.common.role != obj.common.role ||
463
+ obj_new.common.type != obj.common.type ||
464
+ (obj_new.common.unit != obj.common.unit && obj.common.unit != null) ||
465
+ obj_new.common.read != obj.common.read ||
466
+ obj_new.common.write != obj.common.write ||
467
+ obj_new.common.name != obj.common.name) &&
468
+ obj.type === "state"
478
469
  ) {
479
- adapter.log.warn("change object " + JSON.stringify(obj) + " " + JSON.stringify(obj_new));
470
+ adapter.log.warn(`change object ${ JSON.stringify(obj) } ${ JSON.stringify(obj_new)}`);
480
471
  await adapter.extendObject(key, {
481
472
  common: {
482
473
  name: obj.common.name,
@@ -484,61 +475,51 @@ async function CreateObject(key, obj) {
484
475
  type: obj.common.type,
485
476
  unit: obj.common.unit,
486
477
  read: obj.common.read,
487
- write: obj.common.write
488
- }
478
+ write: obj.common.write,
479
+ },
489
480
  });
490
481
  }
491
- }
492
- else {
482
+ } else {
493
483
  await adapter.setObjectNotExistsAsync(key, obj);
494
484
  }
495
485
  }
496
486
 
497
-
498
487
  //circuit,name,comment
499
488
  async function UpdateDP(circuit, name, comment) {
500
-
501
- const key = circuit + ".messages." + name;
502
- adapter.log.debug("update check for " + key);
503
-
489
+ const key = `${circuit }.messages.${ name}`;
490
+ adapter.log.debug(`update check for ${ key}`);
504
491
 
505
492
  // ehp.messages.Injection
506
493
  //ebus.0.ehp.messages.Injection
507
494
 
508
495
  const obj = await adapter.getObjectAsync(key);
509
- adapter.log.debug("update check got " + JSON.stringify(obj));
510
-
496
+ adapter.log.debug(`update check got ${ JSON.stringify(obj)}`);
511
497
 
512
498
  //update check got null
513
499
 
514
500
  if (obj != null) {
515
-
516
501
  if (obj.common.name != comment) {
517
- adapter.log.debug("update " + key + " " + comment);
502
+ adapter.log.debug(`update ${ key } ${ comment}`);
518
503
  await adapter.extendObject(key, {
519
504
  common: {
520
505
  name: comment,
521
506
  read: true,
522
- write: false
523
- }
507
+ write: false,
508
+ },
524
509
  });
525
510
  }
526
- }
527
- else {
511
+ } else {
528
512
  await adapter.setObjectNotExistsAsync(key, {
529
513
  type: "channel",
530
514
  common: {
531
515
  name: comment,
532
516
  read: true,
533
- write: false
534
- }
517
+ write: false,
518
+ },
535
519
  });
536
520
  }
537
-
538
521
  }
539
522
 
540
-
541
-
542
523
  async function checkVariables() {
543
524
  adapter.log.debug("init variables ");
544
525
 
@@ -546,15 +527,15 @@ async function checkVariables() {
546
527
  let obj;
547
528
 
548
529
  key = "cmd";
549
- obj= {
530
+ obj = {
550
531
  type: "state",
551
532
  common: {
552
533
  name: "ebusd command",
553
534
  type: "string",
554
535
  role: "text",
555
536
  read: true,
556
- write: true
557
- }
537
+ write: true,
538
+ },
558
539
  };
559
540
  await CreateObject(key, obj);
560
541
 
@@ -566,8 +547,8 @@ async function checkVariables() {
566
547
  type: "string",
567
548
  role: "text",
568
549
  read: true,
569
- write: false
570
- }
550
+ write: false,
551
+ },
571
552
  };
572
553
  await CreateObject(key, obj);
573
554
 
@@ -579,27 +560,23 @@ async function checkVariables() {
579
560
  type: "boolean",
580
561
  role: "button",
581
562
  read: false,
582
- write: true
583
- }
563
+ write: true,
564
+ },
584
565
  };
585
566
  await CreateObject(key, obj);
586
567
 
568
+ adapter.log.debug(`init common variables and ${ oHistoryVars.length } history DP's`);
587
569
 
588
-
589
- adapter.log.debug("init common variables and " + oHistoryVars.length + " history DP's");
590
-
591
570
  if (oHistoryVars.length > 0) {
592
-
593
571
  if (oHistoryVars.length > 4) {
594
- adapter.log.warn("too many history values " + oHistoryVars.length + " -> maximum is 4");
572
+ adapter.log.warn(`too many history values ${ oHistoryVars.length } -> maximum is 4`);
595
573
  }
596
574
 
597
575
  for (let n = 1; n <= oHistoryVars.length; n++) {
598
-
599
576
  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= {
577
+ const name = `history value ${ n } as JSON ${ oHistoryVars[n - 1].name}`;
578
+ key = `history.value${ n}`;
579
+ obj = {
603
580
  type: "state",
604
581
  common: {
605
582
  name: name,
@@ -607,19 +584,18 @@ async function checkVariables() {
607
584
  role: "value",
608
585
  unit: "",
609
586
  read: true,
610
- write: false
587
+ write: false,
611
588
  },
612
- native: { location: key }
589
+ native: { location: key },
613
590
  };
614
591
  await CreateObject(key, obj);
615
- }
616
- else {
617
- adapter.log.warn("ignoring history value " + n + " (invalid name)");
592
+ } else {
593
+ adapter.log.warn(`ignoring history value ${ n } (invalid name)`);
618
594
  }
619
595
  }
620
596
 
621
597
  key = "history.date";
622
- obj= {
598
+ obj = {
623
599
  type: "state",
624
600
  common: {
625
601
  name: "ebus history date / time as JSON",
@@ -627,16 +603,16 @@ async function checkVariables() {
627
603
  role: "value",
628
604
  unit: "",
629
605
  read: true,
630
- write: false
606
+ write: false,
631
607
  },
632
608
  native: {
633
- location: key
634
- }
609
+ location: key,
610
+ },
635
611
  };
636
612
  await CreateObject(key, obj);
637
613
  }
638
614
  key = "history.error";
639
- obj= {
615
+ obj = {
640
616
  type: "state",
641
617
  common: {
642
618
  name: "ebus error",
@@ -644,32 +620,37 @@ async function checkVariables() {
644
620
  role: "value",
645
621
  unit: "",
646
622
  read: true,
647
- write: false
623
+ write: false,
648
624
  },
649
- native: { location: key }
625
+ native: { location: key },
650
626
  };
651
627
  await CreateObject(key, obj);
652
628
  }
653
629
 
654
-
655
630
  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]);
631
+ if (ebusdVersion[0] > 0) {
632
+ if (
633
+ ebusdVersion[0] < ebusdMinVersion[0] ||
634
+ (ebusdVersion[0] == ebusdMinVersion[0] && ebusdVersion[1] < ebusdMinVersion[1])
635
+ ) {
636
+ adapter.log.info(`please update ebusd, old version found: ${ ebusdVersion[0] }.${ ebusdVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
660
637
  }
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]);
638
+ if (
639
+ ebusdVersion[0] > ebusdMinVersion[0] ||
640
+ (ebusdVersion[0] >= ebusdMinVersion[0] && ebusdVersion[1] > ebusdMinVersion[1])
641
+ ) {
642
+ adapter.log.info(`unsupported ebusd version found (too new): ${ ebusdVersion[0] }.${ ebusdVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
663
643
  }
664
644
  }
665
645
 
666
646
  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]);
647
+ if (
648
+ ebusdUpdateVersion[0] > ebusdVersion[0] ||
649
+ (ebusdUpdateVersion[0] == ebusdVersion[0] && ebusdUpdateVersion[1] > ebusdVersion[1])
650
+ ) {
651
+ adapter.log.info(`new ebusd version found: ${ ebusdUpdateVersion[0] }.${ ebusdUpdateVersion[1] } supported version is ${ ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`);
670
652
 
671
653
  }
672
-
673
654
  }
674
655
  }
675
656
 
@@ -677,6 +658,240 @@ function VersionCheck() {
677
658
  //https://github.com/john30/ebusd/wiki/3.2.-HTTP-client
678
659
 
679
660
  async function ebusd_ReceiveData() {
661
+ try {
662
+ let sUrl = `http://${ adapter.config.targetIP }:${ parseInt(adapter.config.targetHTTPPort) }/data`;
663
+
664
+ //Erweiterung mit optionalen parametern
665
+ var paramsCnt = 0;
666
+ if (oHTTPParamsVars !== undefined && oHTTPParamsVars != null && oHTTPParamsVars.length > 0) {
667
+ for (let i = 0; i < oHTTPParamsVars.length; i++) {
668
+ if (oHTTPParamsVars[i].active) {
669
+ if (paramsCnt == 0) {
670
+ sUrl += "?";
671
+ } else {
672
+ sUrl += "&";
673
+ }
674
+ sUrl += `${oHTTPParamsVars[i].name }=${ oHTTPParamsVars[i].value}`;
675
+ paramsCnt++;
676
+ }
677
+ }
678
+ }
679
+
680
+ adapter.log.debug(`request data from ${ sUrl}`);
681
+ const buffer = await axios.get(sUrl);
682
+
683
+ adapter.log.debug(`got data ${ typeof buffer.data } ${ JSON.stringify(buffer.data)}`);
684
+
685
+ const flattenObject = (obj, delimiter = ".", prefix = "") =>
686
+ Object.keys(obj).reduce((acc, k) => {
687
+ const pre = prefix.length ? `${prefix}${delimiter}` : "";
688
+ if (typeof obj[k] === "object" && obj[k] !== null && Object.keys(obj[k]).length > 0) {
689
+ Object.assign(acc, flattenObject(obj[k], delimiter, pre + k));
690
+ } else {
691
+ acc[pre + k] = obj[k];
692
+ }
693
+ return acc;
694
+ }, {});
695
+
696
+ let data = flattenObject(buffer.data, ".");
697
+
698
+ const historyvalues = [];
699
+ const historydates = [];
700
+
701
+ const oToday = new Date();
702
+ const month = oToday.getMonth() + 1;
703
+
704
+ historydates.push({
705
+ date: `${oToday.getDate() }.${ month }.${ oToday.getFullYear()}`,
706
+ time: `${oToday.getHours() }:${ oToday.getMinutes() }:${ oToday.getSeconds()}`
707
+ });
708
+
709
+ let sError = "none";
710
+
711
+ for (let key in data) {
712
+ const subnames = key.split(".");
713
+ //const namelength = subnames.length;
714
+ let value = data[key];
715
+
716
+ //adapter.log.debug("key " + key);
717
+
718
+ if (key.includes("[") || key.includes("]")) {
719
+ adapter.log.debug(`found unsupported chars in ${ key}`);
720
+ const start = key.indexOf("[");
721
+ const end = key.lastIndexOf("]");
722
+
723
+ if (start > 0 && end > 0) {
724
+ const toReplace = key.slice(start, end + 1);
725
+ key = key.replace(toReplace, "");
726
+ }
727
+ //adapter.log.warn("new key is " + key);
728
+ }
729
+
730
+ //======== version check
731
+ if (key.includes("global.version")) {
732
+ //adapter.log.info("in version, value " + value);
733
+ const versionInfo = value.split(".");
734
+ if (versionInfo.length > 1) {
735
+ adapter.log.debug(`installed ebusd version is ${ versionInfo[0] }.${ versionInfo[1]}`);
736
+
737
+ ebusdVersion[0] = versionInfo[0];
738
+ ebusdVersion[1] = versionInfo[1];
739
+
740
+ VersionCheck();
741
+ }
742
+ }
743
+
744
+ if (key.includes("global.updatecheck")) {
745
+ //revision v21.2 available
746
+ value = value.replace("revision v", "");
747
+ value = value.replace(" available", "");
748
+
749
+ const versionInfo = value.split(".");
750
+ if (versionInfo.length > 1) {
751
+ adapter.log.info(`found ebusd update version ${ versionInfo[0] }.${ versionInfo[1]}`);
752
+
753
+ ebusdUpdateVersion[0] = versionInfo[0];
754
+ ebusdUpdateVersion[1] = versionInfo[1];
755
+
756
+ VersionCheck();
757
+ }
758
+ }
759
+
760
+ //============ type check
761
+ let type = typeof value;
762
+
763
+ if (adapter.config.useBoolean4Onoff) {
764
+ if (type == "string" && (value == "on" || value == "off")) {
765
+ adapter.log.debug(`Key ${ key } change to boolean ${ value}`);
766
+ //Key mc.messages.Status.fields.1.value could be boolean off
767
+
768
+ type = "boolean";
769
+
770
+ if (value == "on") {
771
+ value = true;
772
+ } else {
773
+ value = false;
774
+ }
775
+ }
776
+ }
777
+
778
+ //EVU Sperrzeit
779
+ if (key.includes(".hcmode2.value") || key.includes(".hcmode.value")) {
780
+ if (parseInt(value) === 0) {
781
+ adapter.log.info(`${key }in hcmode2 with value 0: off`);
782
+ value = "off";
783
+ } else if (parseInt(value) === 5) {
784
+ adapter.log.info(`${key } with value 5: EVU Sperrzeit`);
785
+ value = "EVU Sperrzeit";
786
+ } else {
787
+ adapter.log.debug(`in hcmode2, value ${ value}`);
788
+ }
789
+ type = typeof value;
790
+ }
791
+
792
+ //lastup umrechnen
793
+ if (key.includes(".lastup")) {
794
+ if (parseInt(value) > 0) {
795
+ //adapter.log.debug('Key : ' + key + ', Value : ' + newData[key] + " name " + name);
796
+
797
+ //umrechnen...
798
+ const oDate = new Date(value * 1000);
799
+ //const nDate = oDate.getDate();
800
+ //const nMonth = oDate.getMonth() + 1;
801
+ //const nYear = oDate.getFullYear();
802
+ //const nHours = oDate.getHours();
803
+ //const nMinutes = oDate.getMinutes();
804
+ //const nSeconds = oDate.getSeconds();
805
+
806
+ const sDate = oDate.toLocaleString();
807
+
808
+ value = sDate;
809
+ type = typeof value;
810
+
811
+ const oToday = new Date();
812
+
813
+ let bSkip = false;
814
+
815
+ if (
816
+ subnames[0].includes("scan") ||
817
+ subnames[0].includes("Scan") ||
818
+ subnames[0].includes("ehp") ||
819
+ (subnames.length > 2 && subnames[2].includes("currenterror")) ||
820
+ adapter.config.DisableTimeUpdateCheck
821
+ ) {
822
+ bSkip = true;
823
+ }
824
+
825
+ //adapter.log.debug("_______________size " + temp);
826
+ if (subnames.length > 2 && subnames[2].includes("Timer")) {
827
+ bSkip = true;
828
+ }
829
+
830
+ if (!bSkip && Math.abs(oDate.getTime() - oToday.getTime()) > 1 * 60 * 60 * 1000) {
831
+ const sError1 = `no update since ${ sDate } ${ key } `;
832
+ if (sError.includes("none")) {
833
+ sError = `ebus: ${ sError1}`;
834
+ } else {
835
+ sError += sError1;
836
+ }
837
+ adapter.log.warn(sError1);
838
+ }
839
+ }
840
+ }
841
+
842
+ //add and update data
843
+ await AddObject(key, type);
844
+ await UpdateObject(key, value);
845
+
846
+ //push to history
847
+
848
+ for (let ii = 0; ii < oHistoryVars.length; ii++) {
849
+
850
+ //adapter.log.debug("check " + key + "==" + oHistoryVars[ii].name);
851
+
852
+ // check uih.messages.YieldThisYear.fields.energy_1.value==ActualEnvironmentPower
853
+
854
+ /*
855
+ ehp.messages.ActualEnvironmentPower.fields.value.value
856
+ ehp.messages.YieldTotal.fields.value.value
857
+ ehp.messages.SourceTempInput.fields.temp.value
858
+ ehp.messages.SourceTempOutput.fields.temp.value
859
+ ehp.messages.HwcTemp.fields.temp.value
860
+ */
861
+
862
+
863
+ if (key === oHistoryVars[ii].name) {
864
+ const sTemp = '{"' + key + '": "' + value + '"}';
865
+ adapter.log.debug("push history " + sTemp);
866
+ historyvalues[ii] = [];
867
+ historyvalues[ii].push(JSON.parse(sTemp));
868
+ //adapter.log.debug(JSON.stringify(historyvalues));
869
+ }
870
+ }
871
+ }
872
+
873
+ await adapter.setStateAsync("history.error", { ack: true, val: sError });
874
+
875
+ //adapter.log.debug(JSON.stringify(historyvalues));
876
+
877
+ adapter.log.debug("all http done");
878
+
879
+ if (historyvalues.length > 0 && historydates.length > 0) {
880
+ if (adapter.config.History4Vis2) {
881
+ await UpdateHistory_Vis2(historyvalues, historydates);
882
+ } else {
883
+ await UpdateHistory(historyvalues, historydates);
884
+ }
885
+ }
886
+ } catch (e) {
887
+ adapter.log.error(`exception in ebusd_ReceiveData [${ e }]`);
888
+
889
+ await adapter.setStateAsync("history.error", { ack: true, val: "exception in receive" });
890
+ }
891
+ }
892
+
893
+ /*
894
+ async function ebusd_ReceiveData_old() {
680
895
 
681
896
  let sUrl = "http://" + adapter.config.targetIP + ":" + parseInt(adapter.config.targetHTTPPort) + "/data";
682
897
 
@@ -722,13 +937,11 @@ async function ebusd_ReceiveData() {
722
937
 
723
938
  //adapter.log.debug("000 " + typeof oData + JSON.stringify(oData));
724
939
 
725
- //adapter.log.debug("oData " + oData);
940
+ adapter.log.debug("oData " + oData);
726
941
 
727
- const flatten = require("flat");
942
+ const newData = flatten.flattenDeep(oData);
728
943
 
729
- const newData = flatten(oData);
730
-
731
- //adapter.log.debug("111 " + JSON.stringify(newData));
944
+ adapter.log.debug("111 " + JSON.stringify(newData));
732
945
 
733
946
  const keys = Object.keys(newData);
734
947
 
@@ -925,15 +1138,6 @@ async function ebusd_ReceiveData() {
925
1138
 
926
1139
  if (!bSkip && Math.abs(oDate.getTime() - oToday.getTime()) > 1 * 60 * 60 * 1000) {
927
1140
 
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
1141
  const sError1 = "no update since " + sDate + " " + key + " ";
938
1142
  if (sError.includes("none")) {
939
1143
  sError = "ebus: " + sError1;
@@ -981,29 +1185,30 @@ async function ebusd_ReceiveData() {
981
1185
  //});
982
1186
  }
983
1187
 
1188
+ */
1189
+
984
1190
  async function UpdateHistory_Vis2(values, dates) {
985
- adapter.log.debug("start history 4 VIS-2 " + JSON.stringify(values) + " " + JSON.stringify(dates));
1191
+ adapter.log.debug(`start history 4 VIS-2 ${ JSON.stringify(values) } ${ JSON.stringify(dates)}`);
986
1192
 
987
1193
  //not used anymore
988
1194
  await adapter.setStateAsync("history.date", { ack: true, val: "" });
989
1195
 
990
1196
  for (let s = 0; s < values.length; s++) {
991
-
992
1197
  const values1 = values[s];
993
1198
  //adapter.log.debug(s + " " + JSON.stringify(values1));
994
1199
 
995
1200
  let val2Write = [];
996
1201
  const ctr = s + 1;
997
1202
 
998
- const obj = await adapter.getStateAsync("history.value" + ctr);
1203
+ const obj = await adapter.getStateAsync(`history.value${ ctr}`);
999
1204
 
1000
1205
  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: "[]" });
1206
+ adapter.log.warn(`history.value${ ctr } not found, creating DP ${ JSON.stringify(obj)}`);
1207
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1003
1208
  }
1004
1209
 
1005
1210
  val2Write = JSON.parse(obj.val);
1006
- adapter.log.debug("history.value" + ctr + " got " + JSON.stringify(val2Write));
1211
+ adapter.log.debug(`history.value${ ctr } got ${ JSON.stringify(val2Write)}`);
1007
1212
 
1008
1213
  for (let ss = 0; ss < values1.length; ss++) {
1009
1214
  const values2 = values1[ss];
@@ -1012,7 +1217,6 @@ async function UpdateHistory_Vis2(values, dates) {
1012
1217
  let d = 0;
1013
1218
 
1014
1219
  for (const n in values2) {
1015
-
1016
1220
  const val = values2[n];
1017
1221
  const time = dates[d]["time"];
1018
1222
  const date = dates[d]["date"];
@@ -1029,35 +1233,23 @@ async function UpdateHistory_Vis2(values, dates) {
1029
1233
 
1030
1234
  const oDate = new Date(year, month, day, hours, minutes, 0, 0);
1031
1235
 
1032
- adapter.log.debug(n + " " + val + " " + oDate.toLocaleString());
1236
+ adapter.log.debug(`${n } ${ val } ${ oDate.toLocaleString()}`);
1033
1237
 
1034
- val2Write.push(
1035
- [
1036
- oDate,
1037
- val
1038
- ]
1039
- );
1238
+ val2Write.push([oDate, val]);
1040
1239
 
1041
1240
  if (val2Write.length > 200) {
1042
-
1043
1241
  for (let i = val2Write.length; i > 200; i--) {
1044
1242
  //adapter.log.debug("delete");
1045
1243
  val2Write.shift();
1046
1244
  }
1047
1245
  }
1048
-
1049
1246
  }
1050
1247
  }
1051
- await adapter.setStateAsync("history.value" + ctr, { ack: true, val: JSON.stringify(val2Write) });
1248
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: JSON.stringify(val2Write) });
1052
1249
  }
1053
1250
  }
1054
1251
 
1055
-
1056
-
1057
-
1058
-
1059
1252
  async function UpdateHistory(values, dates) {
1060
-
1061
1253
  if (oHistoryVars.length > 0) {
1062
1254
  //prüfen ob alle json gleich lang sind
1063
1255
  let NoOfDates = -1;
@@ -1071,13 +1263,10 @@ async function UpdateHistory(values, dates) {
1071
1263
  oEbusDates = JSON.parse(obj.val);
1072
1264
  //adapter.log.debug("after parse " + JSON.stringify(oEbusDates));
1073
1265
 
1074
-
1075
-
1076
1266
  oEbusDates.push(dates);
1077
1267
  //adapter.log.debug("after push " + JSON.stringify(oEbusDates));
1078
1268
  //limit length of object...
1079
1269
  if (oEbusDates.length > 200) {
1080
-
1081
1270
  for (let i = oEbusDates.length; i > 200; i--) {
1082
1271
  //adapter.log.debug("delete");
1083
1272
  oEbusDates.shift();
@@ -1085,22 +1274,19 @@ async function UpdateHistory(values, dates) {
1085
1274
  }
1086
1275
  NoOfDates = oEbusDates.length;
1087
1276
  await adapter.setStateAsync("history.date", { ack: true, val: JSON.stringify(oEbusDates) });
1088
- }
1089
- catch (e) {
1090
- adapter.log.error("exception in UpdateHistory part1 [" + e + "]");
1277
+ } catch (e) {
1278
+ adapter.log.error(`exception in UpdateHistory part1 [${ e }]`);
1091
1279
  await adapter.setStateAsync("history.date", { ack: true, val: "[]" });
1092
1280
  NoOfDates = 0;
1093
1281
  }
1094
- }
1095
- else {
1282
+ } else {
1096
1283
  adapter.log.warn("history.date not found, creating DP ");
1097
1284
  await adapter.setStateAsync("history.date", { ack: true, val: "[]" });
1098
1285
  NoOfDates = 0;
1099
1286
  }
1100
-
1287
+
1101
1288
  if (oHistoryVars.length > 0) {
1102
1289
  for (let ctr = 1; ctr <= oHistoryVars.length; ctr++) {
1103
-
1104
1290
  if (oHistoryVars[ctr - 1].name.length > 0) {
1105
1291
  const ctrOkay = await UpdateHistoryValues(values, ctr, NoOfDates);
1106
1292
 
@@ -1109,28 +1295,22 @@ async function UpdateHistory(values, dates) {
1109
1295
  NoOfDates = 0;
1110
1296
  adapter.log.warn("reset history date too");
1111
1297
  }
1112
- }
1113
- else {
1114
- adapter.log.debug("ignoring history value " + ctr);
1298
+ } else {
1299
+ adapter.log.debug(`ignoring history value ${ ctr}`);
1115
1300
  }
1116
1301
  }
1117
1302
 
1118
1303
  adapter.log.info("all history done");
1119
1304
  }
1120
- }
1121
- else {
1305
+ } else {
1122
1306
  adapter.log.debug("nothing to do for history");
1123
1307
  }
1124
1308
  }
1125
1309
 
1126
-
1127
-
1128
1310
  async function UpdateHistoryValues(values, ctr, curDateCtr) {
1129
-
1130
-
1131
1311
  let bRet = true;
1132
1312
 
1133
- const obj = await adapter.getStateAsync("history.value" + ctr);
1313
+ const obj = await adapter.getStateAsync(`history.value${ ctr}`);
1134
1314
 
1135
1315
  if (obj !== undefined && obj != null) {
1136
1316
  try {
@@ -1152,39 +1332,32 @@ async function UpdateHistoryValues(values, ctr, curDateCtr) {
1152
1332
  //adapter.log.debug("after push cnt " + oEbusValues.length);
1153
1333
  //limit length of object...
1154
1334
  if (oEbusValues.length > 200) {
1155
-
1156
1335
  for (let i = oEbusValues.length; i > 200; i--) {
1157
1336
  //adapter.log.debug("delete");
1158
1337
  oEbusValues.shift();
1159
1338
  }
1160
1339
  }
1161
1340
 
1162
- const key = "history.value" + ctr;
1163
- adapter.log.debug("update history " + key);
1341
+ const key = `history.value${ ctr}`;
1342
+ adapter.log.debug(`update history ${ key}`);
1164
1343
 
1165
1344
  if (curDateCtr != oEbusValues.length) {
1166
1345
  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 {
1346
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1347
+ adapter.log.warn(`reset history ${ key } because number of values different to date values`);
1348
+ } else {
1172
1349
  await adapter.setStateAsync(key, { ack: true, val: JSON.stringify(oEbusValues) });
1173
1350
  }
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: "[]" });
1351
+ } catch (e) {
1352
+ adapter.log.error(`exception in UpdateHistory part2 [${ e }]`);
1353
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1180
1354
  if (curDateCtr > 0) {
1181
1355
  bRet = false;
1182
1356
  }
1183
1357
  }
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: "[]" });
1358
+ } else {
1359
+ adapter.log.warn(`history.value${ ctr } not found, creating DP ${ JSON.stringify(obj)}`);
1360
+ await adapter.setStateAsync(`history.value${ ctr}`, { ack: true, val: "[]" });
1188
1361
  if (curDateCtr > 0) {
1189
1362
  bRet = false;
1190
1363
  }
@@ -1193,8 +1366,6 @@ async function UpdateHistoryValues(values, ctr, curDateCtr) {
1193
1366
  return bRet;
1194
1367
  }
1195
1368
 
1196
-
1197
-
1198
1369
  async function AddObject(key, type) {
1199
1370
  //adapter.log.debug("addObject " + key);
1200
1371
 
@@ -1203,19 +1374,17 @@ async function AddObject(key, type) {
1203
1374
 
1204
1375
  if (obj != null) {
1205
1376
  //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);
1377
+ if (obj.common.role != "value" || obj.common.type != type) {
1378
+ adapter.log.debug(` !!! need to extend for ${ key}`);
1209
1379
  await adapter.extendObject(key, {
1210
1380
  common: {
1211
1381
  type: type,
1212
1382
  role: "value",
1213
- }
1383
+ },
1214
1384
  });
1215
1385
  }
1216
- }
1217
- else {
1218
- adapter.log.warn(" !!! does not exist, creating now " + key );
1386
+ } else {
1387
+ adapter.log.warn(` !!! does not exist, creating now ${ key}` );
1219
1388
 
1220
1389
  await adapter.setObjectNotExistsAsync(key, {
1221
1390
  type: "state",
@@ -1225,38 +1394,34 @@ async function AddObject(key, type) {
1225
1394
  role: "value",
1226
1395
  unit: "",
1227
1396
  read: true,
1228
- write: false
1397
+ write: false,
1229
1398
  },
1230
1399
  native: {
1231
- location: key
1232
- }
1400
+ location: key,
1401
+ },
1233
1402
  });
1234
1403
  }
1235
-
1236
1404
  } catch (e) {
1237
- adapter.log.error("exception in AddObject " + "[" + e + "]");
1405
+ adapter.log.error(`exception in AddObject ` + `[${ e }]`);
1238
1406
  }
1239
1407
  }
1240
1408
 
1241
1409
  async function UpdateObject(key, value) {
1242
1410
  try {
1243
1411
  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);
1412
+ adapter.log.warn(`updateObject: not updated ${ key } value: ${ value } ${ typeof value}`);
1413
+ } else if (value == null ) {
1414
+ adapter.log.debug(`updateObject: update to null ${ key } value: ${ value}`);
1248
1415
  await adapter.setStateAsync(key, { ack: true, val: null });
1249
- }
1250
- else {
1251
- adapter.log.debug("updateObject " + key + " : " + value);
1416
+ } else {
1417
+ //adapter.log.debug("updateObject " + key + " : " + value);
1252
1418
  await adapter.setStateAsync(key, { ack: true, val: value });
1253
- }
1419
+ }
1254
1420
  } catch (e) {
1255
- adapter.log.error("exception in UpdateObject " + "[" + e + "]");
1421
+ adapter.log.error(`exception in UpdateObject ` + `[${ e }]`);
1256
1422
  }
1257
1423
  }
1258
1424
 
1259
-
1260
1425
  //telnet client to write to ebusd
1261
1426
  //https://github.com/john30/ebusd/wiki/3.1.-TCP-client-commands
1262
1427
  /*
@@ -1273,37 +1438,33 @@ read -f YieldTotal,read LegioProtectionEnabled,read -f -c broadcast outsidetemp
1273
1438
 
1274
1439
  */
1275
1440
 
1276
-
1277
1441
  //this function just triggers ebusd to read data; result will not be parsed; we just take the values from http result
1278
1442
  //here we need a loop over all configured read data in admin-page
1279
1443
  async function ebusd_ReadValues() {
1280
-
1281
1444
  if (oPolledVars.length > 0) {
1282
-
1283
- adapter.log.debug("to poll ctr " + oPolledVars.length + " vals: " + JSON.stringify(oPolledVars));
1445
+ adapter.log.debug(`to poll ctr ${ oPolledVars.length } vals: ${ JSON.stringify(oPolledVars)}`);
1284
1446
 
1285
1447
  try {
1286
1448
  const socket = new net.Socket();
1287
1449
  const promiseSocket = new PromiseSocket(socket);
1288
1450
 
1289
1451
  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);
1452
+ adapter.log.debug(`telnet connected to poll variables ${ adapter.config.targetIP } port ${ adapter.config.targetTelnetPort}`);
1291
1453
  promiseSocket.setTimeout(5000);
1292
1454
 
1293
1455
  let retries = 0;
1294
1456
  for (let nCtr = 0; nCtr < oPolledVars.length; nCtr++) {
1295
-
1296
1457
  let circuit = "";
1297
1458
  let params = "";
1298
1459
  if (oPolledVars[nCtr].circuit != null && oPolledVars[nCtr].circuit.length > 0) {
1299
- circuit = "-c " + oPolledVars[nCtr].circuit + " ";
1460
+ circuit = `-c ${ oPolledVars[nCtr].circuit } `;
1300
1461
  }
1301
1462
  if (oPolledVars[nCtr].parameter != null && oPolledVars[nCtr].parameter.length > 0) {
1302
- params = " " + oPolledVars[nCtr].parameter;
1463
+ params = ` ${ oPolledVars[nCtr].parameter}`;
1303
1464
  }
1304
- let cmd = "read -f " + circuit + oPolledVars[nCtr].name + params;
1465
+ let cmd = `read -f ${ circuit }${oPolledVars[nCtr].name }${params}`;
1305
1466
 
1306
- adapter.log.debug("send cmd " + cmd);
1467
+ adapter.log.debug(`send cmd ${ cmd}`);
1307
1468
 
1308
1469
  cmd += "\n";
1309
1470
  await promiseSocket.write(cmd);
@@ -1312,56 +1473,44 @@ async function ebusd_ReadValues() {
1312
1473
 
1313
1474
  //received ERR: arbitration lost for YieldThisYear
1314
1475
  if (data.includes("ERR")) {
1315
- adapter.log.warn("sent " + cmd + ", received " + data + " for " + JSON.stringify(oPolledVars[nCtr]) + " please check ebusd logs for details!");
1476
+ adapter.log.warn(`sent ${ cmd }, received ${ data } for ${ JSON.stringify(oPolledVars[nCtr]) } please check ebusd logs for details!`);
1316
1477
 
1317
1478
  /*
1318
- * sent read -f YieldLastYear, received ERR: arbitration lost for {"circuit":"","name":"YieldLastYear","parameter":""}
1319
- * */
1479
+ * sent read -f YieldLastYear, received ERR: arbitration lost for {"circuit":"","name":"YieldLastYear","parameter":""}
1480
+ * */
1320
1481
  if (data.includes("arbitration lost")) {
1321
-
1322
1482
  retries++;
1323
1483
  if (retries > adapter.config.maxretries) {
1324
- adapter.log.error("max retries, skip cmd " + cmd);
1484
+ adapter.log.error(`max retries, skip cmd ${ cmd}`);
1325
1485
  retries = 0;
1326
- }
1327
- else {
1486
+ } else {
1328
1487
  nCtr--;
1329
1488
  adapter.log.debug("retry to send data ");
1330
1489
  }
1331
1490
  }
1332
- }
1333
- else {
1334
- adapter.log.debug("received " + data + " for " + JSON.stringify(oPolledVars[nCtr]));
1491
+ } else {
1492
+ adapter.log.debug(`received ${ data } for ${ JSON.stringify(oPolledVars[nCtr])}`);
1335
1493
  }
1336
1494
  }
1337
1495
  promiseSocket.destroy();
1338
1496
  adapter.log.debug("telnet disonnected");
1339
-
1340
1497
  } catch (e) {
1341
- adapter.log.error("exception from tcp socket in ebusd_ReadValues " + "[" + e + "]");
1498
+ adapter.log.error(`exception from tcp socket in ebusd_ReadValues ` + `[${ e }]`);
1342
1499
  }
1343
-
1344
-
1345
- }
1346
- else {
1500
+ } else {
1347
1501
  adapter.log.debug("nothing to poll; skip telnet");
1348
1502
  }
1349
-
1350
1503
  }
1351
1504
 
1352
-
1353
1505
  async function FindParams(obj) {
1354
-
1355
- adapter.log.debug("FindParams " + JSON.stringify(obj) + " " + JSON.stringify(obj.message) + " " + JSON.stringify(obj.message.circuit));
1506
+ adapter.log.debug(`FindParams ${ JSON.stringify(obj) } ${ JSON.stringify(obj.message) } ${ JSON.stringify(obj.message.circuit)}`);
1356
1507
 
1357
1508
  const list = [];
1358
-
1359
1509
 
1360
1510
  try {
1361
1511
  //FindParams {"command":"findParams","message":{"circuit":"cc"},"from":"system.adapter.admin.0","callback":{"message":{"circuit":"cc"},"id":90,"ack":false,"time":1733690088670},"_id":39690903}
1362
1512
 
1363
1513
  if (obj.message != null) {
1364
-
1365
1514
  const circuit = obj.message.circuit;
1366
1515
 
1367
1516
  const socket = new net.Socket();
@@ -1371,16 +1520,16 @@ async function FindParams(obj) {
1371
1520
  adapter.log.debug("telnet connected for cmd");
1372
1521
  promiseSocket.setTimeout(5000);
1373
1522
 
1374
- const cmd = "find -c " + circuit + " -F circuit,name\n";
1523
+ const cmd = `find -c ${ circuit } -F circuit,name\n`;
1375
1524
  await promiseSocket.write(cmd);
1376
1525
 
1377
1526
  const data = await promiseSocket.read();
1378
1527
 
1379
1528
  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);
1529
+ adapter.log.warn(`received error! sent find, received ${ data } please check ebusd logs for details! ${ cmd}`);
1530
+
1531
+ } else {
1532
+ adapter.log.debug(`received ${ typeof data } ${ data } ${ + cmd}`);
1384
1533
  }
1385
1534
  /*
1386
1535
  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 +1538,6 @@ async function FindParams(obj) {
1389
1538
  const datas = str.split(/\r?\n/);
1390
1539
 
1391
1540
  for (let i = 0; i < datas.length; i++) {
1392
-
1393
1541
  //adapter.log.debug(JSON.stringify(datas[i]));
1394
1542
 
1395
1543
  const names = datas[i].split(",");
@@ -1399,11 +1547,9 @@ async function FindParams(obj) {
1399
1547
 
1400
1548
  if (names[0] == "" || names[1] == "") {
1401
1549
  add = false;
1402
- }
1403
- else {
1550
+ } else {
1404
1551
 
1405
1552
  for (let n = 0; n < list.length; n++) {
1406
-
1407
1553
  if (list[n].circuit == names[0] && list[n].name == names[1]) {
1408
1554
  add = false;
1409
1555
  //already in list
@@ -1415,27 +1561,24 @@ async function FindParams(obj) {
1415
1561
  const entry = {
1416
1562
  active: false,
1417
1563
  circuit: names[0],
1418
- name: names[1]
1564
+ name: names[1],
1419
1565
  };
1420
1566
 
1421
1567
  list.push(entry);
1422
1568
  }
1423
1569
  }
1424
- }
1425
- else {
1570
+ } else {
1426
1571
  adapter.log.error("no circuit defined where to look for parameter, check values!");
1427
1572
  }
1428
1573
  } catch (e) {
1429
- adapter.log.error("exception in FindParams " + "[" + e + "]");
1574
+ adapter.log.error(`exception in FindParams ` + `[${ e }]`);
1430
1575
  }
1431
1576
 
1432
- adapter.log.info("parameters " + JSON.stringify(list));
1433
-
1577
+ adapter.log.info(`parameters ${ JSON.stringify(list)}`);
1434
1578
 
1435
1579
  adapter.sendTo(obj.from, obj.command, list, obj.callback);
1436
1580
  }
1437
1581
 
1438
-
1439
1582
  async function CallExternalScript(script, msg) {
1440
1583
 
1441
1584
 
@@ -1456,7 +1599,7 @@ async function CallExternalScript(script, msg) {
1456
1599
  adapter.sendTo(msg.from, msg.command, { error: 'script folder not found ' + folderName }, msg.callback);
1457
1600
  return;
1458
1601
  }
1459
- else {
1602
+
1460
1603
 
1461
1604
  adapter.log.info("folder exists " + folderName);
1462
1605
 
@@ -1471,8 +1614,7 @@ async function CallExternalScript(script, msg) {
1471
1614
 
1472
1615
  return;
1473
1616
 
1474
- }
1475
- else {
1617
+ } else {
1476
1618
 
1477
1619
  adapter.log.info("file exists " + scriptfile);
1478
1620
 
@@ -1498,9 +1640,8 @@ async function CallExternalScript(script, msg) {
1498
1640
  }, msg.callback);
1499
1641
  });
1500
1642
  }
1501
- }
1502
- }
1503
- else {
1643
+
1644
+ } else {
1504
1645
  adapter.sendTo(msg.from, msg.command, { error: 'possible only on Linux systems, this system is ' + os.platform() }, msg.callback);
1505
1646
  }
1506
1647
  } catch (e) {
@@ -1546,17 +1687,44 @@ async function CallExternalScript(script, msg) {
1546
1687
  }
1547
1688
 
1548
1689
  async function CheckVersion(version, msg) {
1549
-
1550
1690
  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);
1691
+ let version = "unknown";
1692
+
1693
+ if (ebusdUpdateVersion[0] > 0 && ebusdVersion[0] > 0) {
1694
+ version = `${ebusdUpdateVersion[0] }.${ ebusdUpdateVersion[1]}`
1695
+ } else {
1696
+ version = await GetLatestVersionGithub();
1697
+ }
1698
+ adapter.sendTo(msg.from, msg.command, version, msg.callback);
1699
+ } else if (version == "current") {
1700
+ adapter.sendTo(msg.from, msg.command, `${ebusdVersion[0] }.${ ebusdVersion[1]}`, msg.callback);
1701
+ } else if (version == "supported") {
1702
+ adapter.sendTo(msg.from, msg.command, `${ebusdMinVersion[0] }.${ ebusdMinVersion[1]}`, msg.callback);
1558
1703
  }
1704
+ }
1705
+
1706
+ async function GetLatestVersionGithub() {
1707
+ let latestVersion = "unknown";
1708
+
1709
+ try {
1710
+ const url = "https://api.github.com/repos/john30/ebusd/releases/latest";
1711
+ adapter.log.debug(`call ${ url}`);
1712
+
1713
+ let result = await axios.get(url, { timeout: 5000 });
1559
1714
 
1715
+ if (result != null && result.status == 200 && result.data != null) {
1716
+ adapter.log.info(`installable version on github ${ JSON.stringify(result.data.tag_name) } (${ JSON.stringify(result.data.name) })`);
1717
+
1718
+ latestVersion =
1719
+ "on github " + JSON.stringify(result.data.tag_name) + "(" + JSON.stringify(result.data.name) + ")";
1720
+ } else {
1721
+ latestVersion = "unknown / no result";
1722
+ }
1723
+ } catch (e) {
1724
+ adapter.log.error(`exception in GetLatestVersionGithub [${ e }]`);
1725
+ latestVersion = "unknown / error";
1726
+ }
1727
+ return latestVersion;
1560
1728
  }
1561
1729
 
1562
1730
  // If started as allInOne/compact mode => return function to create instance
@@ -1565,4 +1733,4 @@ if (module && module.parent) {
1565
1733
  } else {
1566
1734
  // or start the instance directly
1567
1735
  startAdapter();
1568
- }
1736
+ }