iobroker.smartcontrol 1.2.0 → 1.2.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/.github/ISSUE_TEMPLATE/BugReport.md +36 -36
- package/.github/ISSUE_TEMPLATE/Enhancement.md +19 -19
- package/.github/auto-merge.yml +17 -17
- package/.github/workflows/dependabot-auto-merge.yml +22 -22
- package/.github/workflows/npmpublish.yml +30 -30
- package/.github/workflows/test-and-release.yml +92 -129
- package/.releaseconfig.json +3 -0
- package/LICENSE +21 -21
- package/README.md +374 -402
- package/admin/doc-md/readme.txt +6 -6
- package/admin/doc-md/start_de.md +124 -124
- package/admin/doc-md/start_en.md +126 -126
- package/admin/doc-md/table-conditions_de.md +10 -10
- package/admin/doc-md/table-conditions_en.md +10 -10
- package/admin/doc-md/table-execution_de.md +12 -12
- package/admin/doc-md/table-execution_en.md +12 -12
- package/admin/doc-md/table-target-devices_de.md +18 -18
- package/admin/doc-md/table-target-devices_en.md +21 -21
- package/admin/doc-md/table-target-enums_de.md +13 -13
- package/admin/doc-md/table-target-enums_en.md +15 -15
- package/admin/doc-md/table-target-url_de.md +29 -29
- package/admin/doc-md/table-target-url_en.md +27 -27
- package/admin/doc-md/table-trigger-devices_de.md +12 -12
- package/admin/doc-md/table-trigger-devices_en.md +10 -10
- package/admin/doc-md/table-trigger-motion_de.md +23 -23
- package/admin/doc-md/table-trigger-motion_en.md +24 -24
- package/admin/doc-md/table-trigger-times_de.md +13 -13
- package/admin/doc-md/table-trigger-times_en.md +11 -11
- package/admin/doc-md/table-zones_de.md +14 -14
- package/admin/doc-md/table-zones_en.md +13 -13
- package/admin/doc-md/table-zones_select-targets_de.md +18 -18
- package/admin/doc-md/table-zones_select-targets_en.md +18 -18
- package/admin/index_m.html +1 -1
- package/admin/index_m.js +118 -88
- package/admin/zero-md/webcomponents-loader.min.js +8 -8
- package/admin/zero-md/zero-md.min.js.js +8 -8
- package/io-package.json +461 -433
- package/lib/adapter-config.d.ts +15 -15
- package/lib/constants.js +128 -125
- package/lib/helper.js +1069 -1059
- package/lib/tools.js +93 -93
- package/lib/trigger-class.js +964 -964
- package/main.js +105 -48
- package/main.test.js +30 -30
- package/package.json +73 -70
package/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* ioBroker Smart Control Adapter
|
|
4
4
|
*
|
|
5
|
-
* @github https://github.com/
|
|
5
|
+
* @github https://github.com/iobroker-community-adapters/ioBroker.smartcontrol
|
|
6
6
|
* @forum https://forum.iobroker.net/topic/36728/
|
|
7
7
|
* @author Mic-M <https://github.com/Mic-M/ioBroker.smartcontrol>
|
|
8
8
|
* @license MIT
|
|
@@ -31,6 +31,7 @@ class SmartControl extends utils.Adapter {
|
|
|
31
31
|
|
|
32
32
|
this.on('ready', this._asyncOnReady.bind(this));
|
|
33
33
|
this.on('stateChange', this._asyncOnStateChange.bind(this));
|
|
34
|
+
this.on('message', this._asyncOnMessage.bind(this));
|
|
34
35
|
this.on('unload', this._onUnload.bind(this));
|
|
35
36
|
|
|
36
37
|
|
|
@@ -233,10 +234,18 @@ class SmartControl extends utils.Adapter {
|
|
|
233
234
|
/**
|
|
234
235
|
* Validate Adapter Admin Configuration
|
|
235
236
|
*/
|
|
236
|
-
|
|
237
|
+
const configVerificationResult = await this._asyncVerifyConfig(this.config);
|
|
238
|
+
if (configVerificationResult.passed) {
|
|
239
|
+
this.config = configVerificationResult.obj;
|
|
237
240
|
this.log.info('Adapter admin configuration successfully validated...');
|
|
238
241
|
} else {
|
|
239
|
-
// Error(s) occurred.
|
|
242
|
+
// Error(s) occurred.
|
|
243
|
+
this.log.error(`[User Error (Anwenderfehler)] - ${configVerificationResult.issues.length} error(s) found in adapter configuration. You must fix these issue(s) to use this adapter.`);
|
|
244
|
+
let counter = 0;
|
|
245
|
+
for (const lpMsg of configVerificationResult.issues) {
|
|
246
|
+
counter++;
|
|
247
|
+
this.log.warn(`Issue #${counter}: ${lpMsg}`);
|
|
248
|
+
}
|
|
240
249
|
this.setState('info.connection', false, true); // change to yellow
|
|
241
250
|
return; // Go out.
|
|
242
251
|
}
|
|
@@ -516,6 +525,48 @@ class SmartControl extends utils.Adapter {
|
|
|
516
525
|
|
|
517
526
|
}
|
|
518
527
|
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Get messages from Adapter Configuration UI
|
|
531
|
+
* Using this method requires "common.message" property to be set to true in io-package.json
|
|
532
|
+
* @param {ioBroker.Message} obj
|
|
533
|
+
*/
|
|
534
|
+
async _asyncOnMessage(obj) {
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
|
|
538
|
+
if (typeof obj !== 'object') throw (`Verify input object: object is not defined.`);
|
|
539
|
+
if (!obj.message) throw (`Verify input object: object.message is not defined.`);
|
|
540
|
+
if (!obj.callback) throw (`Verify input object: object.callback is not defined.`);
|
|
541
|
+
|
|
542
|
+
/**********************************
|
|
543
|
+
* Verify the configuration from admin/index_m.html, once user hits the save button.
|
|
544
|
+
*********************************/
|
|
545
|
+
if (obj.command == 'verifyConfig') {
|
|
546
|
+
|
|
547
|
+
this.log.debug(`[_asyncOnMessage] command 'Verify Adapter Configuration' received from admin/index_m.html. Verifying the configuration and sending the result back to index_m.html...`);
|
|
548
|
+
|
|
549
|
+
// Verify and send the result back to admin/index_m.html
|
|
550
|
+
const configVerificationResult = await this._asyncVerifyConfig(obj.message);
|
|
551
|
+
this.sendTo(obj.from, obj.command, configVerificationResult, obj.callback);
|
|
552
|
+
// Some log
|
|
553
|
+
if (configVerificationResult.passed) {
|
|
554
|
+
this.log.debug(`[_asyncOnMessage] Configuration successfully verified, no issues found.`);
|
|
555
|
+
} else {
|
|
556
|
+
this.log.debug(`[_asyncOnMessage] Configuration verification failed, ${configVerificationResult.issues.length} issue(s) found.`);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
} else {
|
|
560
|
+
throw (`[_asyncOnMessage] sendTo() received object, but command '${obj.command}' is not defined in this method.`);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
} catch (error) {
|
|
564
|
+
this.x.helper.dumpError('[_asyncOnMessage()]', error);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
519
570
|
/**
|
|
520
571
|
* Schedule all trigger times of Trigger Times table
|
|
521
572
|
*
|
|
@@ -1045,18 +1096,20 @@ class SmartControl extends utils.Adapter {
|
|
|
1045
1096
|
|
|
1046
1097
|
/**
|
|
1047
1098
|
* Verify adapter configuration table
|
|
1048
|
-
* @param {
|
|
1049
|
-
* @return {Promise<boolean>}
|
|
1099
|
+
* @param {object} configObject - configuration object, typically this.config
|
|
1100
|
+
* @return {Promise<{passed:boolean, obj:object, issues:array}>} passed: true if successful, false if not. obj: the altered configObject. issues: array of all issue string messages
|
|
1050
1101
|
*/
|
|
1051
|
-
async _asyncVerifyConfig(
|
|
1102
|
+
async _asyncVerifyConfig(configObject) {
|
|
1052
1103
|
|
|
1053
1104
|
try {
|
|
1054
1105
|
|
|
1055
1106
|
let errors = 0;
|
|
1056
1107
|
let validTriggerCounter = 0;
|
|
1108
|
+
let validTargetDevicesCounter = 0;
|
|
1109
|
+
const issues = [];
|
|
1057
1110
|
|
|
1058
1111
|
// FIRST: Check the config array
|
|
1059
|
-
for (const functionConfigObj of
|
|
1112
|
+
for (const functionConfigObj of this.x.constants.configTableValidation) {
|
|
1060
1113
|
|
|
1061
1114
|
/**
|
|
1062
1115
|
* Prepare the table(s). Typically we only have one table to check, however, 'tableZoneExecution' requires
|
|
@@ -1065,11 +1118,11 @@ class SmartControl extends utils.Adapter {
|
|
|
1065
1118
|
const tablesToCheck = []; // Array holding all tables to check. Will be just one element, except to 'tableZoneExecution'
|
|
1066
1119
|
if (!(functionConfigObj.tableId == 'tableZoneExecution')) {
|
|
1067
1120
|
// settings of adapter config table, like of 'tableTargetDevices'
|
|
1068
|
-
tablesToCheck.push({table:
|
|
1121
|
+
tablesToCheck.push({table: configObject[functionConfigObj.tableId]});
|
|
1069
1122
|
} else {
|
|
1070
1123
|
|
|
1071
1124
|
let counter = 0;
|
|
1072
|
-
for (const lpZoneRow of
|
|
1125
|
+
for (const lpZoneRow of configObject.tableZones) {
|
|
1073
1126
|
if (lpZoneRow.active) {
|
|
1074
1127
|
const tbl = (this.x.helper.isLikeEmpty(lpZoneRow.executionJson)) ? [] : JSON.parse(lpZoneRow.executionJson);
|
|
1075
1128
|
tablesToCheck.push({zoneTableRowNo:counter, executeAlways:lpZoneRow.executeAlways, table:tbl});
|
|
@@ -1086,7 +1139,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1086
1139
|
|
|
1087
1140
|
// For Zone Table Execution only: set "better" table name for log
|
|
1088
1141
|
if(lpTable.zoneTableRowNo != undefined) {
|
|
1089
|
-
functionConfigObj.tableName = `Zone: ${
|
|
1142
|
+
functionConfigObj.tableName = `Zone: ${configObject.tableZones[lpTable.zoneTableRowNo].name}, Execution`;
|
|
1090
1143
|
}
|
|
1091
1144
|
|
|
1092
1145
|
// Active status of each row; We simply push true or false in loop, same index as table rows (lpTable.table)
|
|
@@ -1094,7 +1147,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1094
1147
|
|
|
1095
1148
|
if (this.x.helper.isLikeEmpty(lpTable.table)) {
|
|
1096
1149
|
if(functionConfigObj.tableMustHaveActiveRows) {
|
|
1097
|
-
|
|
1150
|
+
issues.push('[Config Table \'' + functionConfigObj.tableName + '\'] No rows defined.');
|
|
1098
1151
|
errors++;
|
|
1099
1152
|
}
|
|
1100
1153
|
continue;
|
|
@@ -1102,7 +1155,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1102
1155
|
|
|
1103
1156
|
for (let i = 0; i < lpTable.table.length; i++) {
|
|
1104
1157
|
|
|
1105
|
-
if (!lpTable.table[i].active && !
|
|
1158
|
+
if (!lpTable.table[i].active && !configObject.validateDeactivatedRows) continue;
|
|
1106
1159
|
|
|
1107
1160
|
// Returns all object keys starting with 'check_' as array, like ['check_1','check_2']. Or empty array, if not found.
|
|
1108
1161
|
const lpCriteriaToCheck = (Object.keys(functionConfigObj).filter(str => str.includes('check_')));
|
|
@@ -1138,7 +1191,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1138
1191
|
|
|
1139
1192
|
if (!this.x.helper.isStateIdValid(lpConfigString)) {
|
|
1140
1193
|
// State path is not valid
|
|
1141
|
-
|
|
1194
|
+
issues.push(`[Config Table '${functionConfigObj.tableName}'] ${lpFcnConfigCheckObj.id} - State '${lpConfigString}' is not valid.`);
|
|
1142
1195
|
if (lpFcnConfigCheckObj.deactivateIfError) {
|
|
1143
1196
|
lpTable.table[i].active = false;
|
|
1144
1197
|
rowActiveStatus[i] = false;
|
|
@@ -1151,7 +1204,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1151
1204
|
const lpStateObject = await this.getForeignObjectAsync(lpConfigString);
|
|
1152
1205
|
if (!lpStateObject) {
|
|
1153
1206
|
// State does not exist
|
|
1154
|
-
|
|
1207
|
+
issues.push(`[Config Table '${functionConfigObj.tableName}'] State '${lpConfigString}' does not exist.`);
|
|
1155
1208
|
if (lpFcnConfigCheckObj.deactivateIfError) {
|
|
1156
1209
|
lpTable.table[i].active = false;
|
|
1157
1210
|
rowActiveStatus[i] = false;
|
|
@@ -1180,11 +1233,12 @@ class SmartControl extends utils.Adapter {
|
|
|
1180
1233
|
lpTable.table[i].active = false;
|
|
1181
1234
|
rowActiveStatus[i] = false;
|
|
1182
1235
|
}
|
|
1236
|
+
issues.push(stateValueResult.issue);
|
|
1183
1237
|
errors++;
|
|
1184
1238
|
continue;
|
|
1185
1239
|
} else {
|
|
1186
1240
|
if ('newStateVal' in stateValueResult) {
|
|
1187
|
-
|
|
1241
|
+
configObject[functionConfigObj.tableId][i][lpFcnConfigCheckObj.id] = stateValueResult.newStateVal;
|
|
1188
1242
|
}
|
|
1189
1243
|
}
|
|
1190
1244
|
|
|
@@ -1202,7 +1256,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1202
1256
|
lpTable.table[i].active = false;
|
|
1203
1257
|
rowActiveStatus[i] = false;
|
|
1204
1258
|
}
|
|
1205
|
-
|
|
1259
|
+
issues.push(`[Config Table '${functionConfigObj.tableName}'] - URL '${urlToCheck}' is not a valid URL.`);
|
|
1206
1260
|
errors++;
|
|
1207
1261
|
continue;
|
|
1208
1262
|
} else {
|
|
@@ -1215,7 +1269,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1215
1269
|
const finalStateId = this.namespace + '.targetURLs.' + lpConfigString.trim();
|
|
1216
1270
|
|
|
1217
1271
|
if (! this.x.helper.isStateIdValid(finalStateId)) {
|
|
1218
|
-
|
|
1272
|
+
issues.push(`[Config Table ${functionConfigObj.tableName}] Field ${lpFcnConfigCheckObj.id}, content '${lpConfigString}' contains invalid characters.'.`);
|
|
1219
1273
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1220
1274
|
errors++;
|
|
1221
1275
|
continue;
|
|
@@ -1236,14 +1290,14 @@ class SmartControl extends utils.Adapter {
|
|
|
1236
1290
|
}
|
|
1237
1291
|
|
|
1238
1292
|
if(! this.x.helper.isNumber(lpNumberToCheck) ) {
|
|
1239
|
-
|
|
1293
|
+
issues.push(`[Config Table ${functionConfigObj.tableName}] Field ${lpFcnConfigCheckObj.id} is expecting a number, but you set '${lpConfigString}'.`);
|
|
1240
1294
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1241
1295
|
errors++;
|
|
1242
1296
|
continue;
|
|
1243
1297
|
// check for lower limit, if 'numberLowerLimit' set in functionConfigObj object
|
|
1244
1298
|
} else if (! this.x.helper.isLikeEmpty(lpFcnConfigCheckObj.numberLowerLimit)) {
|
|
1245
1299
|
if(parseInt(lpNumberToCheck) < lpFcnConfigCheckObj.numberLowerLimit) {
|
|
1246
|
-
|
|
1300
|
+
issues.push('[Config Table \'' + functionConfigObj.tableName + '\'] Number in field "' + lpFcnConfigCheckObj.id + '" is smaller than ' + lpFcnConfigCheckObj.numberLowerLimit + ', which does not make sense.');
|
|
1247
1301
|
if (lpFcnConfigCheckObj.deactivateIfError) {
|
|
1248
1302
|
lpTable.table[i].active = false;
|
|
1249
1303
|
}
|
|
@@ -1253,7 +1307,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1253
1307
|
// check for upper limit, if 'numberUpperLimit' set in functionConfigObj object
|
|
1254
1308
|
} else if (! this.x.helper.isLikeEmpty(lpFcnConfigCheckObj.numberUpperLimit)) {
|
|
1255
1309
|
if(parseInt(lpNumberToCheck) < lpFcnConfigCheckObj.numberUpperLimit) {
|
|
1256
|
-
|
|
1310
|
+
issues.push('[Config Table \'' + functionConfigObj.tableName + '\'] Number in field "' + lpFcnConfigCheckObj.id + '" is greater than ' + lpFcnConfigCheckObj.numberUpperLimit + ', which does not make sense.');
|
|
1257
1311
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1258
1312
|
errors++;
|
|
1259
1313
|
continue;
|
|
@@ -1295,7 +1349,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1295
1349
|
}
|
|
1296
1350
|
|
|
1297
1351
|
if (this.x.helper.isLikeEmpty(lpToCheck) && !lpFcnConfigCheckObj.optional) {
|
|
1298
|
-
|
|
1352
|
+
issues.push('[Config Table \'' + functionConfigObj.tableName + '\'] Field "' + lpFcnConfigCheckObj.id + '" is empty or contains forbidden chars.');
|
|
1299
1353
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1300
1354
|
errors++;
|
|
1301
1355
|
continue;
|
|
@@ -1316,7 +1370,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1316
1370
|
isValidTime = true;
|
|
1317
1371
|
}
|
|
1318
1372
|
if (!isValidTime) {
|
|
1319
|
-
|
|
1373
|
+
issues.push(`[Config Table '${functionConfigObj.tableName}'] No valid time in field '${lpFcnConfigCheckObj.id}': '${lpConfigString}'`);
|
|
1320
1374
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1321
1375
|
errors++;
|
|
1322
1376
|
continue;
|
|
@@ -1328,7 +1382,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1328
1382
|
} else if (lpFcnConfigCheckObj.type == 'overwrite') {
|
|
1329
1383
|
|
|
1330
1384
|
// Like: "targetsOverwrite": { "Bath.Light": "true", "Hallway Light": "50"}
|
|
1331
|
-
const targetsOverwriteObject =
|
|
1385
|
+
const targetsOverwriteObject = configObject[functionConfigObj.tableId][i][lpFcnConfigCheckObj.id];
|
|
1332
1386
|
if (this.x.helper.isLikeEmpty(targetsOverwriteObject)) continue; // nothing at this point
|
|
1333
1387
|
|
|
1334
1388
|
// loop thru the object to get the key name ("property")
|
|
@@ -1353,6 +1407,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1353
1407
|
const stateValueValidationResult = await this._asyncVerifyConfig_verifyStateValue(lpStatePath, lpStateVal, true, lpConfigTableName);
|
|
1354
1408
|
if (stateValueValidationResult.validationFailed) {
|
|
1355
1409
|
if (lpFcnConfigCheckObj.deactivateIfError) lpTable.table[i].active = false;
|
|
1410
|
+
issues.push(stateValueValidationResult.issue);
|
|
1356
1411
|
errors++;
|
|
1357
1412
|
continue;
|
|
1358
1413
|
} else {
|
|
@@ -1370,14 +1425,17 @@ class SmartControl extends utils.Adapter {
|
|
|
1370
1425
|
// Finalize
|
|
1371
1426
|
if(this.x.helper.isLikeEmpty(finalObj)) {
|
|
1372
1427
|
this.log.warn(`Verifying Targets Overwrite - failed for '${name}' - no keys found.`);
|
|
1428
|
+
errors++;
|
|
1429
|
+
continue;
|
|
1373
1430
|
} else {
|
|
1374
|
-
|
|
1431
|
+
configObject[functionConfigObj.tableId][i][lpFcnConfigCheckObj.id][name] = finalObj;
|
|
1375
1432
|
}
|
|
1376
1433
|
|
|
1377
1434
|
}
|
|
1378
1435
|
}
|
|
1379
1436
|
}
|
|
1380
1437
|
if(functionConfigObj.isTriggerTable) validTriggerCounter++;
|
|
1438
|
+
if(functionConfigObj.isTargetTable) validTargetDevicesCounter++;
|
|
1381
1439
|
|
|
1382
1440
|
}
|
|
1383
1441
|
let activeRowCounter = 0;
|
|
@@ -1386,23 +1444,27 @@ class SmartControl extends utils.Adapter {
|
|
|
1386
1444
|
}
|
|
1387
1445
|
|
|
1388
1446
|
if (activeRowCounter == 0 && functionConfigObj.tableMustHaveActiveRows && !functionConfigObj.isTriggerTable) {
|
|
1389
|
-
|
|
1447
|
+
issues.push(`[Config Table '${functionConfigObj.tableName}'] No active rows defined (certain rows may have been deactivated due to errors, see previous logs for details).`);
|
|
1390
1448
|
errors++;
|
|
1391
1449
|
}
|
|
1392
1450
|
|
|
1393
|
-
// We altered table variable, so set into
|
|
1451
|
+
// We altered table variable, so set into config object
|
|
1394
1452
|
if (!(functionConfigObj.tableId == 'tableZoneExecution')) {
|
|
1395
|
-
|
|
1453
|
+
configObject[functionConfigObj.tableId] = lpTable.table;
|
|
1396
1454
|
} else {
|
|
1397
1455
|
// @ts-ignore - Type 'undefined' cannot be used as an index type
|
|
1398
|
-
|
|
1456
|
+
configObject.tableZones[lpTable.zoneTableRowNo].executionJson = JSON.stringify(lpTable.table);
|
|
1399
1457
|
}
|
|
1400
1458
|
|
|
1401
1459
|
}
|
|
1402
1460
|
|
|
1403
1461
|
}
|
|
1404
1462
|
if (validTriggerCounter == 0) {
|
|
1405
|
-
|
|
1463
|
+
issues.push(`Tab [3. TRIGGERS] You need to define at least 1 trigger: you either have no triggers defined, or your triggers(s) did not pass the input validation.`);
|
|
1464
|
+
errors++;
|
|
1465
|
+
}
|
|
1466
|
+
if (validTargetDevicesCounter == 0) {
|
|
1467
|
+
issues.push(`Tab '1. TARGET DEVICES': You need to define at least 1 target: you either have no targets defined, or your target(s) did not pass the input validation.`);
|
|
1406
1468
|
errors++;
|
|
1407
1469
|
}
|
|
1408
1470
|
|
|
@@ -1413,11 +1475,11 @@ class SmartControl extends utils.Adapter {
|
|
|
1413
1475
|
const uniqueCheckObjects = [
|
|
1414
1476
|
// name: for logging only, column: the table to check, rows: the adapter config table rows
|
|
1415
1477
|
// @ts-ignore -> https://github.com/microsoft/TypeScript/issues/36769
|
|
1416
|
-
{ name:'Trigger Tables: Names', column:'name', rows:
|
|
1417
|
-
{ name:'Target device table: Names', column:'name', rows:
|
|
1418
|
-
{ name:'Zones table: Names', column:'name', rows:
|
|
1419
|
-
{ name:'Conditions table: Names', column:'name', rows:
|
|
1420
|
-
// { name:'Trigger Tables Motion/Other: State Paths', column:'stateId', rows:
|
|
1478
|
+
{ name:'Trigger Tables: Names', column:'name', rows:configObject.tableTriggerMotion.concat(configObject.tableTriggerDevices, configObject.tableTriggerTimes) },
|
|
1479
|
+
{ name:'Target device table: Names', column:'name', rows:configObject.tableTargetDevices },
|
|
1480
|
+
{ name:'Zones table: Names', column:'name', rows:configObject.tableZones },
|
|
1481
|
+
{ name:'Conditions table: Names', column:'name', rows:configObject.tableConditions },
|
|
1482
|
+
// { name:'Trigger Tables Motion/Other: State Paths', column:'stateId', rows:configObject.tableTriggerMotion.concat(configObject.tableTriggerDevices) },
|
|
1421
1483
|
];
|
|
1422
1484
|
for (const lpCheckObj of uniqueCheckObjects) {
|
|
1423
1485
|
if (!this.x.helper.isLikeEmpty(lpCheckObj.rows)) {
|
|
@@ -1428,7 +1490,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1428
1490
|
}
|
|
1429
1491
|
}
|
|
1430
1492
|
if ( !this.x.helper.isArrayUnique(allValues) ) {
|
|
1431
|
-
|
|
1493
|
+
issues.push(`${lpCheckObj.name} must be unique. You cannot use same string more than once here.`);
|
|
1432
1494
|
errors++;
|
|
1433
1495
|
}
|
|
1434
1496
|
}
|
|
@@ -1437,15 +1499,14 @@ class SmartControl extends utils.Adapter {
|
|
|
1437
1499
|
|
|
1438
1500
|
// FINALIZE
|
|
1439
1501
|
if (errors == 0) {
|
|
1440
|
-
return true;
|
|
1502
|
+
return {passed:true, obj:configObject, issues:[]};
|
|
1441
1503
|
} else {
|
|
1442
|
-
|
|
1443
|
-
return false;
|
|
1504
|
+
return {passed:false, obj:configObject, issues:this.x.helper.uniqueArray(issues)};
|
|
1444
1505
|
}
|
|
1445
1506
|
|
|
1446
1507
|
} catch (error) {
|
|
1447
1508
|
this.x.helper.dumpError('[asyncVerifyConfig()]', error);
|
|
1448
|
-
return false;
|
|
1509
|
+
return {passed:false, obj:configObject, issues:[`Error in [asyncVerifyConfig()]: ${error}`]};
|
|
1449
1510
|
}
|
|
1450
1511
|
}
|
|
1451
1512
|
|
|
@@ -1457,7 +1518,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1457
1518
|
* @param {*} stateVal
|
|
1458
1519
|
* @param {boolean} isOptional
|
|
1459
1520
|
* @param {string} configTableName -- name of config table, for log only
|
|
1460
|
-
* @return {Promise<object>} {validationFailed:false, newStateVal:'xyz'}
|
|
1521
|
+
* @return {Promise<object>} {validationFailed:false, newStateVal:'xyz', issue:''}
|
|
1461
1522
|
*/
|
|
1462
1523
|
async _asyncVerifyConfig_verifyStateValue(statePath, stateVal, isOptional, configTableName) {
|
|
1463
1524
|
|
|
@@ -1479,8 +1540,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1479
1540
|
|
|
1480
1541
|
if (!lpStateObject) {
|
|
1481
1542
|
// State does not exist
|
|
1482
|
-
|
|
1483
|
-
return {validationFailed:true};
|
|
1543
|
+
return {validationFailed:true, issue:`[Config Table '${configTableName}'] State '${statePath}' does not exist.`};
|
|
1484
1544
|
} else {
|
|
1485
1545
|
// State exists
|
|
1486
1546
|
// Verify State Type (like boolean, switch, number)
|
|
@@ -1488,8 +1548,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1488
1548
|
|
|
1489
1549
|
if (stateType == 'boolean' || stateType == 'switch') {
|
|
1490
1550
|
if (stateVal != 'true' && stateVal != 'false') {
|
|
1491
|
-
|
|
1492
|
-
return {validationFailed:true};
|
|
1551
|
+
return {validationFailed:true, issue:`[Config Table '${configTableName}'] State '${statePath}' is expecting boolean (true/false), but you set '${stateVal}'.`};
|
|
1493
1552
|
} else {
|
|
1494
1553
|
if (stateVal == 'true') stateVal = true;
|
|
1495
1554
|
if (stateVal == 'false') stateVal = false;
|
|
@@ -1503,8 +1562,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1503
1562
|
} else if (this.x.helper.isNumber(stateVal)) {
|
|
1504
1563
|
return {validationFailed:false, newStateVal:parseFloat(stateVal)};
|
|
1505
1564
|
} else {
|
|
1506
|
-
|
|
1507
|
-
return {validationFailed:true};
|
|
1565
|
+
return {validationFailed:true, issue:`[Config Table ${configTableName}] State ${statePath} is expecting a number, but you set '${stateVal}'.`};
|
|
1508
1566
|
}
|
|
1509
1567
|
} else if (this.x.helper.isLikeEmpty(stateVal)) {
|
|
1510
1568
|
// Let's convert an "like empty" value to an empty string, just to make sure....
|
|
@@ -1515,8 +1573,7 @@ class SmartControl extends utils.Adapter {
|
|
|
1515
1573
|
}
|
|
1516
1574
|
}
|
|
1517
1575
|
} catch (error) {
|
|
1518
|
-
this.x.helper.dumpError('[verifyStateValue()]', error);
|
|
1519
|
-
return {validationFailed:true};
|
|
1576
|
+
return {validationFailed:true, issue:this.x.helper.dumpError('[verifyStateValue()]', error, true)};
|
|
1520
1577
|
}
|
|
1521
1578
|
|
|
1522
1579
|
}
|
package/main.test.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This is a dummy TypeScript test file using chai and mocha
|
|
5
|
-
*
|
|
6
|
-
* It's automatically excluded from npm and its build output is excluded from both git and npm.
|
|
7
|
-
* It is advised to test all your modules with accompanying *.test.js-files
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// tslint:disable:no-unused-expression
|
|
11
|
-
|
|
12
|
-
const { expect } = require('chai');
|
|
13
|
-
// import { functionToTest } from "./moduleToTest";
|
|
14
|
-
|
|
15
|
-
describe('module to test => function to test', () => {
|
|
16
|
-
// initializing logic
|
|
17
|
-
const expected = 5;
|
|
18
|
-
|
|
19
|
-
it(`should return ${expected}`, () => {
|
|
20
|
-
const result = 5;
|
|
21
|
-
// assign result a value from functionToTest
|
|
22
|
-
expect(result).to.equal(expected);
|
|
23
|
-
// or using the should() syntax
|
|
24
|
-
result.should.equal(expected);
|
|
25
|
-
});
|
|
26
|
-
// ... more tests => it
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// ... more test suites => describe
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a dummy TypeScript test file using chai and mocha
|
|
5
|
+
*
|
|
6
|
+
* It's automatically excluded from npm and its build output is excluded from both git and npm.
|
|
7
|
+
* It is advised to test all your modules with accompanying *.test.js-files
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// tslint:disable:no-unused-expression
|
|
11
|
+
|
|
12
|
+
const { expect } = require('chai');
|
|
13
|
+
// import { functionToTest } from "./moduleToTest";
|
|
14
|
+
|
|
15
|
+
describe('module to test => function to test', () => {
|
|
16
|
+
// initializing logic
|
|
17
|
+
const expected = 5;
|
|
18
|
+
|
|
19
|
+
it(`should return ${expected}`, () => {
|
|
20
|
+
const result = 5;
|
|
21
|
+
// assign result a value from functionToTest
|
|
22
|
+
expect(result).to.equal(expected);
|
|
23
|
+
// or using the should() syntax
|
|
24
|
+
result.should.equal(expected);
|
|
25
|
+
});
|
|
26
|
+
// ... more tests => it
|
|
27
|
+
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// ... more test suites => describe
|
package/package.json
CHANGED
|
@@ -1,70 +1,73 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "iobroker.smartcontrol",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "Control devices smarter: by grouping, including triggers like motion, opening window, etc. and set target devices accordingly",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Mic-M",
|
|
7
|
-
"email": "iob.micm@gmail.com"
|
|
8
|
-
},
|
|
9
|
-
"homepage": "https://github.com/
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"keywords": [
|
|
12
|
-
"smart",
|
|
13
|
-
"control",
|
|
14
|
-
"rooms",
|
|
15
|
-
"groups",
|
|
16
|
-
"motion sensors",
|
|
17
|
-
"devices",
|
|
18
|
-
"switches",
|
|
19
|
-
"lights",
|
|
20
|
-
"trigger",
|
|
21
|
-
"schedule"
|
|
22
|
-
],
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "https://github.com/
|
|
26
|
-
},
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"@iobroker/adapter-core": "^2.4.0",
|
|
29
|
-
"@types/jquery": "^3.5.
|
|
30
|
-
"cheerio": "^1.0.0-rc.
|
|
31
|
-
"got": "^11.8.0",
|
|
32
|
-
"node-schedule": "^1.
|
|
33
|
-
"suncalc2": "^1.8.1"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"test:
|
|
62
|
-
"test:
|
|
63
|
-
"test": "
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
},
|
|
69
|
-
"
|
|
70
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "iobroker.smartcontrol",
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "Control devices smarter: by grouping, including triggers like motion, opening window, etc. and set target devices accordingly",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Mic-M",
|
|
7
|
+
"email": "iob.micm@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/iobroker-community-adapters/ioBroker.smartcontrol",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"smart",
|
|
13
|
+
"control",
|
|
14
|
+
"rooms",
|
|
15
|
+
"groups",
|
|
16
|
+
"motion sensors",
|
|
17
|
+
"devices",
|
|
18
|
+
"switches",
|
|
19
|
+
"lights",
|
|
20
|
+
"trigger",
|
|
21
|
+
"schedule"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/iobroker-community-adapters/ioBroker.smartcontrol"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@iobroker/adapter-core": "^2.4.0",
|
|
29
|
+
"@types/jquery": "^3.5.14",
|
|
30
|
+
"cheerio": "^1.0.0-rc.12",
|
|
31
|
+
"got": "^11.8.0",
|
|
32
|
+
"node-schedule": "^2.1.0",
|
|
33
|
+
"suncalc2": "^1.8.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@alcalzone/release-script": "^3.5.9",
|
|
37
|
+
"@alcalzone/release-script-plugin-iobroker": "^3.5.9",
|
|
38
|
+
"@alcalzone/release-script-plugin-license": "^3.5.9",
|
|
39
|
+
"@alcalzone/release-script-plugin-manual-review": "^3.5.9",
|
|
40
|
+
"@iobroker/testing": "^4.1.0",
|
|
41
|
+
"@types/chai": "^4.3.1",
|
|
42
|
+
"@types/chai-as-promised": "^7.1.3",
|
|
43
|
+
"@types/gulp": "^4.0.9",
|
|
44
|
+
"@types/mocha": "^9.1.1",
|
|
45
|
+
"@types/node": "^18.7.23",
|
|
46
|
+
"@types/proxyquire": "^1.3.28",
|
|
47
|
+
"@types/sinon": "^10.0.11",
|
|
48
|
+
"@types/sinon-chai": "^3.2.5",
|
|
49
|
+
"axios": "^0.27.2",
|
|
50
|
+
"chai": "^4.3.6",
|
|
51
|
+
"chai-as-promised": "^7.1.1",
|
|
52
|
+
"eslint": "^8.24.0",
|
|
53
|
+
"gulp": "^4.0.2",
|
|
54
|
+
"mocha": "^10.0.0",
|
|
55
|
+
"proxyquire": "^2.1.3",
|
|
56
|
+
"sinon": "^9.2.4",
|
|
57
|
+
"sinon-chai": "^3.7.0"
|
|
58
|
+
},
|
|
59
|
+
"main": "main.js",
|
|
60
|
+
"scripts": {
|
|
61
|
+
"test:js": "mocha --opts test/mocha.custom.opts",
|
|
62
|
+
"test:package": "mocha test/package --exit",
|
|
63
|
+
"test:unit": "mocha test/unit --exit",
|
|
64
|
+
"test:integration": "mocha test/integration --exit",
|
|
65
|
+
"test": "npm run test:js && npm run test:package",
|
|
66
|
+
"lint": "eslint",
|
|
67
|
+
"release": "release-script"
|
|
68
|
+
},
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/iobroker-community-adapters/ioBroker.smartcontrol/issues"
|
|
71
|
+
},
|
|
72
|
+
"readmeFilename": "README.md"
|
|
73
|
+
}
|