iobroker.sql 1.15.6 → 1.16.2
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/LICENSE +1 -1
- package/README.md +36 -21
- package/admin/.gitignore +0 -0
- package/admin/i18n/de/translations.json +47 -0
- package/admin/i18n/en/translations.json +47 -0
- package/admin/i18n/es/translations.json +47 -0
- package/admin/i18n/fr/translations.json +47 -0
- package/admin/i18n/it/translations.json +47 -0
- package/admin/i18n/nl/translations.json +47 -0
- package/admin/i18n/pl/translations.json +47 -0
- package/admin/i18n/pt/translations.json +47 -0
- package/admin/i18n/ru/translations.json +47 -0
- package/admin/i18n/zh-cn/translations.json +47 -0
- package/admin/jsonCustom.json +138 -56
- package/admin/words.js +37 -44
- package/io-package.json +207 -221
- package/lib/aggregate.js +25 -17
- package/main.js +155 -152
- package/package.json +23 -10
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/auto-merge.yml +0 -17
- package/.github/dependabot.yml +0 -16
- package/.github/stale.yml +0 -78
- package/.github/workflows/dependabot-automerge.yml +0 -22
- package/.github/workflows/test-and-release.yml +0 -159
package/main.js
CHANGED
|
@@ -120,7 +120,7 @@ function startAdapter(options) {
|
|
|
120
120
|
id = aliasMap[id];
|
|
121
121
|
checkForRemove = false;
|
|
122
122
|
} else {
|
|
123
|
-
adapter.log.warn(
|
|
123
|
+
adapter.log.warn(`Ignoring Alias-ID because identical to ID for ${id}`);
|
|
124
124
|
obj.common.custom[adapter.namespace].aliasId = '';
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -160,7 +160,7 @@ function startAdapter(options) {
|
|
|
160
160
|
}
|
|
161
161
|
} else {
|
|
162
162
|
if (aliasMap[id]) {
|
|
163
|
-
adapter.log.debug(
|
|
163
|
+
adapter.log.debug(`Removed Alias: ${id} !-> ${aliasMap[id]}`);
|
|
164
164
|
delete aliasMap[id];
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -188,10 +188,10 @@ function startAdapter(options) {
|
|
|
188
188
|
_state.from = 'system.adapter.' + adapter.namespace;
|
|
189
189
|
nullValue.ts += 4;
|
|
190
190
|
nullValue.lc += 4; // because of MS SQL
|
|
191
|
-
adapter.log.debug(
|
|
191
|
+
adapter.log.debug(`Write 1/2 "${_state.val}" _id: ${_id}`);
|
|
192
192
|
pushValueIntoDB(_id, _state, () => {
|
|
193
193
|
// terminate values with null to indicate adapter stop. timestamp + 1#
|
|
194
|
-
adapter.log.debug(
|
|
194
|
+
adapter.log.debug(`Write 2/2 "null" _id: ${_id}`);
|
|
195
195
|
pushValueIntoDB(_id, _nullValue, () => delete sqlDPs[id][adapter.namespace]);
|
|
196
196
|
});
|
|
197
197
|
})(id, state, nullValue);
|
|
@@ -269,6 +269,9 @@ function reInit(id, realId, formerAliasId, storedIndex, storedType, obj) {
|
|
|
269
269
|
// changesOnly
|
|
270
270
|
obj.common.custom[adapter.namespace].changesOnly = obj.common.custom[adapter.namespace].changesOnly === 'true' || obj.common.custom[adapter.namespace].changesOnly === true;
|
|
271
271
|
|
|
272
|
+
obj.common.custom[adapter.namespace].ignoreZero = obj.common.custom[adapter.namespace].ignoreZero === 'true' || obj.common.custom[adapter.namespace].ignoreZero === true;
|
|
273
|
+
obj.common.custom[adapter.namespace].ignoreBelowZero = obj.common.custom[adapter.namespace].ignoreBelowZero === 'true' || obj.common.custom[adapter.namespace].ignoreBelowZero === true;
|
|
274
|
+
|
|
272
275
|
if (obj.common.custom[adapter.namespace].changesRelogInterval || obj.common.custom[adapter.namespace].changesRelogInterval === 0) {
|
|
273
276
|
obj.common.custom[adapter.namespace].changesRelogInterval = parseInt(obj.common.custom[adapter.namespace].changesRelogInterval, 10) || 0;
|
|
274
277
|
} else {
|
|
@@ -295,7 +298,7 @@ function reInit(id, realId, formerAliasId, storedIndex, storedType, obj) {
|
|
|
295
298
|
if (sqlDPs[formerAliasId] &&
|
|
296
299
|
sqlDPs[formerAliasId][adapter.namespace] &&
|
|
297
300
|
isEqual(obj.common.custom[adapter.namespace], sqlDPs[formerAliasId][adapter.namespace])) {
|
|
298
|
-
return adapter.log.debug(
|
|
301
|
+
return adapter.log.debug(`Object ${id} unchanged. Ignore`);
|
|
299
302
|
}
|
|
300
303
|
|
|
301
304
|
// relogTimeout
|
|
@@ -317,7 +320,7 @@ function reInit(id, realId, formerAliasId, storedIndex, storedType, obj) {
|
|
|
317
320
|
writeNulls(id);
|
|
318
321
|
}
|
|
319
322
|
|
|
320
|
-
adapter.log.info(
|
|
323
|
+
adapter.log.info(`enabled logging of ${id}, Alias=${id !== realId}`);
|
|
321
324
|
}
|
|
322
325
|
|
|
323
326
|
function setConnected(isConnected) {
|
|
@@ -339,7 +342,7 @@ function connect(callback) {
|
|
|
339
342
|
|
|
340
343
|
let params = {
|
|
341
344
|
server: adapter.config.host, // needed for MSSQL
|
|
342
|
-
host: adapter.config.host, // needed for
|
|
345
|
+
host: adapter.config.host, // needed for PostgreSQL , MySQL
|
|
343
346
|
user: adapter.config.user || '',
|
|
344
347
|
password: adapter.config.password || '',
|
|
345
348
|
max_idle: (adapter.config.dbtype === 'sqlite') ? 1 : 2
|
|
@@ -359,10 +362,10 @@ function connect(callback) {
|
|
|
359
362
|
return adapter.log.error('DB Type is not defined!');
|
|
360
363
|
} else
|
|
361
364
|
if (!clients[adapter.config.dbtype] || !clients[adapter.config.dbtype].name) {
|
|
362
|
-
return adapter.log.error(
|
|
365
|
+
return adapter.log.error(`Unknown type "${adapter.config.dbtype}"`);
|
|
363
366
|
} else
|
|
364
367
|
if (!SQL[clients[adapter.config.dbtype].name]) {
|
|
365
|
-
return adapter.log.error(
|
|
368
|
+
return adapter.log.error(`SQL package "${clients[adapter.config.dbtype].name}" is not installed.`);
|
|
366
369
|
}
|
|
367
370
|
|
|
368
371
|
if (adapter.config.dbtype !== 'postgresql') {
|
|
@@ -423,9 +426,9 @@ function connect(callback) {
|
|
|
423
426
|
|
|
424
427
|
try {
|
|
425
428
|
if (!clients[adapter.config.dbtype].name) {
|
|
426
|
-
adapter.log.error(
|
|
429
|
+
adapter.log.error(`Unknown SQL type selected: "${adapter.config.dbtype}"`);
|
|
427
430
|
} else if (!SQL[clients[adapter.config.dbtype].name + 'Pool']) {
|
|
428
|
-
adapter.log.error(
|
|
431
|
+
adapter.log.error(`Selected SQL DB was not installed properly: "${adapter.config.dbtype}". SQLite requires build tools on system. See README.md`);
|
|
429
432
|
} else {
|
|
430
433
|
clientPool = new SQL[clients[adapter.config.dbtype].name + 'Pool'](params);
|
|
431
434
|
|
|
@@ -444,7 +447,7 @@ function connect(callback) {
|
|
|
444
447
|
}
|
|
445
448
|
} catch (ex) {
|
|
446
449
|
if (ex.toString() === 'TypeError: undefined is not a function') {
|
|
447
|
-
adapter.log.error(
|
|
450
|
+
adapter.log.error(`Node.js DB driver for "${adapter.config.dbtype}" could not be installed.`);
|
|
448
451
|
} else {
|
|
449
452
|
adapter.log.error(ex.toString());
|
|
450
453
|
adapter.log.error(ex.stack);
|
|
@@ -679,7 +682,7 @@ function oneScript(script, cb) {
|
|
|
679
682
|
else if (err.code === '42P07') {
|
|
680
683
|
const match = script.match(/CREATE\s+TABLE\s+(\w*)\s+\(/);
|
|
681
684
|
if (match) {
|
|
682
|
-
adapter.log.debug(
|
|
685
|
+
adapter.log.debug(`OK. Table "${match[1]}" yet exists`);
|
|
683
686
|
err = null;
|
|
684
687
|
} else {
|
|
685
688
|
adapter.log.error(script);
|
|
@@ -688,7 +691,7 @@ function oneScript(script, cb) {
|
|
|
688
691
|
} else if (script.startsWith('CREATE INDEX')) {
|
|
689
692
|
adapter.log.info('Ignore Error on Create index. You might want to create the index yourself!');
|
|
690
693
|
adapter.log.info(script);
|
|
691
|
-
adapter.log.info(err.code
|
|
694
|
+
adapter.log.info(`${err.code}: ${err}`);
|
|
692
695
|
err = null;
|
|
693
696
|
} else {
|
|
694
697
|
adapter.log.error(script);
|
|
@@ -776,10 +779,10 @@ function finish(callback) {
|
|
|
776
779
|
_state.from = 'system.adapter.' + adapter.namespace;
|
|
777
780
|
nullValue.ts += 4;
|
|
778
781
|
nullValue.lc += 4; // because of MS SQL
|
|
779
|
-
adapter.log.debug(
|
|
782
|
+
adapter.log.debug(`Write 1/2 "${_state.val}" _id: ${_id}`);
|
|
780
783
|
pushValueIntoDB(_id, _state, () => {
|
|
781
784
|
// terminate values with null to indicate adapter stop. timestamp + 1#
|
|
782
|
-
adapter.log.debug(
|
|
785
|
+
adapter.log.debug(`Write 2/2 "null" _id: ${_id}`);
|
|
783
786
|
pushValueIntoDB(_id, _nullValue, () => {
|
|
784
787
|
if (!--count) {
|
|
785
788
|
if (clientPool) {
|
|
@@ -880,7 +883,7 @@ function finish(callback) {
|
|
|
880
883
|
|
|
881
884
|
function processMessage(msg) {
|
|
882
885
|
if (msg.command === 'features') {
|
|
883
|
-
adapter.sendTo(msg.from, msg.command, {supportedFeatures: ['update', 'delete', 'deleteRange', 'deleteAll']}, msg.callback);
|
|
886
|
+
adapter.sendTo(msg.from, msg.command, {supportedFeatures: ['update', 'delete', 'deleteRange', 'deleteAll', 'storeState']}, msg.callback);
|
|
884
887
|
} else
|
|
885
888
|
if (msg.command === 'getHistory') {
|
|
886
889
|
getHistory(msg);
|
|
@@ -933,26 +936,6 @@ function processMessage(msg) {
|
|
|
933
936
|
}
|
|
934
937
|
}
|
|
935
938
|
|
|
936
|
-
function fixSelector(callback) {
|
|
937
|
-
// fix _design/custom object
|
|
938
|
-
adapter.getForeignObject('_design/custom', (err, obj) => {
|
|
939
|
-
if (!obj || !obj.views.state.map.includes('common.custom')) {
|
|
940
|
-
obj = {
|
|
941
|
-
_id: '_design/custom',
|
|
942
|
-
language: 'javascript',
|
|
943
|
-
views: {
|
|
944
|
-
state: {
|
|
945
|
-
map: 'function(doc) { doc.type === \'state\' && doc.common.custom && emit(doc._id, doc.common.custom) }'
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
adapter.setForeignObject('_design/custom', obj, err => callback && callback(err));
|
|
950
|
-
} else {
|
|
951
|
-
callback && callback(err);
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
|
|
956
939
|
function processStartValues(callback) {
|
|
957
940
|
if (tasksStart && tasksStart.length) {
|
|
958
941
|
const task = tasksStart.shift();
|
|
@@ -1171,7 +1154,7 @@ function pushHelper(_id, timeoutTriggered) {
|
|
|
1171
1154
|
}
|
|
1172
1155
|
|
|
1173
1156
|
if (sqlDPs[_id].state.val !== null && sqlDPs[_id].state.val !== undefined) {
|
|
1174
|
-
adapter.log.debug(
|
|
1157
|
+
adapter.log.debug(`Datatype ${_id}: Currently: ${typeof sqlDPs[_id].state.val}, StorageType: ${_settings.storageType}`);
|
|
1175
1158
|
|
|
1176
1159
|
if (typeof sqlDPs[_id].state.val === 'string' && _settings.storageType !== 'String') {
|
|
1177
1160
|
adapter.log.debug('Do Automatic Datatype conversion for ' + _id);
|
|
@@ -1330,7 +1313,7 @@ function _insertValueIntoDB(query, id, cb) {
|
|
|
1330
1313
|
borrowClientFromPool((err, client) => {
|
|
1331
1314
|
if (err) {
|
|
1332
1315
|
adapter.log.error(err);
|
|
1333
|
-
cb && cb();
|
|
1316
|
+
cb && cb(); // BF asked (2021.12.14): may be return here err?
|
|
1334
1317
|
} else {
|
|
1335
1318
|
client.execute(query, (err /* , rows, fields */) => {
|
|
1336
1319
|
returnClientToPool(client);
|
|
@@ -1339,7 +1322,7 @@ function _insertValueIntoDB(query, id, cb) {
|
|
|
1339
1322
|
} else {
|
|
1340
1323
|
checkRetention(id);
|
|
1341
1324
|
}
|
|
1342
|
-
cb && cb();
|
|
1325
|
+
cb && cb(); // BF asked (2021.12.14): may be return here err?
|
|
1343
1326
|
});
|
|
1344
1327
|
}
|
|
1345
1328
|
});
|
|
@@ -1589,6 +1572,15 @@ function pushValueIntoDB(id, state, isCounter, cb) {
|
|
|
1589
1572
|
isCounter = false;
|
|
1590
1573
|
}
|
|
1591
1574
|
|
|
1575
|
+
if (sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id][adapter.namespace].ignoreZero && (!state || state.val === undefined || state.val === null || state.val === 0)) {
|
|
1576
|
+
adapter.log.debug(`pushValueIntoDB called for ${id} (type: ${sqlDPs[id].type}, ID: ${sqlDPs[id].index}) and state: ${JSON.stringify(state)} and it was ignored because the value zero or null`);
|
|
1577
|
+
return cb && cb();
|
|
1578
|
+
} else
|
|
1579
|
+
if (state && sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id][adapter.namespace].ignoreBelowZero && typeof state.val === 'number' && state.val < 0) {
|
|
1580
|
+
adapter.log.debug(`pushValueIntoDB called for ${id} (type: ${sqlDPs[id].type}, ID: ${sqlDPs[id].index}) and state: ${JSON.stringify(state)} and it was ignored because the value is below 0`);
|
|
1581
|
+
return cb && cb();
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1592
1584
|
adapter.log.debug(`pushValueIntoDB called for ${id} (type: ${sqlDPs[id].type}, ID: ${sqlDPs[id].index}) and state: ${JSON.stringify(state)}`);
|
|
1593
1585
|
|
|
1594
1586
|
prepareTaskCheckTypeAndDbId(id, state, isCounter, err => {
|
|
@@ -1611,7 +1603,7 @@ function pushValueIntoDB(id, state, isCounter, cb) {
|
|
|
1611
1603
|
|
|
1612
1604
|
if (!multiRequests) {
|
|
1613
1605
|
if (tasks.length > MAXTASKS) {
|
|
1614
|
-
const error = 'Cannot queue new requests, because more than '+MAXTASKS;
|
|
1606
|
+
const error = 'Cannot queue new requests, because more than ' + MAXTASKS;
|
|
1615
1607
|
adapter.log.error(error);
|
|
1616
1608
|
cb && cb(error);
|
|
1617
1609
|
} else {
|
|
@@ -1982,12 +1974,12 @@ function getHistory(msg) {
|
|
|
1982
1974
|
if (sqlDPs[options.id].type === undefined && sqlDPs[options.id].dbtype !== undefined) {
|
|
1983
1975
|
if (sqlDPs[options.id][adapter.namespace] && sqlDPs[options.id][adapter.namespace].storageType) {
|
|
1984
1976
|
if (storageTypes.indexOf(sqlDPs[options.id][adapter.namespace].storageType) === sqlDPs[options.id].dbtype) {
|
|
1985
|
-
adapter.log.debug(
|
|
1977
|
+
adapter.log.debug(`For getHistory for id ${options.id}: Type empty, use storageType dbtype ${sqlDPs[options.id].dbtype}`);
|
|
1986
1978
|
sqlDPs[options.id].type = sqlDPs[options.id].dbtype;
|
|
1987
1979
|
}
|
|
1988
1980
|
}
|
|
1989
1981
|
else {
|
|
1990
|
-
adapter.log.debug(
|
|
1982
|
+
adapter.log.debug(`For getHistory for id ${options.id}: Type empty, use dbtype ${sqlDPs[options.id].dbtype}`);
|
|
1991
1983
|
sqlDPs[options.id].type = sqlDPs[options.id].dbtype;
|
|
1992
1984
|
}
|
|
1993
1985
|
}
|
|
@@ -1995,7 +1987,7 @@ function getHistory(msg) {
|
|
|
1995
1987
|
// read or create in DB
|
|
1996
1988
|
return getId(options.id, null, err => {
|
|
1997
1989
|
if (err) {
|
|
1998
|
-
adapter.log.warn(
|
|
1990
|
+
adapter.log.warn(`Cannot get index of "${options.id}": ${err}`);
|
|
1999
1991
|
commons.sendResponse(adapter, msg, options, [], startTime);
|
|
2000
1992
|
} else {
|
|
2001
1993
|
getHistory(msg);
|
|
@@ -2003,7 +1995,7 @@ function getHistory(msg) {
|
|
|
2003
1995
|
});
|
|
2004
1996
|
}
|
|
2005
1997
|
if (options.id && sqlDPs[options.id].type === undefined) {
|
|
2006
|
-
adapter.log.warn(
|
|
1998
|
+
adapter.log.warn(`For getHistory for id "${options.id}": Type empty. Need to write data first. Index = ${sqlDPs[options.id].index}`);
|
|
2007
1999
|
commons.sendResponse(adapter, msg, options, 'Please wait till next data record is logged and reload.', startTime);
|
|
2008
2000
|
return;
|
|
2009
2001
|
}
|
|
@@ -2293,7 +2285,7 @@ function storeState(msg) {
|
|
|
2293
2285
|
if (msg.message.state[j] && typeof msg.message.state[j] === 'object') {
|
|
2294
2286
|
pushFunc(id, msg.message.state[j]);
|
|
2295
2287
|
} else {
|
|
2296
|
-
adapter.log.warn(
|
|
2288
|
+
adapter.log.warn(`Invalid state for ${JSON.stringify(msg.message.state[j])}`);
|
|
2297
2289
|
}
|
|
2298
2290
|
}
|
|
2299
2291
|
} else if (msg.message.id && msg.message.state && typeof msg.message.state === 'object') {
|
|
@@ -2303,7 +2295,7 @@ function storeState(msg) {
|
|
|
2303
2295
|
} else {
|
|
2304
2296
|
adapter.log.error('storeState called with invalid data');
|
|
2305
2297
|
return adapter.sendTo(msg.from, msg.command, {
|
|
2306
|
-
error:
|
|
2298
|
+
error: `Invalid call: ${JSON.stringify(msg)}`
|
|
2307
2299
|
}, msg.callback);
|
|
2308
2300
|
}
|
|
2309
2301
|
|
|
@@ -2321,7 +2313,7 @@ function getDpOverview(msg) {
|
|
|
2321
2313
|
borrowClientFromPool((err, client) => {
|
|
2322
2314
|
if (err) {
|
|
2323
2315
|
return adapter.sendTo(msg.from, msg.command, {
|
|
2324
|
-
error:
|
|
2316
|
+
error: `Cannot select ${query}: ${err}`
|
|
2325
2317
|
}, msg.callback);
|
|
2326
2318
|
}
|
|
2327
2319
|
client.execute(query, (err, rows /* , fields */) => {
|
|
@@ -2331,9 +2323,10 @@ function getDpOverview(msg) {
|
|
|
2331
2323
|
if (err) {
|
|
2332
2324
|
returnClientToPool(client);
|
|
2333
2325
|
|
|
2334
|
-
adapter.log.error(
|
|
2326
|
+
adapter.log.error(`Cannot select ${query}: ${err}`);
|
|
2327
|
+
|
|
2335
2328
|
adapter.sendTo(msg.from, msg.command, {
|
|
2336
|
-
error:
|
|
2329
|
+
error: `Cannot select ${query}: ${err}`
|
|
2337
2330
|
}, msg.callback);
|
|
2338
2331
|
return;
|
|
2339
2332
|
}
|
|
@@ -2342,11 +2335,15 @@ function getDpOverview(msg) {
|
|
|
2342
2335
|
|
|
2343
2336
|
if (rows.length) {
|
|
2344
2337
|
for (let r = 0; r < rows.length; r++) {
|
|
2345
|
-
if (!result[rows[r].type])
|
|
2338
|
+
if (!result[rows[r].type]) {
|
|
2339
|
+
result[rows[r].type] = {};
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2346
2342
|
result[rows[r].type][rows[r].id] = {};
|
|
2347
2343
|
|
|
2348
2344
|
result[rows[r].type][rows[r].id].name = rows[r].name;
|
|
2349
|
-
|
|
2345
|
+
|
|
2346
|
+
switch (dbNames[rows[r].type]) {
|
|
2350
2347
|
case 'ts_number':
|
|
2351
2348
|
result[rows[r].type][rows[r].id].type = 'number';
|
|
2352
2349
|
break;
|
|
@@ -2384,14 +2381,14 @@ function getFirstTsForIds(dbClient, typeId, resultData, msg) {
|
|
|
2384
2381
|
if (err) {
|
|
2385
2382
|
returnClientToPool(dbClient);
|
|
2386
2383
|
|
|
2387
|
-
adapter.log.error(
|
|
2384
|
+
adapter.log.error(`Cannot select ${query}: ${err}`);
|
|
2388
2385
|
adapter.sendTo(msg.from, msg.command, {
|
|
2389
|
-
error:
|
|
2386
|
+
error: `Cannot select ${query}: ${err}`
|
|
2390
2387
|
}, msg.callback);
|
|
2391
2388
|
return;
|
|
2392
2389
|
}
|
|
2393
2390
|
|
|
2394
|
-
adapter.log.info(
|
|
2391
|
+
adapter.log.info(`Query result ${JSON.stringify(rows)}`);
|
|
2395
2392
|
|
|
2396
2393
|
if (rows.length) {
|
|
2397
2394
|
for (let r = 0; r < rows.length; r++) {
|
|
@@ -2401,7 +2398,7 @@ function getFirstTsForIds(dbClient, typeId, resultData, msg) {
|
|
|
2401
2398
|
}
|
|
2402
2399
|
}
|
|
2403
2400
|
|
|
2404
|
-
adapter.log.info(
|
|
2401
|
+
adapter.log.info(`enhanced result (${typeId}): ${JSON.stringify(resultData)}`);
|
|
2405
2402
|
setTimeout(getFirstTsForIds, 5000, dbClient, typeId + 1, resultData, msg);
|
|
2406
2403
|
});
|
|
2407
2404
|
}
|
|
@@ -2413,7 +2410,9 @@ function getFirstTsForIds(dbClient, typeId, resultData, msg) {
|
|
|
2413
2410
|
for (let ti = 0; ti < dbNames.length; ti++ ) {
|
|
2414
2411
|
if (resultData[ti]) {
|
|
2415
2412
|
for (let index in resultData[ti]) {
|
|
2416
|
-
if (!resultData[ti].hasOwnProperty(index))
|
|
2413
|
+
if (!resultData[ti].hasOwnProperty(index)) {
|
|
2414
|
+
continue;
|
|
2415
|
+
}
|
|
2417
2416
|
|
|
2418
2417
|
const id = resultData[ti][index].name;
|
|
2419
2418
|
if (!result[id]) {
|
|
@@ -2441,7 +2440,7 @@ function enableHistory(msg) {
|
|
|
2441
2440
|
if (!msg.message || !msg.message.id) {
|
|
2442
2441
|
adapter.log.error('enableHistory called with invalid data');
|
|
2443
2442
|
adapter.sendTo(msg.from, msg.command, {
|
|
2444
|
-
error:
|
|
2443
|
+
error: 'Invalid call'
|
|
2445
2444
|
}, msg.callback);
|
|
2446
2445
|
return;
|
|
2447
2446
|
}
|
|
@@ -2477,7 +2476,7 @@ function disableHistory(msg) {
|
|
|
2477
2476
|
if (!msg.message || !msg.message.id) {
|
|
2478
2477
|
adapter.log.error('disableHistory called with invalid data');
|
|
2479
2478
|
return adapter.sendTo(msg.from, msg.command, {
|
|
2480
|
-
error:
|
|
2479
|
+
error: 'Invalid call'
|
|
2481
2480
|
}, msg.callback);
|
|
2482
2481
|
}
|
|
2483
2482
|
|
|
@@ -2522,9 +2521,9 @@ function main() {
|
|
|
2522
2521
|
obj.common.defaultHistory = adapter.namespace;
|
|
2523
2522
|
adapter.setForeignObject('system.config', obj, err => {
|
|
2524
2523
|
if (err) {
|
|
2525
|
-
adapter.log.error(
|
|
2524
|
+
adapter.log.error(`Cannot set default history instance: ${err}`);
|
|
2526
2525
|
} else {
|
|
2527
|
-
adapter.log.info(
|
|
2526
|
+
adapter.log.info(`Set default history instance to "${adapter.namespace}"`);
|
|
2528
2527
|
}
|
|
2529
2528
|
});
|
|
2530
2529
|
}
|
|
@@ -2547,7 +2546,7 @@ function main() {
|
|
|
2547
2546
|
}
|
|
2548
2547
|
|
|
2549
2548
|
if (!clients[adapter.config.dbtype]) {
|
|
2550
|
-
adapter.log.error(
|
|
2549
|
+
adapter.log.error(`Unknown DB type: ${adapter.config.dbtype}`);
|
|
2551
2550
|
adapter.stop();
|
|
2552
2551
|
}
|
|
2553
2552
|
if (adapter.config.multiRequests !== undefined && adapter.config.dbtype !== 'SQLite3Client' && adapter.config.dbtype !== 'sqlite') {
|
|
@@ -2601,117 +2600,121 @@ function main() {
|
|
|
2601
2600
|
|
|
2602
2601
|
if (adapter.config.dbtype === 'sqlite' || adapter.config.host) {
|
|
2603
2602
|
connect(() => {
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
}
|
|
2603
|
+
// read all custom settings
|
|
2604
|
+
adapter.getObjectView('system', 'custom' , {}, (err, doc) => {
|
|
2605
|
+
let count = 0;
|
|
2606
|
+
if (doc && doc.rows) {
|
|
2607
|
+
for (let i = 0, l = doc.rows.length; i < l; i++) {
|
|
2608
|
+
if (doc.rows[i].value) {
|
|
2609
|
+
let id = doc.rows[i].id;
|
|
2610
|
+
const realId = id;
|
|
2611
|
+
if (doc.rows[i].value[adapter.namespace] && doc.rows[i].value[adapter.namespace].aliasId) {
|
|
2612
|
+
aliasMap[id] = doc.rows[i].value[adapter.namespace].aliasId;
|
|
2613
|
+
adapter.log.debug(`Found Alias: ${id} --> ${aliasMap[id]}`);
|
|
2614
|
+
id = aliasMap[id];
|
|
2615
|
+
}
|
|
2618
2616
|
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2617
|
+
let storedIndex = null;
|
|
2618
|
+
let storedType = null;
|
|
2619
|
+
if (sqlDPs[id] && sqlDPs[id].index !== undefined) {
|
|
2620
|
+
storedIndex = sqlDPs[id].index;
|
|
2621
|
+
}
|
|
2622
|
+
if (sqlDPs[id] && sqlDPs[id].dbtype !== undefined) {
|
|
2623
|
+
storedType = sqlDPs[id].dbtype;
|
|
2624
|
+
}
|
|
2627
2625
|
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2626
|
+
sqlDPs[id] = doc.rows[i].value;
|
|
2627
|
+
if (storedIndex !== null) {
|
|
2628
|
+
sqlDPs[id].index = storedIndex;
|
|
2629
|
+
}
|
|
2630
|
+
if (storedType !== null) {
|
|
2631
|
+
sqlDPs[id].dbtype = storedType;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
if (!sqlDPs[id][adapter.namespace] || typeof sqlDPs[id][adapter.namespace] !== 'object' || sqlDPs[id][adapter.namespace].enabled === false) {
|
|
2635
|
+
delete sqlDPs[id];
|
|
2636
|
+
} else {
|
|
2637
|
+
count++;
|
|
2638
|
+
adapter.log.info(`enabled logging of ${id}, Alias=${id !== realId}, ${count} points now activated`);
|
|
2639
|
+
|
|
2640
|
+
// retention
|
|
2641
|
+
if (sqlDPs[id][adapter.namespace].retention !== undefined && sqlDPs[id][adapter.namespace].retention !== null && sqlDPs[id][adapter.namespace].retention !== '') {
|
|
2642
|
+
sqlDPs[id][adapter.namespace].retention = parseInt(sqlDPs[id][adapter.namespace].retention, 10) || 0;
|
|
2643
|
+
} else {
|
|
2644
|
+
sqlDPs[id][adapter.namespace].retention = adapter.config.retention;
|
|
2634
2645
|
}
|
|
2635
2646
|
|
|
2636
|
-
|
|
2637
|
-
|
|
2647
|
+
// debounce
|
|
2648
|
+
if (sqlDPs[id][adapter.namespace].debounce !== undefined && sqlDPs[id][adapter.namespace].debounce !== null && sqlDPs[id][adapter.namespace].debounce !== '') {
|
|
2649
|
+
sqlDPs[id][adapter.namespace].debounce = parseInt(sqlDPs[id][adapter.namespace].debounce, 10) || 0;
|
|
2638
2650
|
} else {
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
// retention
|
|
2643
|
-
if (sqlDPs[id][adapter.namespace].retention !== undefined && sqlDPs[id][adapter.namespace].retention !== null && sqlDPs[id][adapter.namespace].retention !== '') {
|
|
2644
|
-
sqlDPs[id][adapter.namespace].retention = parseInt(sqlDPs[id][adapter.namespace].retention, 10) || 0;
|
|
2645
|
-
} else {
|
|
2646
|
-
sqlDPs[id][adapter.namespace].retention = adapter.config.retention;
|
|
2647
|
-
}
|
|
2651
|
+
sqlDPs[id][adapter.namespace].debounce = adapter.config.debounce;
|
|
2652
|
+
}
|
|
2648
2653
|
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
sqlDPs[id][adapter.namespace].debounce = parseInt(sqlDPs[id][adapter.namespace].debounce, 10) || 0;
|
|
2652
|
-
} else {
|
|
2653
|
-
sqlDPs[id][adapter.namespace].debounce = adapter.config.debounce;
|
|
2654
|
-
}
|
|
2654
|
+
// changesOnly
|
|
2655
|
+
sqlDPs[id][adapter.namespace].changesOnly = sqlDPs[id][adapter.namespace].changesOnly === 'true' || sqlDPs[id][adapter.namespace].changesOnly === true;
|
|
2655
2656
|
|
|
2656
|
-
|
|
2657
|
-
|
|
2657
|
+
// ignoreZero
|
|
2658
|
+
sqlDPs[id][adapter.namespace].ignoreZero = sqlDPs[id][adapter.namespace].ignoreZero === 'true' || sqlDPs[id][adapter.namespace].ignoreZero === true;
|
|
2658
2659
|
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
sqlDPs[id][adapter.namespace].changesRelogInterval = parseInt(sqlDPs[id][adapter.namespace].changesRelogInterval, 10) || 0;
|
|
2662
|
-
} else {
|
|
2663
|
-
sqlDPs[id][adapter.namespace].changesRelogInterval = adapter.config.changesRelogInterval;
|
|
2664
|
-
}
|
|
2660
|
+
// ignoreBelowZero
|
|
2661
|
+
sqlDPs[id][adapter.namespace].ignoreBelowZero = sqlDPs[id][adapter.namespace].ignoreBelowZero === 'true' || sqlDPs[id][adapter.namespace].ignoreBelowZero === true;
|
|
2665
2662
|
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2663
|
+
// changesRelogInterval
|
|
2664
|
+
if (sqlDPs[id][adapter.namespace].changesRelogInterval !== undefined && sqlDPs[id][adapter.namespace].changesRelogInterval !== null && sqlDPs[id][adapter.namespace].changesRelogInterval !== '') {
|
|
2665
|
+
sqlDPs[id][adapter.namespace].changesRelogInterval = parseInt(sqlDPs[id][adapter.namespace].changesRelogInterval, 10) || 0;
|
|
2666
|
+
} else {
|
|
2667
|
+
sqlDPs[id][adapter.namespace].changesRelogInterval = adapter.config.changesRelogInterval;
|
|
2668
|
+
}
|
|
2672
2669
|
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2670
|
+
// changesMinDelta
|
|
2671
|
+
if (sqlDPs[id][adapter.namespace].changesMinDelta !== undefined && sqlDPs[id][adapter.namespace].changesMinDelta !== null && sqlDPs[id][adapter.namespace].changesMinDelta !== '') {
|
|
2672
|
+
sqlDPs[id][adapter.namespace].changesMinDelta = parseFloat(sqlDPs[id][adapter.namespace].changesMinDelta) || 0;
|
|
2673
|
+
} else {
|
|
2674
|
+
sqlDPs[id][adapter.namespace].changesMinDelta = adapter.config.changesMinDelta;
|
|
2675
|
+
}
|
|
2677
2676
|
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2677
|
+
// storageType
|
|
2678
|
+
if (!sqlDPs[id][adapter.namespace].storageType) {
|
|
2679
|
+
sqlDPs[id][adapter.namespace].storageType = false;
|
|
2680
|
+
}
|
|
2682
2681
|
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
}
|
|
2682
|
+
// add one day if retention is too small
|
|
2683
|
+
if (sqlDPs[id][adapter.namespace].retention && sqlDPs[id][adapter.namespace].retention <= 604800) {
|
|
2684
|
+
sqlDPs[id][adapter.namespace].retention += 86400;
|
|
2685
|
+
}
|
|
2688
2686
|
|
|
2689
|
-
|
|
2687
|
+
// relogTimeout
|
|
2688
|
+
if (sqlDPs[id][adapter.namespace] && sqlDPs[id][adapter.namespace].changesRelogInterval > 0) {
|
|
2689
|
+
sqlDPs[id].relogTimeout && clearTimeout(sqlDPs[id].relogTimeout);
|
|
2690
|
+
sqlDPs[id].relogTimeout = setTimeout(reLogHelper, (sqlDPs[id][adapter.namespace].changesRelogInterval * 500 * Math.random()) + sqlDPs[id][adapter.namespace].changesRelogInterval * 500, id);
|
|
2690
2691
|
}
|
|
2692
|
+
|
|
2693
|
+
sqlDPs[id].realId = realId;
|
|
2691
2694
|
}
|
|
2692
2695
|
}
|
|
2693
2696
|
}
|
|
2697
|
+
}
|
|
2694
2698
|
|
|
2695
|
-
|
|
2699
|
+
adapter.config.writeNulls && writeNulls();
|
|
2696
2700
|
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2701
|
+
if (count < 200) {
|
|
2702
|
+
Object.keys(sqlDPs).forEach(id =>
|
|
2703
|
+
sqlDPs[id] && sqlDPs[id][adapter.namespace] && !sqlDPs[id].realId && adapter.log.warn(`No realID found for ${id}`));
|
|
2700
2704
|
|
|
2701
|
-
|
|
2702
|
-
|
|
2705
|
+
// BF (2020.05.20) change it later to
|
|
2706
|
+
// adapter.subscribeForeignStates(Object.keys(sqlDPs).forEach(id => sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id].realId).filter(id => id));
|
|
2703
2707
|
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
});
|
|
2708
|
+
Object.keys(sqlDPs).forEach(id =>
|
|
2709
|
+
sqlDPs[id] && sqlDPs[id][adapter.namespace] && sqlDPs[id].realId && adapter.subscribeForeignStates(sqlDPs[id].realId));
|
|
2710
|
+
} else {
|
|
2711
|
+
subscribeAll = true;
|
|
2712
|
+
adapter.subscribeForeignStates('*');
|
|
2713
|
+
}
|
|
2714
|
+
adapter.subscribeForeignObjects('*');
|
|
2715
|
+
adapter.log.debug('Initialization done');
|
|
2716
|
+
setConnected(true);
|
|
2717
|
+
processStartValues();
|
|
2715
2718
|
});
|
|
2716
2719
|
});
|
|
2717
2720
|
}
|