iobroker.influxdb 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js CHANGED
@@ -103,21 +103,27 @@ function startAdapter(options) {
103
103
  } else {
104
104
  obj.common.custom[adapter.namespace].debounce = adapter.config.debounce;
105
105
  }
106
+
106
107
  obj.common.custom[adapter.namespace].changesOnly = obj.common.custom[adapter.namespace].changesOnly === 'true' || obj.common.custom[adapter.namespace].changesOnly === true;
108
+ obj.common.custom[adapter.namespace].ignoreZero = obj.common.custom[adapter.namespace].ignoreZero === 'true' || obj.common.custom[adapter.namespace].ignoreZero === true;
109
+ obj.common.custom[adapter.namespace].ignoreBelowZero = obj.common.custom[adapter.namespace].ignoreBelowZero === 'true' || obj.common.custom[adapter.namespace].ignoreBelowZero === true;
110
+
107
111
  if (obj.common.custom[adapter.namespace].changesRelogInterval !== undefined && obj.common.custom[adapter.namespace].changesRelogInterval !== null && obj.common.custom[adapter.namespace].changesRelogInterval !== '') {
108
112
  obj.common.custom[adapter.namespace].changesRelogInterval = parseInt(obj.common.custom[adapter.namespace].changesRelogInterval, 10) || 0;
109
113
  } else {
110
114
  obj.common.custom[adapter.namespace].changesRelogInterval = adapter.config.changesRelogInterval;
111
115
  }
116
+
112
117
  if (obj.common.custom[adapter.namespace].changesMinDelta !== undefined && obj.common.custom[adapter.namespace].changesMinDelta !== null && obj.common.custom[adapter.namespace].changesMinDelta !== '') {
113
118
  obj.common.custom[adapter.namespace].changesMinDelta = parseFloat(obj.common.custom[adapter.namespace].changesMinDelta.toString().replace(/,/g, '.')) || 0;
114
119
  } else {
115
120
  obj.common.custom[adapter.namespace].changesMinDelta = adapter.config.changesMinDelta;
116
121
  }
122
+
117
123
  if (!obj.common.custom[adapter.namespace].storageType) obj.common.custom[adapter.namespace].storageType = false;
118
124
 
119
125
  if (adapter._influxDPs[formerAliasId] && !adapter._influxDPs[formerAliasId].storageTypeAdjustedInternally && adapter._influxDPs[formerAliasId][adapter.namespace] && isEqual(obj.common.custom[adapter.namespace], adapter._influxDPs[formerAliasId][adapter.namespace])) {
120
- adapter.log.debug('Object ' + id + ' unchanged. Ignore');
126
+ adapter.log.debug(`Object ${id} unchanged. Ignore`);
121
127
  return;
122
128
  }
123
129
 
@@ -133,10 +139,10 @@ function startAdapter(options) {
133
139
 
134
140
  writeInitialValue(adapter, realId, id);
135
141
 
136
- adapter.log.info('enabled logging of ' + id + ', Alias=' + (id !== realId));
142
+ adapter.log.info(`enabled logging of ${id}, Alias=${id !== realId}`);
137
143
  } else {
138
144
  if (adapter._aliasMap[id]) {
139
- adapter.log.debug('Removed Alias: ' + id + ' !-> ' + adapter._aliasMap[id]);
145
+ adapter.log.debug(`Removed Alias: ${id} !-> ${adapter._aliasMap[id]}`);
140
146
  delete adapter._aliasMap[id];
141
147
  }
142
148
 
@@ -232,21 +238,22 @@ function ping(adapter) {
232
238
  }
233
239
  },
234
240
  error => {
235
- adapter.log.error("Error during ping: " + error + ". Attempting reconnect.");
241
+ adapter.log.error(`Error during ping: ${error}. Attempting reconnect.`);
236
242
  reconnect(adapter);
237
243
  });
238
244
  }
239
245
 
240
246
  function connect(adapter) {
241
- adapter.log.info('Connecting ' + adapter.config.protocol + '://' + adapter.config.host + ':' + adapter.config.port + ' ...');
247
+ adapter.log.info(`Connecting ${adapter.config.protocol}://${adapter.config.host}:${adapter.config.port} ...`);
242
248
 
243
249
  adapter.config.dbname = adapter.config.dbname || appName;
244
250
 
245
251
  adapter.config.seriesBufferMax = parseInt(adapter.config.seriesBufferMax, 10) || 0;
246
252
 
247
- adapter.log.info("Influx DB Version used: " + adapter.config.dbversion);
253
+ adapter.log.info('Influx DB Version used: ' + adapter.config.dbversion);
254
+
248
255
  switch (adapter.config.dbversion) {
249
- case "2.x":
256
+ case '2.x':
250
257
  if (/[\x00-\x08\x0E-\x1F\x80-\xFF]/.test(adapter.config.token)) {
251
258
  adapter.log.error('Token error: Please re-enter the token in Admin. Stopping');
252
259
  return;
@@ -262,7 +269,7 @@ function connect(adapter) {
262
269
  adapter.config.usetags
263
270
  )
264
271
  break;
265
- case "1.x":
272
+ case '1.x':
266
273
  default:
267
274
  if (/[\x00-\x08\x0E-\x1F\x80-\xFF]/.test(adapter.config.password)) {
268
275
  adapter.log.error('Password error: Please re-enter the password in Admin. Stopping');
@@ -288,8 +295,8 @@ function connect(adapter) {
288
295
  adapter.log.error(err);
289
296
  reconnect(adapter);
290
297
  } else {
291
- setConnected(adapter, true); //??? to early, move down?
292
- if (dbNames.indexOf(adapter.config.dbname) === -1) {
298
+ setConnected(adapter, true); // ??? to early, move down?
299
+ if (!dbNames.includes(adapter.config.dbname)) {
293
300
  adapter._client.createDatabase(adapter.config.dbname, err => {
294
301
  if (err) {
295
302
  adapter.log.error(err);
@@ -304,7 +311,7 @@ function connect(adapter) {
304
311
  }
305
312
  });
306
313
 
307
- if (adapter.config.dbversion === "2.x") {
314
+ if (adapter.config.dbversion === '2.x') {
308
315
  checkMetaDataStorageType(adapter);
309
316
  }
310
317
  });
@@ -317,7 +324,7 @@ function connect(adapter) {
317
324
  }
318
325
  });
319
326
 
320
- if (adapter.config.dbversion === "2.x") {
327
+ if (adapter.config.dbversion === '2.x') {
321
328
  checkMetaDataStorageType(adapter);
322
329
  }
323
330
  }
@@ -328,13 +335,13 @@ function connect(adapter) {
328
335
  function checkMetaDataStorageType(adapter) {
329
336
  adapter._client.getMetaDataStorageType((error,storageType) => {
330
337
  if (error)
331
- adapter.log.error("Error checking for metadata storage type: " + error);
338
+ adapter.log.error(`Error checking for metadata storage type: ${error}`);
332
339
  else {
333
- adapter.log.debug("Storage type for metadata found in DB: " + storageType);
334
- if (((storageType === "tags") && (!adapter.config.usetags))||((storageType === "fields")&&( adapter.config.usetags))) {
335
- adapter.log.error("Cannot use " + ((adapter.config.usetags) ? "tags" : "fields") +" for metadata (q, ack, from) since \
336
- the selected DB already uses " + storageType + " instead. Please change your adapter configuration, or choose a DB \
337
- that already uses " + ((adapter.config.usetags) ? "tags" : "fields") + ", or is empty.");
340
+ adapter.log.debug(`Storage type for metadata found in DB: ${storageType}`);
341
+ if ((storageType === 'tags' && !adapter.config.usetags) || (storageType === 'fields' && adapter.config.usetags)) {
342
+ adapter.log.error(`Cannot use ${adapter.config.usetags ? 'tags' : 'fields'} for metadata (q, ack, from) since ` +
343
+ `the selected DB already uses ${storageType} instead. Please change your adapter configuration, or choose a DB ` +
344
+ `that already uses ${adapter.config.usetags ? 'tags' : 'fields'}, or is empty.`);
338
345
  setConnected(adapter, false);
339
346
  finish(adapter, null);
340
347
  } else {
@@ -358,7 +365,7 @@ function processStartValues(adapter) {
358
365
  }
359
366
 
360
367
  function getRetention(adapter, msg) {
361
- adapter.log.debug("getRetention invoked, checking DB");
368
+ adapter.log.debug('getRetention invoked, checking DB');
362
369
  try {
363
370
  adapter._client.getRetentionPolicyForDB(adapter.config.dbname, result => {
364
371
  adapter.sendTo(msg.from, msg.command, {
@@ -372,7 +379,7 @@ function getRetention(adapter, msg) {
372
379
  }
373
380
 
374
381
  function testConnection(adapter, msg) {
375
- adapter.log.debug("testConnection msg-object: " + JSON.stringify(msg));
382
+ adapter.log.debug('testConnection msg-object: ' + JSON.stringify(msg));
376
383
  msg.message.config.port = parseInt(msg.message.config.port, 10) || 0;
377
384
 
378
385
  let timeout;
@@ -383,10 +390,10 @@ function testConnection(adapter, msg) {
383
390
  }, 5000);
384
391
 
385
392
  let lClient;
386
- adapter.log.debug("TEST DB Version: " + msg.message.config.dbversion);
393
+ adapter.log.debug('TEST DB Version: ' + msg.message.config.dbversion);
387
394
  switch (msg.message.config.dbversion) {
388
- case "2.x":
389
- adapter.log.info("Connecting to InfluxDB 2");
395
+ case '2.x':
396
+ adapter.log.info('Connecting to InfluxDB 2');
390
397
  lClient = new DatabaseInfluxDB2x(
391
398
  adapter.log,
392
399
  msg.message.config.host,
@@ -398,7 +405,7 @@ function testConnection(adapter, msg) {
398
405
  )
399
406
  break;
400
407
  default:
401
- case "1.x":
408
+ case '1.x':
402
409
  lClient = new DatabaseInfluxDB1x(
403
410
  adapter.log,
404
411
  msg.message.config.host,
@@ -411,7 +418,7 @@ function testConnection(adapter, msg) {
411
418
  break;
412
419
  }
413
420
 
414
- lClient.getDatabaseNames(function (err /* , arrayDatabaseNames*/ ) {
421
+ lClient.getDatabaseNames((err /* , arrayDatabaseNames*/ ) => {
415
422
  if (timeout) {
416
423
  clearTimeout(timeout);
417
424
  timeout = null;
@@ -436,37 +443,37 @@ function destroyDB(adapter, msg) {
436
443
  return adapter.sendTo(msg.from, msg.command, {error: 'Not connected'}, msg.callback);
437
444
  }
438
445
  try {
439
- adapter._client.dropDatabase(adapter.config.dbname, function (err) {
446
+ adapter._client.dropDatabase(adapter.config.dbname, err => {
440
447
  if (err) {
441
448
  adapter.log.error(err);
442
449
  adapter.sendTo(msg.from, msg.command, {error: err.toString()}, msg.callback);
443
450
  } else {
444
451
  adapter.sendTo(msg.from, msg.command, {error: null}, msg.callback);
445
452
  // restart adapter
446
- setTimeout(function () {
447
- adapter.getForeignObject('system.adapter.' + adapter.namespace, function (err, obj) {
453
+ setTimeout(() => {
454
+ adapter.getForeignObject('system.adapter.' + adapter.namespace, (err, obj) => {
448
455
  if (!err) {
449
456
  adapter.setForeignObject(obj._id, obj);
450
457
  } else {
451
- adapter.log.error('Cannot read object "system.adapter.' + adapter.namespace + '": ' + err);
458
+ adapter.log.error(`Cannot read object "system.adapter.${adapter.namespace}": ${err}`);
452
459
  adapter.stop();
453
460
  }
454
461
  });
455
462
  }, 2000);
456
463
  }
457
464
  });
458
- } catch (ex) {
459
- return adapter.sendTo(msg.from, msg.command, {error: ex.toString()}, msg.callback);
465
+ } catch (err) {
466
+ return adapter.sendTo(msg.from, msg.command, {error: err.toString()}, msg.callback);
460
467
  }
461
468
  }
462
469
 
463
470
  function processMessage(adapter, msg) {
464
- adapter.log.debug('Incoming message ' + msg.command + ' from ' + msg.from);
471
+ adapter.log.debug(`Incoming message ${msg.command} from ${msg.from}`);
465
472
  if (msg.command === 'features') {
466
473
  adapter.sendTo(msg.from, msg.command, {supportedFeatures: []}, msg.callback);
467
474
  } else
468
475
  if (msg.command === 'getHistory') {
469
- (adapter.config.dbversion === "1.x") ? getHistory(adapter, msg) : getHistoryIflx2(adapter, msg);
476
+ adapter.config.dbversion === '1.x' ? getHistory(adapter, msg) : getHistoryIflx2(adapter, msg);
470
477
  }
471
478
  else if (msg.command === 'test') {
472
479
  testConnection(adapter, msg);
@@ -475,13 +482,12 @@ function processMessage(adapter, msg) {
475
482
  destroyDB(adapter, msg);
476
483
  }
477
484
  else if (msg.command === 'query') {
478
-
479
485
  switch (adapter.config.dbversion) {
480
- case "2.x":
486
+ case '2.x':
481
487
  // Influx 2.x uses Flux instead of InfluxQL, so for multiple statements there is no delimiter by default, so we introduce ;
482
488
  multiQuery(adapter, msg);
483
489
  break;
484
- case "1.x":
490
+ case '1.x':
485
491
  default:
486
492
  query(adapter, msg);
487
493
  break;
@@ -528,26 +534,6 @@ function resetConflictingPoints(adapter, msg) {
528
534
  return adapter.sendTo(msg.from, msg.command, resultMsg, msg.callback);
529
535
  }
530
536
 
531
- function fixSelector(adapter, callback) {
532
- // fix _design/custom object
533
- adapter.getForeignObject('_design/custom', (err, obj) => {
534
- if (!obj || !obj.views.state.map.includes('common.custom')) {
535
- obj = {
536
- _id: '_design/custom',
537
- language: 'javascript',
538
- views: {
539
- state: {
540
- map: 'function(doc) { doc.type === \'state\' && doc.common.custom && emit(doc._id, doc.common.custom) }'
541
- }
542
- }
543
- };
544
- adapter.setForeignObject('_design/custom', obj, err => callback && callback(err));
545
- } else {
546
- callback && callback(err);
547
- }
548
- });
549
- }
550
-
551
537
  function main(adapter) {
552
538
  adapter.config.port = parseInt(adapter.config.port, 10) || 0;
553
539
 
@@ -557,9 +543,9 @@ function main(adapter) {
557
543
  obj.common.defaultHistory = adapter.namespace;
558
544
  adapter.setForeignObject('system.config', obj, err => {
559
545
  if (err) {
560
- adapter.log.error('Cannot set default history instance: ' + err);
546
+ adapter.log.error(`Cannot set default history instance: ${err}`);
561
547
  } else {
562
- adapter.log.info('Set default history instance to "' + adapter.namespace + '"');
548
+ adapter.log.info(`Set default history instance to "${adapter.namespace}"`);
563
549
  }
564
550
  });
565
551
  }
@@ -599,74 +585,75 @@ function main(adapter) {
599
585
  if (tempData.seriesBufferCounter) adapter._seriesBufferCounter = tempData.seriesBufferCounter;
600
586
  if (tempData.seriesBuffer) adapter._seriesBuffer = tempData.seriesBuffer;
601
587
  if (tempData.conflictingPoints) adapter._conflictingPoints = tempData.conflictingPoints;
602
- adapter.log.info('Buffer initialized with data for ' + adapter._seriesBufferCounter + ' points and ' + Object.keys(adapter._conflictingPoints).length + ' conflicts from last exit');
588
+ adapter.log.info(`Buffer initialized with data for ${adapter._seriesBufferCounter} points and ${Object.keys(adapter._conflictingPoints).length} conflicts from last exit`);
603
589
  fs.unlinkSync(cacheFile);
604
590
  }
605
591
  } catch (err) {
606
592
  adapter.log.info('No stored data from last exit found');
607
593
  }
608
594
 
609
- fixSelector(adapter, () =>
610
- // read all custom settings
611
- adapter.getObjectView('custom', 'state', {}, (err, doc) => {
612
- if (err) adapter.log.error('main/getObjectView: ' + err);
613
- let count = 0;
614
- if (doc && doc.rows) {
615
- for (let i = 0, l = doc.rows.length; i < l; i++) {
616
- if (doc.rows[i].value) {
617
- let id = doc.rows[i].id;
618
- const realId = id;
619
- if (doc.rows[i].value[adapter.namespace] && doc.rows[i].value[adapter.namespace].aliasId) {
620
- adapter._aliasMap[id] = doc.rows[i].value[adapter.namespace].aliasId;
621
- adapter.log.debug('Found Alias: ' + id + ' --> ' + adapter._aliasMap[id]);
622
- id = adapter._aliasMap[id];
623
- }
624
- adapter._influxDPs[id] = doc.rows[i].value;
625
-
626
- if (!adapter._influxDPs[id][adapter.namespace] || typeof adapter._influxDPs[id][adapter.namespace] !== 'object' || adapter._influxDPs[id][adapter.namespace].enabled === false) {
627
- delete adapter._influxDPs[id];
628
- } else {
629
- count++;
630
- adapter.log.info('enabled logging of ' + id + ', Alias=' + (id !== realId) + ', ' + count + ' points now activated');
595
+ // read all custom settings
596
+ adapter.getObjectView('system', 'custom', {}, (err, doc) => {
597
+ if (err) adapter.log.error('main/getObjectView: ' + err);
598
+ let count = 0;
599
+ if (doc && doc.rows) {
600
+ for (let i = 0, l = doc.rows.length; i < l; i++) {
601
+ if (doc.rows[i].value) {
602
+ let id = doc.rows[i].id;
603
+ const realId = id;
604
+ if (doc.rows[i].value[adapter.namespace] && doc.rows[i].value[adapter.namespace].aliasId) {
605
+ adapter._aliasMap[id] = doc.rows[i].value[adapter.namespace].aliasId;
606
+ adapter.log.debug(`Found Alias: ${id} --> ${adapter._aliasMap[id]}`);
607
+ id = adapter._aliasMap[id];
608
+ }
609
+ adapter._influxDPs[id] = doc.rows[i].value;
631
610
 
632
- if (adapter._influxDPs[id][adapter.namespace].debounce !== undefined && adapter._influxDPs[id][adapter.namespace].debounce !== null && adapter._influxDPs[id][adapter.namespace].debounce !== '') {
633
- adapter._influxDPs[id][adapter.namespace].debounce = parseInt(adapter._influxDPs[id][adapter.namespace].debounce, 10) || 0;
634
- } else {
635
- adapter._influxDPs[id][adapter.namespace].debounce = adapter.config.debounce;
636
- }
611
+ if (!adapter._influxDPs[id][adapter.namespace] || typeof adapter._influxDPs[id][adapter.namespace] !== 'object' || adapter._influxDPs[id][adapter.namespace].enabled === false) {
612
+ delete adapter._influxDPs[id];
613
+ } else {
614
+ count++;
615
+ adapter.log.info(`enabled logging of ${id}, Alias=${id !== realId}, ${count} points now activated`);
637
616
 
638
- adapter._influxDPs[id][adapter.namespace].changesOnly = adapter._influxDPs[id][adapter.namespace].changesOnly === 'true' || adapter._influxDPs[id][adapter.namespace].changesOnly === true;
617
+ if (adapter._influxDPs[id][adapter.namespace].debounce !== undefined && adapter._influxDPs[id][adapter.namespace].debounce !== null && adapter._influxDPs[id][adapter.namespace].debounce !== '') {
618
+ adapter._influxDPs[id][adapter.namespace].debounce = parseInt(adapter._influxDPs[id][adapter.namespace].debounce, 10) || 0;
619
+ } else {
620
+ adapter._influxDPs[id][adapter.namespace].debounce = adapter.config.debounce;
621
+ }
639
622
 
640
- if (adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== undefined && adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== null && adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== '') {
641
- adapter._influxDPs[id][adapter.namespace].changesRelogInterval = parseInt(adapter._influxDPs[id][adapter.namespace].changesRelogInterval, 10) || 0;
642
- } else {
643
- adapter._influxDPs[id][adapter.namespace].changesRelogInterval = adapter.config.changesRelogInterval;
644
- }
645
- if (adapter._influxDPs[id][adapter.namespace].changesMinDelta !== undefined && adapter._influxDPs[id][adapter.namespace].changesMinDelta !== null && adapter._influxDPs[id][adapter.namespace].changesMinDelta !== '') {
646
- adapter._influxDPs[id][adapter.namespace].changesMinDelta = parseFloat(adapter._influxDPs[id][adapter.namespace].changesMinDelta) || 0;
647
- } else {
648
- adapter._influxDPs[id][adapter.namespace].changesMinDelta = adapter.config.changesMinDelta;
649
- }
650
- if (!adapter._influxDPs[id][adapter.namespace].storageType) adapter._influxDPs[id][adapter.namespace].storageType = false;
623
+ adapter._influxDPs[id][adapter.namespace].changesOnly = adapter._influxDPs[id][adapter.namespace].changesOnly === 'true' || adapter._influxDPs[id][adapter.namespace].changesOnly === true;
624
+ adapter._influxDPs[id][adapter.namespace].ignoreZero = adapter._influxDPs[id][adapter.namespace].ignoreZero === 'true' || adapter._influxDPs[id][adapter.namespace].ignoreZero === true;
625
+ adapter._influxDPs[id][adapter.namespace].ignoreBelowZero = adapter._influxDPs[id][adapter.namespace].ignoreBelowZero === 'true' || adapter._influxDPs[id][adapter.namespace].ignoreBelowZero === true;
651
626
 
652
- adapter._influxDPs[id].realId = realId;
653
- writeInitialValue(adapter, realId, id);
627
+ if (adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== undefined && adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== null && adapter._influxDPs[id][adapter.namespace].changesRelogInterval !== '') {
628
+ adapter._influxDPs[id][adapter.namespace].changesRelogInterval = parseInt(adapter._influxDPs[id][adapter.namespace].changesRelogInterval, 10) || 0;
629
+ } else {
630
+ adapter._influxDPs[id][adapter.namespace].changesRelogInterval = adapter.config.changesRelogInterval;
631
+ }
632
+ if (adapter._influxDPs[id][adapter.namespace].changesMinDelta !== undefined && adapter._influxDPs[id][adapter.namespace].changesMinDelta !== null && adapter._influxDPs[id][adapter.namespace].changesMinDelta !== '') {
633
+ adapter._influxDPs[id][adapter.namespace].changesMinDelta = parseFloat(adapter._influxDPs[id][adapter.namespace].changesMinDelta) || 0;
634
+ } else {
635
+ adapter._influxDPs[id][adapter.namespace].changesMinDelta = adapter.config.changesMinDelta;
654
636
  }
637
+ if (!adapter._influxDPs[id][adapter.namespace].storageType) adapter._influxDPs[id][adapter.namespace].storageType = false;
638
+
639
+ adapter._influxDPs[id].realId = realId;
640
+ writeInitialValue(adapter, realId, id);
655
641
  }
656
642
  }
657
643
  }
644
+ }
658
645
 
659
- if (count < 20) {
660
- for (const _id in adapter._influxDPs) {
661
- if (adapter._influxDPs.hasOwnProperty(_id)) {
662
- adapter.subscribeForeignStates(adapter._influxDPs[_id].realId);
663
- }
646
+ if (count < 20) {
647
+ for (const _id in adapter._influxDPs) {
648
+ if (adapter._influxDPs.hasOwnProperty(_id)) {
649
+ adapter.subscribeForeignStates(adapter._influxDPs[_id].realId);
664
650
  }
665
- } else {
666
- adapter._subscribeAll = true;
667
- adapter.subscribeForeignStates('*');
668
651
  }
669
- }));
652
+ } else {
653
+ adapter._subscribeAll = true;
654
+ adapter.subscribeForeignStates('*');
655
+ }
656
+ });
670
657
 
671
658
  adapter.subscribeForeignObjects('*');
672
659
 
@@ -717,29 +704,27 @@ function pushHistory(adapter, id, state, timerRelog) {
717
704
  if (settings.changesRelogInterval === 0) {
718
705
  if (state.ts !== state.lc) {
719
706
  adapter._influxDPs[id].skipped = state; // remember new timestamp
720
- adapter.log.debug('value not changed ' + id + ', last-value=' + adapter._influxDPs[id].state.val + ', new-value=' + state.val + ', ts=' + state.ts);
707
+ adapter.log.debug(`value not changed ${id}, last-value=${adapter._influxDPs[id].state.val}, new-value=${state.val}, ts=${state.ts}`);
721
708
  return;
722
709
  }
723
710
  } else if (adapter._influxDPs[id].lastLogTime) {
724
711
  if ((state.ts !== state.lc) && (Math.abs(adapter._influxDPs[id].lastLogTime - state.ts) < settings.changesRelogInterval * 1000)) {
725
- adapter.log.debug('value not changed ' + id + ', last-value=' + adapter._influxDPs[id].state.val + ', new-value=' + state.val + ', ts=' + state.ts);
712
+ adapter.log.debug(`value not changed ${id}, last-value=${adapter._influxDPs[id].state.val}, new-value=${state.val}, ts=${state.ts}`);
726
713
  adapter._influxDPs[id].skipped = state; // remember new timestamp
727
714
  return;
728
715
  }
729
716
  if (state.ts !== state.lc) {
730
- adapter.log.debug('value-changed-relog ' + id + ', value=' + state.val + ', lastLogTime=' + adapter._influxDPs[id].lastLogTime + ', ts=' + state.ts);
717
+ adapter.log.debug(`value-changed-relog ${id}, value=${state.val}, lastLogTime=${adapter._influxDPs[id].lastLogTime}, ts=${state.ts}`);
731
718
  }
732
719
  }
733
- if ((settings.changesMinDelta !== 0) && (typeof state.val === 'number') && (Math.abs(adapter._influxDPs[id].state.val - state.val) < settings.changesMinDelta)) {
734
- adapter.log.debug('Min-Delta not reached ' + id + ', last-value=' + adapter._influxDPs[id].state.val + ', new-value=' + state.val + ', ts=' + state.ts);
720
+ if (settings.changesMinDelta !== 0 && typeof state.val === 'number' && Math.abs(adapter._influxDPs[id].state.val - state.val) < settings.changesMinDelta) {
721
+ adapter.log.debug(`Min-Delta not reached ${id}, last-value=${adapter._influxDPs[id].state.val}, new-value=${state.val}, ts=${state.ts}`);
735
722
  adapter._influxDPs[id].skipped = state; // remember new timestamp
736
723
  return;
737
- }
738
- else if (typeof state.val === 'number') {
739
- adapter.log.debug('Min-Delta reached ' + id + ', last-value=' + adapter._influxDPs[id].state.val + ', new-value=' + state.val + ', ts=' + state.ts);
740
- }
741
- else {
742
- adapter.log.debug('Min-Delta ignored because no number ' + id + ', last-value=' + adapter._influxDPs[id].state.val + ', new-value=' + state.val + ', ts=' + state.ts);
724
+ } else if (typeof state.val === 'number') {
725
+ adapter.log.debug(`Min-Delta reached ${id}, last-value=${adapter._influxDPs[id].state.val}, new-value=${state.val}, ts=${state.ts}`);
726
+ } else {
727
+ adapter.log.debug(`Min-Delta ignored because no number ${id}, last-value=${adapter._influxDPs[id].state.val}, new-value=${state.val}, ts=${state.ts}`);
743
728
  }
744
729
  }
745
730
 
@@ -755,7 +740,7 @@ function pushHistory(adapter, id, state, timerRelog) {
755
740
  if (timerRelog) {
756
741
  state.ts = Date.now();
757
742
  state.from = 'system.adapter.' + adapter.namespace;
758
- adapter.log.debug('timed-relog ' + id + ', value=' + state.val + ', lastLogTime=' + adapter._influxDPs[id].lastLogTime + ', ts=' + state.ts);
743
+ adapter.log.debug(`timed-relog ${id}, value=${state.val}, lastLogTime=${adapter._influxDPs[id].lastLogTime}, ts=${state.ts}`);
759
744
  ignoreDebounce = true;
760
745
  } else {
761
746
  if (settings.changesOnly && adapter._influxDPs[id].skipped) {
@@ -799,11 +784,11 @@ function reLogHelper(adapter, _id) {
799
784
  else {
800
785
  adapter.getForeignState(adapter._influxDPs[_id].realId, (err, state) => {
801
786
  if (err) {
802
- adapter.log.info('init timed Relog: can not get State for ' + _id + ' : ' + err);
787
+ adapter.log.info(`init timed Relog: can not get State for ${_id}: ${err}`);
803
788
  } else if (!state) {
804
- adapter.log.info('init timed Relog: disable relog because state not set so far for ' + _id + ': ' + JSON.stringify(state));
789
+ adapter.log.info(`init timed Relog: disable relog because state not set so far for ${_id}: ${JSON.stringify(state)}`);
805
790
  } else if (adapter._influxDPs[_id]) {
806
- adapter.log.debug('init timed Relog: getState ' + _id + ': Value=' + state.val + ', ack=' + state.ack + ', ts=' + state.ts + ', lc=' + state.lc);
791
+ adapter.log.debug(`init timed Relog: getState ${_id}: Value=${state.val}, ack=${state.ack}, ts=${state.ts}, lc=${state.lc}`);
807
792
  adapter._influxDPs[_id].state = state;
808
793
  pushHistory(adapter, _id, adapter._influxDPs[_id].state, true);
809
794
  }
@@ -813,19 +798,21 @@ function reLogHelper(adapter, _id) {
813
798
 
814
799
  function pushHelper(adapter, _id, cb) {
815
800
  if (!adapter._influxDPs[_id] || !adapter._influxDPs[_id].state || !adapter._influxDPs[_id][adapter.namespace]) {
816
- return cb && setImmediate(cb, 'ID ' + _id + ' not activated for logging');
801
+ return cb && setImmediate(cb, `ID ${_id} not activated for logging`);
817
802
  }
818
803
  const _settings = adapter._influxDPs[_id][adapter.namespace];
819
804
  // if it was not deleted in this time
820
805
  adapter._influxDPs[_id].timeout = null;
821
806
 
822
807
  if (adapter._influxDPs[_id].state.val === null) { // InfluxDB can not handle null values
823
- return cb && setImmediate(cb, 'null value for ' + _id + ' can not be handled');
808
+ return cb && setImmediate(cb, `null value for ${_id} can not be handled`);
824
809
  }
825
810
 
826
- if (typeof adapter._influxDPs[_id].state.val === 'object') adapter._influxDPs[_id].state.val = JSON.stringify(adapter._influxDPs[_id].state.val);
811
+ if (typeof adapter._influxDPs[_id].state.val === 'object') {
812
+ adapter._influxDPs[_id].state.val = JSON.stringify(adapter._influxDPs[_id].state.val);
813
+ }
827
814
 
828
- adapter.log.debug('Datatype ' + _id + ': Currently: ' + typeof adapter._influxDPs[_id].state.val + ', StorageType: ' + _settings.storageType);
815
+ adapter.log.debug(`Datatype ${_id}: Currently: ${typeof adapter._influxDPs[_id].state.val}, StorageType: ${_settings.storageType}`);
829
816
  if (typeof adapter._influxDPs[_id].state.val === 'string' && _settings.storageType !== 'String') {
830
817
  adapter.log.debug('Do Automatic Datatype conversion for ' + _id);
831
818
  const f = parseFloat(adapter._influxDPs[_id].state.val);
@@ -845,30 +832,37 @@ function pushHelper(adapter, _id, cb) {
845
832
  adapter._influxDPs[_id].state.val = adapter._influxDPs[_id].state.val?1:0;
846
833
  }
847
834
  else {
848
- adapter.log.info('Do not store value "' + adapter._influxDPs[_id].state.val + '" for ' + _id + ' because no number');
849
- return cb && setImmediate(cb, 'do not store value for ' + _id + ' because no number');
835
+ adapter.log.info(`Do not store value "${adapter._influxDPs[_id].state.val}" for ${_id} because no number`);
836
+ return cb && setImmediate(cb, `do not store value for ${_id} because no number`);
850
837
  }
851
838
  }
852
839
  else if (_settings.storageType === 'Boolean' && typeof adapter._influxDPs[_id].state.val !== 'boolean') {
853
840
  adapter._influxDPs[_id].state.val = !!adapter._influxDPs[_id].state.val;
854
841
  }
855
- pushValueIntoDB(adapter, _id, adapter._influxDPs[_id].state, () => cb && setImmediate(cb));
842
+ pushValueIntoDB(adapter, _id, adapter._influxDPs[_id].state, () =>
843
+ cb && setImmediate(cb));
856
844
  }
857
845
 
858
846
  function pushValueIntoDB(adapter, id, state, cb) {
859
847
  if (!adapter._client) {
860
848
  adapter.log.warn('No connection to DB');
861
- if (cb) cb('No connection to DB');
862
- return;
849
+ return cb && cb('No connection to DB');
863
850
  }
864
851
 
865
- if ((state.val === null) || (state.val === undefined)) {
866
- if (cb) cb('InfluxDB can not handle null/non-existing values');
867
- return;
852
+ if (state.val === null || state.val === undefined) {
853
+ return cb && cb('InfluxDB can not handle null/non-existing values');
868
854
  } // InfluxDB can not handle null/non-existing values
869
- if ((typeof state.val === 'number') && (isNaN(state.val))) {
870
- if (cb) cb('InfluxDB can not handle null/non-existing values');
871
- return;
855
+ if (typeof state.val === 'number' && isNaN(state.val)) {
856
+ return cb && cb('InfluxDB can not handle null/non-existing values');
857
+ }
858
+
859
+ if (adapter._influxDPs[id][adapter.namespace].ignoreZero && state.val === 0) {
860
+ adapter.log.debug(`pushValueIntoDB called for ${id} was ignored because the value zero or null`);
861
+ return cb && cb();
862
+ } else
863
+ if (state && adapter._influxDPs[id][adapter.namespace].ignoreBelowZero && typeof state.val === 'number' && state.val < 0) {
864
+ adapter.log.debug(`pushValueIntoDB called for ${id} and state: ${JSON.stringify(state)} was ignored because the value is below 0`);
865
+ return cb && cb();
872
866
  }
873
867
 
874
868
  state.ts = parseInt(state.ts, 10);
@@ -900,9 +894,9 @@ function pushValueIntoDB(adapter, id, state, cb) {
900
894
  ack: !!state.ack
901
895
  };
902
896
 
903
- if ((adapter._conflictingPoints[id] || (adapter.config.seriesBufferMax === 0)) && (adapter._connected && adapter._client.request && adapter._client.request.getHostsAvailable().length > 0)) {
897
+ if ((adapter._conflictingPoints[id] || adapter.config.seriesBufferMax === 0) && (adapter._connected && adapter._client.request && adapter._client.request.getHostsAvailable().length > 0)) {
904
898
  if (adapter.config.seriesBufferMax !== 0) {
905
- adapter.log.debug('Direct writePoint("' + id + ' - ' + influxFields.value + ' / ' + influxFields.time + ')');
899
+ adapter.log.debug(`Direct writePoint("${id} - ${influxFields.value} / ${influxFields.time}")`);
906
900
  }
907
901
  writeOnePointForID(adapter, id, influxFields, true, cb);
908
902
  } else {
@@ -911,9 +905,9 @@ function pushValueIntoDB(adapter, id, state, cb) {
911
905
  }
912
906
 
913
907
  function addPointToSeriesBuffer(adapter, id, stateObj, cb) {
914
- if ((adapter._conflictingPoints[id] || (adapter.config.seriesBufferMax === 0)) && (adapter._connected && adapter._client.request && adapter._client.request.getHostsAvailable().length > 0)) {
908
+ if ((adapter._conflictingPoints[id] || adapter.config.seriesBufferMax === 0) && (adapter._connected && adapter._client.request && adapter._client.request.getHostsAvailable().length > 0)) {
915
909
  if (adapter.config.seriesBufferMax !== 0) {
916
- adapter.log.debug('Direct writePoint("' + id + ' - ' + stateObj.value + ' / ' + stateObj.time + ')');
910
+ adapter.log.debug(`Direct writePoint("${id} - ${stateObj.value} / ${stateObj.time}")`);
917
911
  }
918
912
  return void writeOnePointForID(adapter, id, stateObj, true, cb);
919
913
  }
@@ -923,7 +917,7 @@ function addPointToSeriesBuffer(adapter, id, stateObj, cb) {
923
917
  }
924
918
  adapter._seriesBuffer[id].push([stateObj]);
925
919
  adapter._seriesBufferCounter++;
926
- if ((adapter._seriesBufferCounter > adapter.config.seriesBufferMax) && adapter._connected && adapter._client.request && (adapter._client.request.getHostsAvailable().length > 0) && (!adapter._seriesBufferFlushPlanned)) {
920
+ if (adapter._seriesBufferCounter > adapter.config.seriesBufferMax && adapter._connected && adapter._client.request && adapter._client.request.getHostsAvailable().length > 0 && !adapter._seriesBufferFlushPlanned) {
927
921
  // flush out
928
922
  adapter._seriesBufferFlushPlanned = true;
929
923
  setImmediate(() => storeBufferedSeries(adapter, cb));
@@ -937,7 +931,7 @@ function storeBufferedSeries(adapter, cb) {
937
931
  return cb && cb();
938
932
  }
939
933
 
940
- if ((!adapter._client) || (adapter._client.request.getHostsAvailable().length === 0)) {
934
+ if (!adapter._client || adapter._client.request.getHostsAvailable().length === 0) {
941
935
  setConnected(adapter, false);
942
936
  adapter.log.info('Currently no hosts available, try later');
943
937
  adapter._seriesBufferFlushPlanned = false;
@@ -950,12 +944,12 @@ function storeBufferedSeries(adapter, cb) {
950
944
  }
951
945
  adapter._seriesBufferChecker && clearInterval(adapter._seriesBufferChecker);
952
946
 
953
- adapter.log.info('Store ' + adapter._seriesBufferCounter + ' buffered influxDB history points');
947
+ adapter.log.info(`Store ${adapter._seriesBufferCounter} buffered influxDB history points`);
954
948
 
955
949
  const currentBuffer = adapter._seriesBuffer;
956
950
  if (adapter._seriesBufferCounter > 15000) {
957
- // if we have too many datapoints in buffer; we better writer them per id
958
- adapter.log.info('Too many datapoints (' + adapter._seriesBufferCounter + ') to write at once; write per ID');
951
+ // if we have too many data points in buffer; we better writer them per id
952
+ adapter.log.info(`Too many data points (${adapter._seriesBufferCounter}) to write at once; write per ID`);
959
953
  writeAllSeriesPerID(adapter, currentBuffer, cb);
960
954
  } else {
961
955
  writeAllSeriesAtOnce(adapter, currentBuffer, cb);
@@ -963,11 +957,12 @@ function storeBufferedSeries(adapter, cb) {
963
957
  adapter._seriesBuffer = {};
964
958
  adapter._seriesBufferCounter = 0;
965
959
  adapter._seriesBufferFlushPlanned = false;
966
- adapter._seriesBufferChecker = setInterval(() => storeBufferedSeries(adapter), adapter.config.seriesBufferFlushInterval * 1000);
960
+ adapter._seriesBufferChecker = setInterval(() =>
961
+ storeBufferedSeries(adapter), adapter.config.seriesBufferFlushInterval * 1000);
967
962
  }
968
963
 
969
964
  function writeAllSeriesAtOnce(adapter, series, cb) {
970
- adapter._client.writeSeries(series, function (err /* , result */) {
965
+ adapter._client.writeSeries(series, (err /* , result */) => {
971
966
  if (err) {
972
967
  adapter.log.warn('Error on writeSeries: ' + err);
973
968
  if (adapter._client.request.getHostsAvailable().length === 0) {
@@ -982,10 +977,10 @@ function writeAllSeriesAtOnce(adapter, series, cb) {
982
977
  }
983
978
  });
984
979
  reconnect(adapter);
985
- } else if (err.message && typeof err.message === 'string' && err.message.indexOf('partial write') !== -1 && err.message.indexOf('field type conflict') === -1) {
986
- adapter.log.warn('All possible datapoints were written, others can not really be corrected');
980
+ } else if (err.message && typeof err.message === 'string' && err.message.includes('partial write') && !err.message.includes('field type conflict')) {
981
+ adapter.log.warn('All possible data points were written, others can not really be corrected');
987
982
  } else {
988
- adapter.log.info('Try to write ' + Object.keys(series).length + ' Points separate to find the conflicting id');
983
+ adapter.log.info(`Try to write ${Object.keys(series).length} Points separate to find the conflicting id`);
989
984
  // fallback and send data per id to find out problematic id!
990
985
  return writeAllSeriesPerID(adapter, series, cb);
991
986
  }
@@ -1011,15 +1006,15 @@ function writeSeriesPerID(adapter, seriesId, points, cb) {
1011
1006
  if (!points.length) {
1012
1007
  return cb && cb();
1013
1008
  }
1014
- adapter.log.debug('writePoints ' + points.length + ' for ' + seriesId + ' at once');
1009
+ adapter.log.debug(`writePoints ${points.length} for ${seriesId} at once`);
1015
1010
 
1016
1011
  const pointsToSend = points.splice(0, 15000);
1017
1012
  if (points.length) { // We still have some left
1018
- adapter.log.info('Too many dataPoints (' + (pointsToSend.length + points.length) + ') for "' + seriesId + '" to write at once; split in 15.000 batches');
1013
+ adapter.log.info(`Too many dataPoints (${pointsToSend.length + points.length}) for "${seriesId}" to write at once; split in 15.000 batches`);
1019
1014
  }
1020
1015
  adapter._client.writePoints(seriesId, pointsToSend, err => {
1021
1016
  if (err) {
1022
- adapter.log.warn('Error on writePoints for ' + seriesId + ': ' + err);
1017
+ adapter.log.warn(`Error on writePoints for ${seriesId}: ${err}`);
1023
1018
  if ((adapter._client.request.getHostsAvailable().length === 0) || (err.message && (err.message === 'timeout' || err.message.includes('timed out') ))) {
1024
1019
  adapter.log.info('Host not available, move all points back in the Buffer');
1025
1020
  // error caused InfluxDB adapter._client to remove the host from available for now
@@ -1036,7 +1031,7 @@ function writeSeriesPerID(adapter, seriesId, points, cb) {
1036
1031
  reconnect(adapter);
1037
1032
  return cb && cb();
1038
1033
  } else {
1039
- adapter.log.warn('Try to write ' + pointsToSend.length + ' Points separate to find the conflicting one');
1034
+ adapter.log.warn(`Try to write ${pointsToSend.length} Points separate to find the conflicting one`);
1040
1035
  // we found the conflicting id
1041
1036
  return writePointsForID(adapter, seriesId, pointsToSend, () => writeSeriesPerID(adapter, seriesId, points, cb));
1042
1037
  }
@@ -1051,10 +1046,12 @@ function writePointsForID(adapter, seriesId, points, cb) {
1051
1046
  if (!points.length) {
1052
1047
  return cb && cb();
1053
1048
  }
1054
- adapter.log.debug('writePoint ' + points.length + ' for ' + seriesId + ' separate');
1049
+ adapter.log.debug(`writePoint ${points.length} for ${seriesId} separate`);
1055
1050
 
1056
1051
  const point = points.shift();
1057
- writeOnePointForID(adapter, seriesId, point[0], false, () => setImmediate (() => writePointsForID(adapter, seriesId, points, cb)));
1052
+ writeOnePointForID(adapter, seriesId, point[0], false, () =>
1053
+ setImmediate (() =>
1054
+ writePointsForID(adapter, seriesId, points, cb)));
1058
1055
  }
1059
1056
 
1060
1057
  function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
@@ -1067,17 +1064,17 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1067
1064
 
1068
1065
  adapter._client.writePoint(pointId, point, null, (err /* , result */) => {
1069
1066
  if (err) {
1070
- adapter.log.warn('Error on writePoint("' + JSON.stringify(point) + '): ' + err + ' / ' + JSON.stringify(err.message));
1067
+ adapter.log.warn(`Error on writePoint("${JSON.stringify(point)}): ${err} / ${JSON.stringify(err.message)}"`);
1071
1068
  if ((adapter._client.request.getHostsAvailable().length === 0) || (err.message && err.message === 'timeout')) {
1072
1069
  reconnect(adapter);
1073
1070
  addPointToSeriesBuffer(adapter, pointId, point);
1074
- } else if (err.message && (typeof err.message === 'string') && (err.message.indexOf('field type conflict') !== -1)) {
1071
+ } else if (err.message && typeof err.message === 'string' && err.message.includes('field type conflict')) {
1075
1072
  // retry write after type correction for some easy cases
1076
1073
  let retry = false;
1077
1074
  if (adapter._influxDPs[pointId] && adapter._influxDPs[pointId][adapter.namespace] && !adapter._influxDPs[pointId][adapter.namespace].storageType) {
1078
1075
  let convertDirection = '';
1079
- if (err.message.indexOf('is type bool, already exists as type float') !== -1 ||
1080
- err.message.indexOf('is type boolean, already exists as type float') !== -1) {
1076
+ if (err.message.includes('is type bool, already exists as type float') ||
1077
+ err.message.includes('is type boolean, already exists as type float')) {
1081
1078
  convertDirection = 'bool -> float';
1082
1079
  if (point.value === true) {
1083
1080
  point.value = 1;
@@ -1090,7 +1087,8 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1090
1087
  adapter._influxDPs[pointId][adapter.namespace].storageType = 'Number';
1091
1088
  adapter._influxDPs[pointId].storageTypeAdjustedInternally = true;
1092
1089
  }
1093
- else if ((err.message.indexOf('is type float, already exists as type bool') !== -1) || (err.message.indexOf('is type float64, already exists as type bool') !== -1)) {
1090
+ else if (err.message.includes('is type float, already exists as type bool') ||
1091
+ err.message.includes('is type float64, already exists as type bool')) {
1094
1092
  convertDirection = 'float -> bool';
1095
1093
  if (point.value === 1) {
1096
1094
  point.value = true;
@@ -1103,14 +1101,14 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1103
1101
  adapter._influxDPs[pointId][adapter.namespace].storageType = 'Boolean';
1104
1102
  adapter._influxDPs[pointId].storageTypeAdjustedInternally = true;
1105
1103
  }
1106
- else if (err.message.indexOf(', already exists as type string') !== -1) {
1104
+ else if (err.message.includes(', already exists as type string')) {
1107
1105
  point.value = point.value.toString();
1108
1106
  retry = true;
1109
1107
  adapter._influxDPs[pointId][adapter.namespace].storageType = 'String';
1110
1108
  adapter._influxDPs[pointId].storageTypeAdjustedInternally = true;
1111
1109
  }
1112
1110
  if (retry) {
1113
- adapter.log.info('Try to convert ' + convertDirection + ' and re-write for ' + pointId + ' and set storageType to ' + adapter._influxDPs[pointId][adapter.namespace].storageType);
1111
+ adapter.log.info(`Try to convert ${convertDirection} and re-write for ${pointId} and set storageType to ${adapter._influxDPs[pointId][adapter.namespace].storageType}`);
1114
1112
  writeOnePointForID(adapter, pointId, point, true, cb);
1115
1113
  const obj = {};
1116
1114
  obj.common = {};
@@ -1119,7 +1117,7 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1119
1117
  obj.common.custom[adapter.namespace].storageType = adapter._influxDPs[pointId][adapter.namespace].storageType;
1120
1118
  adapter.extendForeignObject(pointId, obj, err => {
1121
1119
  if (err) {
1122
- adapter.log.error('error updating history config for ' + pointId + ' to pin datatype: ' + err);
1120
+ adapter.log.error(`error updating history config for ${pointId} to pin datatype: ${err}`);
1123
1121
  } else {
1124
1122
  adapter.log.info('changed history configuration to pin detected datatype for ' + pointId);
1125
1123
  }
@@ -1129,7 +1127,7 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1129
1127
  if (!directWrite || !retry) {
1130
1128
  // remember this as a pot. conflicting point and write synchronous
1131
1129
  adapter._conflictingPoints[pointId]=1;
1132
- adapter.log.warn('Add ' + pointId + ' to conflicting Points (' + Object.keys(adapter._conflictingPoints).length + ' now)');
1130
+ adapter.log.warn(`Add ${pointId} to conflicting Points (${Object.keys(adapter._conflictingPoints).length} now)`);
1133
1131
  }
1134
1132
  } else {
1135
1133
  if (!adapter._errorPoints[pointId]) {
@@ -1139,10 +1137,10 @@ function writeOnePointForID(adapter, pointId, point, directWrite, cb) {
1139
1137
  }
1140
1138
  if (adapter._errorPoints[pointId] < 10) {
1141
1139
  // re-add that point to buffer to try write again
1142
- adapter.log.info('Add point that had error for ' + pointId + ' to buffer again, error-count=' + adapter._errorPoints[pointId]);
1140
+ adapter.log.info(`Add point that had error for ${pointId} to buffer again, error-count=${adapter._errorPoints[pointId]}`);
1143
1141
  addPointToSeriesBuffer(adapter, pointId, point);
1144
1142
  } else {
1145
- adapter.log.info('Discard point that had error for ' + pointId + ', error-count=' + adapter._errorPoints[pointId]);
1143
+ adapter.log.info(`Discard point that had error for ${pointId}, error-count=${adapter._errorPoints[pointId]}`);
1146
1144
  adapter._errorPoints[pointId] = 0;
1147
1145
  }
1148
1146
  }
@@ -1162,10 +1160,10 @@ function writeFileBufferToDisk() {
1162
1160
  fileData.conflictingPoints = adapter._conflictingPoints;
1163
1161
  try {
1164
1162
  fs.writeFileSync(cacheFile, JSON.stringify(fileData), 'utf-8');
1165
- adapter.log.warn('Store data for ' + fileData.seriesBufferCounter + ' points and ' + Object.keys(fileData.conflictingPoints).length + ' conflicts');
1163
+ adapter.log.warn(`Store data for ${fileData.seriesBufferCounter} points and ${Object.keys(fileData.conflictingPoints).length} conflicts`);
1166
1164
  }
1167
1165
  catch (err) {
1168
- adapter.log.warn('Could not save unstored data to file: ' + err);
1166
+ adapter.log.warn('Could not save non-stored data to file: ' + err);
1169
1167
  }
1170
1168
  }
1171
1169
  adapter._seriesBufferCounter = null;
@@ -1250,7 +1248,6 @@ function finish(adapter, callback) {
1250
1248
  }
1251
1249
 
1252
1250
  function getHistory(adapter, msg) {
1253
-
1254
1251
  const options = {
1255
1252
  id: msg.message.id === '*' ? null : msg.message.id,
1256
1253
  start: msg.message.options.start,
@@ -1263,9 +1260,11 @@ function getHistory(adapter, msg) {
1263
1260
  ignoreNull: true,
1264
1261
  sessionId: msg.message.options.sessionId
1265
1262
  };
1263
+
1266
1264
  if (options.id && adapter._aliasMap[options.id]) {
1267
1265
  options.id = adapter._aliasMap[options.id];
1268
1266
  }
1267
+
1269
1268
  let query = 'SELECT';
1270
1269
  if (options.step) {
1271
1270
  switch (options.aggregate) {
@@ -1358,7 +1357,7 @@ function getHistory(adapter, msg) {
1358
1357
 
1359
1358
  // select one datapoint more then wanted
1360
1359
  if (options.aggregate === 'minmax' || options.aggregate === 'onchange' || options.aggregate === 'none') {
1361
- let addQuery = "";
1360
+ let addQuery = '';
1362
1361
  if (options.start) {
1363
1362
  addQuery = 'SELECT value from "' + options.id + '"' + " WHERE time <= '" + new Date(options.start).toISOString() + "' ORDER BY time DESC LIMIT 1;";
1364
1363
  query = addQuery + query;
@@ -1379,7 +1378,7 @@ function getHistory(adapter, msg) {
1379
1378
  } else {
1380
1379
  setConnected(adapter, true);
1381
1380
  }
1382
- adapter.log.debug("ROWS:" + JSON.stringify(rows));
1381
+ adapter.log.debug('ROWS:' + JSON.stringify(rows));
1383
1382
  let result = [];
1384
1383
  if (rows && rows.length) {
1385
1384
  for (let qr = 0; qr < rows.length; qr++) {
@@ -1421,7 +1420,6 @@ function getHistory(adapter, msg) {
1421
1420
  }
1422
1421
 
1423
1422
  function getHistoryIflx2(adapter, msg) {
1424
-
1425
1423
  const options = {
1426
1424
  id: msg.message.id === '*' ? null : msg.message.id,
1427
1425
  start: msg.message.options.start,
@@ -1434,13 +1432,14 @@ function getHistoryIflx2(adapter, msg) {
1434
1432
  ignoreNull: true,
1435
1433
  sessionId: msg.message.options.sessionId
1436
1434
  };
1435
+
1437
1436
  if (options.id && adapter._aliasMap[options.id]) {
1438
1437
  options.id = adapter._aliasMap[options.id];
1439
1438
  }
1440
1439
  const fluxQueries = [];
1441
1440
  let fluxQuery = 'from(bucket: "' + adapter.config.dbname + '") ';
1442
1441
 
1443
- const valueColumn = (adapter.config.usetags) ? "_value" : "value";
1442
+ const valueColumn = adapter.config.usetags ? '_value' : 'value';
1444
1443
 
1445
1444
  if (!adapter._influxDPs[options.id]) {
1446
1445
  adapter.sendTo(msg.from, msg.command, {
@@ -1507,7 +1506,7 @@ function getHistoryIflx2(adapter, msg) {
1507
1506
  adapter._client.query(booleanTypeCheckQuery, (error, _rslt) => {
1508
1507
  let isBoolean;
1509
1508
  if (error) {
1510
- if (error.message.match(".*type conflict: bool.*"))
1509
+ if (error.message.match('.*type conflict: bool.*'))
1511
1510
  isBoolean = false;
1512
1511
  else {
1513
1512
  adapter.sendTo(msg.from, msg.command, {
@@ -1519,7 +1518,7 @@ function getHistoryIflx2(adapter, msg) {
1519
1518
  }
1520
1519
  } else {
1521
1520
  isBoolean = true;
1522
- adapter.log.debug("Measurement " + options.id + " is of type Boolean - skipping aggregation options");
1521
+ adapter.log.debug(`Measurement ${options.id} is of type Boolean - skipping aggregation options`);
1523
1522
  }
1524
1523
 
1525
1524
 
@@ -1556,7 +1555,7 @@ function getHistoryIflx2(adapter, msg) {
1556
1555
 
1557
1556
  // select one datapoint more then wanted
1558
1557
  if (options.aggregate === 'minmax' || options.aggregate === 'onchange' || options.aggregate === 'none') {
1559
- let addFluxQuery = "";
1558
+ let addFluxQuery = '';
1560
1559
  if (options.start) {
1561
1560
  // get one entry "before" the defined timeframe for displaying purposes
1562
1561
  addFluxQuery = 'from(bucket: "' + adapter.config.dbname + '") \
@@ -1583,7 +1582,7 @@ function getHistoryIflx2(adapter, msg) {
1583
1582
  fluxQueries.push(addFluxQuery);
1584
1583
  }
1585
1584
 
1586
- adapter.log.debug("History-queries to execute: " + fluxQueries);
1585
+ adapter.log.debug('History-queries to execute: ' + fluxQueries);
1587
1586
 
1588
1587
  // if specific id requested
1589
1588
  adapter._client.queries(fluxQueries, (err, rows) => {
@@ -1595,7 +1594,7 @@ function getHistoryIflx2(adapter, msg) {
1595
1594
  } else {
1596
1595
  setConnected(adapter, true);
1597
1596
  }
1598
- adapter.log.debug("Parsing retrieved rows:" + JSON.stringify(rows));
1597
+ adapter.log.debug('Parsing retrieved rows:' + JSON.stringify(rows));
1599
1598
  let result = [];
1600
1599
  if (rows && rows.length) {
1601
1600
  for (let qr = 0; qr < rows.length; qr++) {
@@ -1704,15 +1703,15 @@ function multiQuery(adapter, msg) {
1704
1703
  for (const query of queries) {
1705
1704
  if (!query || typeof query !== 'string') {
1706
1705
  throw {
1707
- name: "Exception",
1708
- message: "Array element #"+ c +": Query messing",
1709
- toString: function() { return this.name + ": " + this.message; }
1706
+ name: 'Exception',
1707
+ message: `Array element #${c}: Query messing`,
1708
+ toString: function () { return `${this.name}: ${this.message}`; }
1710
1709
  }
1711
1710
  }
1712
1711
  c++;
1713
1712
  }
1714
1713
  } catch (error) {
1715
- adapter.log.warn("Error in received multiQuery: " + error);
1714
+ adapter.log.warn('Error in received multiQuery: ' + error);
1716
1715
  adapter.sendTo(msg.from, msg.command, {
1717
1716
  result: [],
1718
1717
  error: error
@@ -1764,26 +1763,26 @@ function storeState(adapter, msg) {
1764
1763
  if (!msg.message || !msg.message.id || !msg.message.state) {
1765
1764
  adapter.log.error('storeState called with invalid data');
1766
1765
  adapter.sendTo(msg.from, msg.command, {
1767
- error: 'Invalid call'
1766
+ error: 'Invalid call'
1768
1767
  }, msg.callback);
1769
1768
  return;
1770
1769
  }
1771
1770
 
1772
1771
  let id;
1773
1772
  if (Array.isArray(msg.message)) {
1774
- adapter.log.debug('storeState: store ' + msg.message.length + ' states for multiple ids');
1773
+ adapter.log.debug(`storeState: store ${msg.message.length} states for multiple ids`);
1775
1774
  for (let i = 0; i < msg.message.length; i++) {
1776
1775
  id = adapter._aliasMap[msg.message[i].id] ? adapter._aliasMap[msg.message[i].id] : msg.message[i].id;
1777
1776
  pushValueIntoDB(adapter, id, msg.message[i].state);
1778
1777
  }
1779
1778
  } else if (Array.isArray(msg.message.state)) {
1780
- adapter.log.debug('storeState: store ' + msg.message.state.length + ' states for ' + msg.message.id);
1779
+ adapter.log.debug(`storeState: store ${msg.message.state.length} states for ${msg.message.id}`);
1781
1780
  for (let j = 0; j < msg.message.state.length; j++) {
1782
1781
  id = adapter._aliasMap[msg.message.id] ? adapter._aliasMap[msg.message.id] : msg.message.id;
1783
1782
  pushValueIntoDB(adapter, id, msg.message.state[j]);
1784
1783
  }
1785
1784
  } else {
1786
- adapter.log.debug('storeState: store 1 state for ' + msg.message.id);
1785
+ adapter.log.debug(`storeState: store 1 state for ${msg.message.id}`);
1787
1786
  id = adapter._aliasMap[msg.message.id] ? adapter._aliasMap[msg.message.id] : msg.message.id;
1788
1787
  pushValueIntoDB(adapter, id, msg.message.state);
1789
1788
  }
@@ -1799,9 +1798,7 @@ function storeState(adapter, msg) {
1799
1798
  function enableHistory(adapter, msg) {
1800
1799
  if (!msg.message || !msg.message.id) {
1801
1800
  adapter.log.error('enableHistory called with invalid data');
1802
- adapter.sendTo(msg.from, msg.command, {
1803
- error: 'Invalid call'
1804
- }, msg.callback);
1801
+ adapter.sendTo(msg.from, msg.command, {error: 'Invalid call'}, msg.callback);
1805
1802
  return;
1806
1803
  }
1807
1804
  const obj = {};
@@ -1827,9 +1824,7 @@ function enableHistory(adapter, msg) {
1827
1824
  function disableHistory(adapter, msg) {
1828
1825
  if (!msg.message || !msg.message.id) {
1829
1826
  adapter.log.error('disableHistory called with invalid data');
1830
- adapter.sendTo(msg.from, msg.command, {
1831
- error: 'Invalid call'
1832
- }, msg.callback);
1827
+ adapter.sendTo(msg.from, msg.command, {error: 'Invalid call'}, msg.callback);
1833
1828
  return;
1834
1829
  }
1835
1830
  const obj = {};
@@ -1855,7 +1850,9 @@ function disableHistory(adapter, msg) {
1855
1850
  function getEnabledDPs(adapter, msg) {
1856
1851
  const data = {};
1857
1852
  for (const id in adapter._influxDPs) {
1858
- if (!adapter._influxDPs.hasOwnProperty(id)) continue;
1853
+ if (!adapter._influxDPs.hasOwnProperty(id)) {
1854
+ continue;
1855
+ }
1859
1856
  data[adapter._influxDPs[id].realId] = adapter._influxDPs[id][adapter.namespace];
1860
1857
  }
1861
1858