iobroker.smartcontrol 2.1.0 → 2.2.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.
Files changed (105) hide show
  1. package/README.md +16 -6
  2. package/admin/custom/assets/Components-CDPYnOs-.js +77 -0
  3. package/admin/custom/assets/Components-DpQjIfuo.js +1 -0
  4. package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__SmartcontrolSet__mf_owner__1-C9SdP7_s.js +1 -0
  5. package/admin/custom/assets/_virtual_mf___mfe_internal__SmartcontrolSet__mf_owner__108197177487852__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-Ca-6Y14s.js +1525 -0
  6. package/admin/custom/assets/_virtual_mf___mfe_internal__SmartcontrolSet__mf_owner__108197177487852__loadShare__shared-4MdeZwge.js +2 -0
  7. package/admin/custom/assets/_virtual_mf___mfe_internal__SmartcontrolSet__mf_owner__108197177487852__prebuild___mf_0_iobroker_mf_1_json_mf_2_config__prebuild__-QT6he7QZ.js +122 -0
  8. package/admin/custom/assets/_virtual_mf___mfe_internal__SmartcontrolSet__mf_owner__108197177487852__prebuild__react_mf_1_jsx_mf_2_runtime__prebuild__-BWTOCVCn.js +1 -0
  9. package/admin/custom/assets/dist-Cnxr-ruU.js +1 -0
  10. package/admin/custom/assets/helpers-CNHzo155.js +1 -0
  11. package/admin/custom/assets/hostInit-BVoHSU7s.js +1 -0
  12. package/admin/custom/assets/iconLibraryData-B5fiyl1C.js +1 -0
  13. package/admin/custom/assets/index-CwC_q7vn.js +1 -0
  14. package/admin/custom/assets/lib-CgOpGT17.js +3 -0
  15. package/admin/custom/assets/mf-entry-bootstrap-0-6167c687.js +54 -0
  16. package/admin/custom/assets/pendingShares-CEz9fejL.js +2 -0
  17. package/admin/custom/assets/prod-XWAlCKxB.js +492 -0
  18. package/admin/custom/assets/rolldown-runtime-9C0vUP4u.js +1 -0
  19. package/admin/custom/assets/utils-DmVoYT7i.js +4 -0
  20. package/admin/custom/assets/vite-preload-helper-nldAWQd6.js +1 -0
  21. package/admin/custom/customComponents.js +12 -0
  22. package/admin/custom/i18n/de.json +59 -0
  23. package/admin/custom/i18n/en.json +59 -0
  24. package/admin/custom/mf-manifest.json +1 -0
  25. package/admin/doc-md/readme.txt +2 -6
  26. package/admin/doc-md/start_de.md +34 -89
  27. package/admin/doc-md/start_en.md +33 -90
  28. package/admin/doc-md/table-conditions_de.md +7 -9
  29. package/admin/doc-md/table-conditions_en.md +7 -9
  30. package/admin/doc-md/table-execution_de.md +11 -10
  31. package/admin/doc-md/table-execution_en.md +12 -11
  32. package/admin/doc-md/table-options_de.md +58 -0
  33. package/admin/doc-md/table-options_en.md +58 -0
  34. package/admin/doc-md/table-target-devices_de.md +20 -16
  35. package/admin/doc-md/table-target-devices_en.md +18 -16
  36. package/admin/doc-md/table-target-enums_de.md +13 -13
  37. package/admin/doc-md/table-target-enums_en.md +12 -14
  38. package/admin/doc-md/table-target-url_de.md +14 -25
  39. package/admin/doc-md/table-target-url_en.md +14 -23
  40. package/admin/doc-md/table-trigger-devices_de.md +10 -11
  41. package/admin/doc-md/table-trigger-devices_en.md +10 -10
  42. package/admin/doc-md/table-trigger-motion_de.md +41 -24
  43. package/admin/doc-md/table-trigger-motion_en.md +35 -19
  44. package/admin/doc-md/table-trigger-times_de.md +11 -12
  45. package/admin/doc-md/table-trigger-times_en.md +11 -11
  46. package/admin/doc-md/table-zones_de.md +19 -14
  47. package/admin/doc-md/table-zones_en.md +19 -14
  48. package/admin/doc-md/table-zones_select-targets_de.md +7 -15
  49. package/admin/doc-md/table-zones_select-targets_en.md +7 -15
  50. package/admin/i18n/{de/translations.json → de.json} +2 -1
  51. package/admin/i18n/{en/translations.json → en.json} +2 -1
  52. package/admin/i18n/{es/translations.json → es.json} +2 -1
  53. package/admin/i18n/{fr/translations.json → fr.json} +2 -1
  54. package/admin/i18n/{it/translations.json → it.json} +2 -1
  55. package/admin/i18n/{nl/translations.json → nl.json} +2 -1
  56. package/admin/i18n/{pl/translations.json → pl.json} +2 -1
  57. package/admin/i18n/{pt/translations.json → pt.json} +2 -1
  58. package/admin/i18n/{ru/translations.json → ru.json} +2 -1
  59. package/admin/i18n/uk.json +110 -0
  60. package/admin/i18n/{zh-cn/translations.json → zh-cn.json} +2 -1
  61. package/admin/img/option-screenshots/tab-conditions.png +0 -0
  62. package/admin/img/option-screenshots/tab-further-options.png +0 -0
  63. package/admin/img/option-screenshots/tab-start.png +0 -0
  64. package/admin/img/option-screenshots/tab-target-devices.png +0 -0
  65. package/admin/img/option-screenshots/tab-triggers-motion.png +0 -0
  66. package/admin/img/option-screenshots/tab-triggers-other.png +0 -0
  67. package/admin/img/option-screenshots/tab-triggers-time.png +0 -0
  68. package/admin/img/option-screenshots/tab-zones-execution.png +0 -0
  69. package/admin/img/option-screenshots/tab-zones.png +0 -0
  70. package/admin/jsonConfig.json5 +524 -0
  71. package/io-package.json +17 -14
  72. package/lib/helper.js +40 -6
  73. package/lib/trigger-class.js +185 -80
  74. package/lib/trigger-match.js +76 -0
  75. package/main.js +132 -62
  76. package/package.json +11 -21
  77. package/admin/admin.d.ts +0 -4
  78. package/admin/css/LICENSE-github-markdown-css.txt +0 -24
  79. package/admin/css/github-markdown-dark.min.css +0 -8
  80. package/admin/css/github-markdown.min.css +0 -8
  81. package/admin/doc-md/img/start_dropdown-ani.gif +0 -0
  82. package/admin/doc-md/img/start_open-dialog.png +0 -0
  83. package/admin/doc-md/img/start_show-explanation.gif +0 -0
  84. package/admin/doc-md/img/table-zones_select-target-devices-overwrite.gif +0 -0
  85. package/admin/fancytree/skin-lion/icons-rtl.gif +0 -0
  86. package/admin/fancytree/skin-lion/icons.gif +0 -0
  87. package/admin/fancytree/skin-lion/loading.gif +0 -0
  88. package/admin/fancytree/skin-lion/ui.fancytree.min.css +0 -6
  89. package/admin/fancytree/skin-lion/vline-rtl.gif +0 -0
  90. package/admin/fancytree/skin-lion/vline.gif +0 -0
  91. package/admin/img/info-big.png +0 -0
  92. package/admin/img/info-big.png_README.txt +0 -6
  93. package/admin/img/sc_always.png +0 -0
  94. package/admin/img/select-target-devices-overwrite.gif +0 -0
  95. package/admin/img/smartControl_options1.gif +0 -0
  96. package/admin/img/smartControl_options_dropdown.gif +0 -0
  97. package/admin/img/smartControl_options_dropdown_2.gif +0 -0
  98. package/admin/index_m.html +0 -812
  99. package/admin/index_m.js +0 -1659
  100. package/admin/style.css +0 -255
  101. package/admin/tsconfig.json +0 -45
  102. package/admin/words.js +0 -113
  103. package/admin/zero-md/readme.txt +0 -1
  104. package/admin/zero-md/webcomponents-loader.min.js +0 -9
  105. package/admin/zero-md/zero-md.min.js.js +0 -9
package/lib/helper.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const nodeTimers = require('node:timers');
4
+
3
5
  /**
4
6
  * @param adapter
5
7
  * @description Generic Helper Functions
@@ -74,10 +76,12 @@ module.exports = function (adapter) {
74
76
  initialDefault = {};
75
77
  }
76
78
  }
79
+ // Default nach create ist Adapter-Wert, nicht Nutzer-Befehl.
80
+ // write:false (z. B. options.*.name) + ack:false -> js-controller-Warnung.
77
81
  if (isForeign) {
78
- await adapter.setForeignStateAsync(lpStateToCreate.statePath, initialDefault, false);
82
+ await adapter.setForeignStateAsync(lpStateToCreate.statePath, initialDefault, true);
79
83
  } else {
80
- await adapter.setStateAsync(lpStateToCreate.statePath, initialDefault, false);
84
+ await adapter.setStateAsync(lpStateToCreate.statePath, initialDefault, true);
81
85
  }
82
86
  adapter.log.debug(`State '${lpStateToCreate.statePath}' created.`);
83
87
  }
@@ -567,9 +571,12 @@ module.exports = function (adapter) {
567
571
  return -1;
568
572
  }
569
573
 
570
- const dummyTimer = setTimeout(() => {}, 0); // We need a dummy timer to get the current number of ms when the node.js session was started
571
- const currMsAfterNodeJsStart = dummyTimer['_idleStart']; // _idleStart is the number of milliseconds since the node.js session was started.
572
- clearTimeout(dummyTimer); // clear dummy timer, just in case.
574
+ // A native dummy timer only to read the current libuv time (_idleStart, ms since the node.js session was started).
575
+ // It is cleared at once, so it cannot outlive the adapter. adapter.setTimeout() is not used on purpose:
576
+ // this is also called in onUnload(), where adapter.setTimeout() returns undefined and logs a warning.
577
+ const dummyTimer = nodeTimers.setTimeout(() => {}, 0);
578
+ const currMsAfterNodeJsStart = dummyTimer['_idleStart'];
579
+ nodeTimers.clearTimeout(dummyTimer);
573
580
 
574
581
  const elapsed = currMsAfterNodeJsStart - timerId._idleStart; // for how many milliseconds is timer already running?
575
582
  let remaining = timerId._idleTimeout - elapsed; // remaining time in ms
@@ -946,12 +953,39 @@ module.exports = function (adapter) {
946
953
  * Converts string like 'val:'abc', delay:500' to a JSON object
947
954
  * If keys 'val' or 'delay' are not existing, return {val: query}
948
955
  *
949
- * @param {string} query
956
+ * jsonConfig speichert denselben Override schon als Objekt { val, delay }.
957
+ * Die alte Admin-UI speicherte nur den String ("95"). Beides muss hier landen.
958
+ *
959
+ * @param {string|object} query
950
960
  * @param {Array} keys - array of strings like ['val', 'delay']
951
961
  * @param {boolean} [flat]
952
962
  * @returns {object|null} JSON object, or null if query is empty or errors
953
963
  */
954
964
  convertStrToJson(query, keys, flat = false) {
965
+ if (query && typeof query === 'object' && !Array.isArray(query)) {
966
+ const out = {};
967
+ if (query.val !== undefined && query.val !== null && String(query.val).trim() !== '') {
968
+ out.val = query.val;
969
+ }
970
+ if (
971
+ query.delay !== undefined &&
972
+ query.delay !== null &&
973
+ query.delay !== '' &&
974
+ this.isNumber(query.delay) &&
975
+ parseInt(query.delay) >= 0
976
+ ) {
977
+ out.delay = query.delay;
978
+ }
979
+ return Object.keys(out).length ? out : null;
980
+ }
981
+
982
+ if (typeof query !== 'string') {
983
+ if (query === undefined || query === null) {
984
+ return null;
985
+ }
986
+ query = String(query);
987
+ }
988
+
955
989
  if (this.isLikeEmpty(query)) {
956
990
  return null;
957
991
  }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { getOtherMotionTriggerNames, zoneMotionOffTimerAction } = require('./motion-zone-timer');
4
+ const { isTriggerStateMatching, isRecheckAfterDelayEnabled, shouldRecheckTriggerState } = require('./trigger-match');
4
5
 
5
6
  /**
6
7
  * @description For handling of triggers and their associated target devices.
@@ -154,7 +155,7 @@ class Trigger {
154
155
 
155
156
  // Timer zoneOn (delay for switching zone on)
156
157
  for (const lpZoneName of this.zoneNames) {
157
- clearTimeout(this.adapter.x.timersZoneOn[lpZoneName]);
158
+ this.adapter.clearTimeout(this.adapter.x.timersZoneOn[lpZoneName]);
158
159
  this.adapter.x.timersZoneOn[lpZoneName] = null;
159
160
  const zoneOnSecs = parseInt(
160
161
  this.adapter.getOptionTableValue('tableZones', 'name', lpZoneName, 'onAfter'),
@@ -165,8 +166,9 @@ class Trigger {
165
166
  );
166
167
  this._asyncSetTargetDevices_processZone(lpZoneName);
167
168
  } else {
168
- this.adapter.x.timersZoneOn[lpZoneName] = setTimeout(() => {
169
- this._asyncSetTargetDevices_processZone(lpZoneName);
169
+ // Nach der Wartezeit: nur prüfen, wenn die Zone das opt-in gesetzt hat.
170
+ this.adapter.x.timersZoneOn[lpZoneName] = this.adapter.setTimeout(() => {
171
+ this._asyncActivateZoneAfterOnDelay(lpZoneName);
170
172
  }, zoneOnSecs * 1000);
171
173
  }
172
174
  }
@@ -175,6 +177,154 @@ class Trigger {
175
177
  }
176
178
  }
177
179
 
180
+ /**
181
+ * Zone-Einschaltverzögerung ist abgelaufen.
182
+ *
183
+ * Warum (#4 / Review #370): Standard wie früher immer schalten. Nur wenn
184
+ * die Zone „Recheck after delay“ an hat, nochmal Auslöser/Bedingungen prüfen.
185
+ *
186
+ * @param {string} zoneName
187
+ */
188
+ async _asyncActivateZoneAfterOnDelay(zoneName) {
189
+ try {
190
+ this.adapter.x.timersZoneOn[zoneName] = null;
191
+ const recheckOn = isRecheckAfterDelayEnabled(
192
+ this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'recheckAfterDelay'),
193
+ );
194
+ if (recheckOn) {
195
+ const stillOk = await this._asyncRecheckAfterOnDelay(zoneName);
196
+ if (!stillOk) {
197
+ this.adapter.log.debug(
198
+ `Trigger [${this.triggerName}] Zone '${zoneName}': delay elapsed, but trigger or conditions no longer match – skip switching on.`,
199
+ );
200
+ return;
201
+ }
202
+ }
203
+ await this._asyncSetTargetDevices_processZone(zoneName);
204
+ } catch (error) {
205
+ this.adapter.x.helper.dumpError('[_asyncActivateZoneAfterOnDelay]', error);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Nochmal: Auslöser-Datenpunkt + Zonen-Ausführung (und bei Zeit: Zusatzbedingungen).
211
+ *
212
+ * @param {string} zoneName
213
+ * @returns {Promise<boolean>}
214
+ */
215
+ async _asyncRecheckAfterOnDelay(zoneName) {
216
+ try {
217
+ if (this.triggerIsTime) {
218
+ let doContinue = await this.asyncAreScheduleConditionsMet(
219
+ 'Trigger: Additional Conditions (recheck after delay)',
220
+ this.triggerTmAdditionCond,
221
+ this.triggerTmAddCondAll,
222
+ );
223
+ if (doContinue) {
224
+ doContinue = await this.asyncAreScheduleConditionsMet(
225
+ 'Trigger: "Never if" Conditions (recheck after delay)',
226
+ this.triggerTmNever,
227
+ this.triggerTmNeverAll,
228
+ true,
229
+ );
230
+ }
231
+ if (!doContinue) {
232
+ return false;
233
+ }
234
+ } else if (shouldRecheckTriggerState(this) && this.triggerStatePath) {
235
+ const stateObject = await this.adapter.x.helper.asyncGetForeignState(this.triggerStatePath);
236
+ if (!stateObject) {
237
+ return false;
238
+ }
239
+ if (!isTriggerStateMatching(stateObject.val, this.triggerStateVal, this.triggerTableId)) {
240
+ this.adapter.log.debug(
241
+ `Trigger [${this.triggerName}] Zone '${zoneName}': current value '${stateObject.val}' no longer matches '${this.triggerStateVal}'.`,
242
+ );
243
+ return false;
244
+ }
245
+ }
246
+
247
+ const zoneRow = (this.adapter.config.tableZones || []).find(
248
+ lpRow => lpRow.active && lpRow.name === zoneName,
249
+ );
250
+ if (!zoneRow || !Array.isArray(zoneRow.triggers) || !zoneRow.triggers.includes(this.triggerName)) {
251
+ return false;
252
+ }
253
+ return await this._asyncIsZoneExecutionCurrentlyMet(zoneRow);
254
+ } catch (error) {
255
+ this.adapter.x.helper.dumpError('[_asyncRecheckAfterOnDelay]', error);
256
+ return false;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Gilt die Ausführungs-Tabelle der Zone jetzt noch? (Uhrzeit, Wochentag, Bedingungen)
262
+ *
263
+ * @param {object} lpRowZones eine Zeile aus tableZones
264
+ * @returns {Promise<boolean>}
265
+ */
266
+ async _asyncIsZoneExecutionCurrentlyMet(lpRowZones) {
267
+ const executeAlways = lpRowZones.executeAlways ? true : false;
268
+ let tablesZoneExecution = [];
269
+ if (executeAlways) {
270
+ tablesZoneExecution = [{ active: true, executeAlways: true }];
271
+ } else {
272
+ tablesZoneExecution = lpRowZones.executionJson ? JSON.parse(lpRowZones.executionJson) : [];
273
+ }
274
+
275
+ for (const lpRow of tablesZoneExecution) {
276
+ if (lpRow.active && (await this._asyncDoesExecutionRowMatch(lpRowZones, lpRow))) {
277
+ return true;
278
+ }
279
+ }
280
+ return false;
281
+ }
282
+
283
+ /**
284
+ * Eine Zeile der Zonen-Ausführung (Zeitfenster, Tage, Bedingungen).
285
+ *
286
+ * @param {object} lpRowZones
287
+ * @param {object} lpRow
288
+ * @returns {Promise<boolean>}
289
+ */
290
+ async _asyncDoesExecutionRowMatch(lpRowZones, lpRow) {
291
+ this.adapter.log.debug(`Trigger [${this.triggerName}] === check schedule conditions ===`);
292
+
293
+ if (lpRow.executeAlways) {
294
+ this.adapter.log.debug(
295
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - 'Execute always is activated, so continue'`,
296
+ );
297
+ return true;
298
+ }
299
+
300
+ const tsCurrent = Date.now();
301
+ let doContinue = this.adapter.x.helper.scheduleIsTimeStampWithinPeriod(
302
+ tsCurrent,
303
+ lpRow.start,
304
+ lpRow.end,
305
+ lpRowZones.name,
306
+ );
307
+ if (doContinue) {
308
+ doContinue = this.adapter.x.helper.scheduleIsWeekdayMatching(lpRow, tsCurrent, lpRowZones.name);
309
+ }
310
+ if (doContinue) {
311
+ doContinue = await this.asyncAreScheduleConditionsMet(
312
+ 'Zone Execution: Additional Conditions',
313
+ lpRow.additionalConditions,
314
+ lpRow.additionalConditionsAll,
315
+ );
316
+ }
317
+ if (doContinue) {
318
+ doContinue = await this.asyncAreScheduleConditionsMet(
319
+ 'Zone Execution: "never if" Conditions',
320
+ lpRow.never,
321
+ lpRow.neverAll,
322
+ true,
323
+ );
324
+ }
325
+ return doContinue;
326
+ }
327
+
178
328
  /**
179
329
  * Set all target devices: Process zone - Start
180
330
  *
@@ -256,7 +406,7 @@ class Trigger {
256
406
 
257
407
  // Clear "linked devices" (mimic motion) timer for motion trigger
258
408
  if (this.triggerIsMotion && timeLeft > -1) {
259
- clearTimeout(this.adapter.x.timersMimicMotionTrigger[zoneName]);
409
+ this.adapter.clearTimeout(this.adapter.x.timersMimicMotionTrigger[zoneName]);
260
410
  this.adapter.x.timersMimicMotionTrigger[zoneName] = null;
261
411
  this.adapter.log.debug(
262
412
  `Clearing timer 'Linked device to motion', which was still running for ${(timeLeft / 1000).toFixed(0)} seconds.`,
@@ -297,18 +447,24 @@ class Trigger {
297
447
  }
298
448
  lDelaySecs.push(delay);
299
449
 
300
- // Targets overwrite: state value, and delay
450
+ // Targets overwrite: alte UI speicherte oft nur den String ("95"),
451
+ // jsonConfig/verify { val, delay }. Beides muss zur Laufzeit greifen.
301
452
  let overwriteValue = null;
302
453
  if (targetsOverwrite && targetsOverwrite[lpTargetDeviceName]) {
303
- if (!this.adapter.x.helper.isLikeEmpty(targetsOverwrite[lpTargetDeviceName].val)) {
304
- overwriteValue = targetsOverwrite[lpTargetDeviceName].val;
454
+ const ow = this.adapter.x.helper.convertStrToJson(targetsOverwrite[lpTargetDeviceName], [
455
+ 'val',
456
+ 'delay',
457
+ ]);
458
+ if (ow && !this.adapter.x.helper.isLikeEmpty(ow.val)) {
459
+ overwriteValue = ow.val;
305
460
  }
306
461
  if (
307
- targetsOverwrite[lpTargetDeviceName].delay !== undefined &&
308
- this.adapter.x.helper.isNumber(targetsOverwrite[lpTargetDeviceName].delay) &&
309
- parseInt(targetsOverwrite[lpTargetDeviceName].delay) > -1
462
+ ow &&
463
+ ow.delay !== undefined &&
464
+ this.adapter.x.helper.isNumber(ow.delay) &&
465
+ parseInt(ow.delay) > -1
310
466
  ) {
311
- delay = parseInt(targetsOverwrite[lpTargetDeviceName].delay);
467
+ delay = parseInt(ow.delay);
312
468
  }
313
469
  }
314
470
 
@@ -319,14 +475,15 @@ class Trigger {
319
475
  if (delay > 0) {
320
476
  lDelayedDevices.push(lpTargetDeviceName);
321
477
  }
322
- clearTimeout(this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`]);
478
+ this.adapter.clearTimeout(this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`]);
323
479
  this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`] = null;
324
480
 
325
481
  if (delay > 0) {
326
482
  // set timeout
327
- this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`] = setTimeout(() => {
328
- switchTargetDeviceAsync(this);
329
- }, delay * 1000);
483
+ this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`] =
484
+ this.adapter.setTimeout(() => {
485
+ switchTargetDeviceAsync(this);
486
+ }, delay * 1000);
330
487
  } else {
331
488
  // call right away
332
489
  await switchTargetDeviceAsync(this);
@@ -513,7 +670,7 @@ class Trigger {
513
670
  that.adapter.log.debug(
514
671
  `Trigger [${that.triggerName}] Zone '${zoneName}': Turn off 'always off' timer, since still running ${(zoneOffTimeLeft / 1000).toFixed(0)} seconds and toggle trigger triggered to turn off.`,
515
672
  );
516
- clearTimeout(that.adapter.x.timersZoneOff[zoneName]);
673
+ that.adapter.clearTimeout(that.adapter.x.timersZoneOff[zoneName]);
517
674
  that.adapter.x.timersZoneOff[zoneName] = null;
518
675
  }
519
676
  } else {
@@ -629,12 +786,12 @@ class Trigger {
629
786
  // First: clear timers. Note: we use timeLeft since we need this anyways for log.
630
787
  const timeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.adapter.x[timerObjectKey][zoneName]);
631
788
  if (timeLeft > -1) {
632
- clearTimeout(this.adapter.x[timerObjectKey][zoneName]);
789
+ this.adapter.clearTimeout(this.adapter.x[timerObjectKey][zoneName]);
633
790
  this.adapter.x[timerObjectKey][zoneName] = null;
634
791
  }
635
792
 
636
793
  // Set timer
637
- this.adapter.x[timerObjectKey][zoneName] = setTimeout(() => {
794
+ this.adapter.x[timerObjectKey][zoneName] = this.adapter.setTimeout(() => {
638
795
  this._asyncSetZoneTimer_doOnTimeout(zoneName, timerObjectKey, targets, zoneOffAfter);
639
796
  }, zoneOffAfter * 1000);
640
797
 
@@ -695,7 +852,7 @@ class Trigger {
695
852
  }
696
853
 
697
854
  // Set timer
698
- this.adapter.x.timersMotionOff[zoneName] = setTimeout(() => {
855
+ this.adapter.x.timersMotionOff[zoneName] = this.adapter.setTimeout(() => {
699
856
  if (!this.motionDuration) {
700
857
  return;
701
858
  }
@@ -717,7 +874,7 @@ class Trigger {
717
874
  */
718
875
  _clearZoneMotionOffTimer(zoneName) {
719
876
  if (this.adapter.x.timersMotionOff[zoneName]) {
720
- clearTimeout(this.adapter.x.timersMotionOff[zoneName]);
877
+ this.adapter.clearTimeout(this.adapter.x.timersMotionOff[zoneName]);
721
878
  this.adapter.x.timersMotionOff[zoneName] = null;
722
879
  }
723
880
  }
@@ -928,68 +1085,16 @@ class Trigger {
928
1085
 
929
1086
  for (const lpRow of tablesZoneExecution) {
930
1087
  if (lpRow.active) {
931
- this.adapter.log.debug(`Trigger [${this.triggerName}] === check schedule conditions ===`);
932
-
933
- if (lpRow.executeAlways) {
1088
+ const doContinue = await this._asyncDoesExecutionRowMatch(lpRowZones, lpRow);
1089
+ if (doContinue) {
934
1090
  this.adapter.log.debug(
935
- `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - 'Execute always is activated, so continue'`,
1091
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row *is* meeting conditions`,
936
1092
  );
937
1093
  this.zoneNames.push(lpRowZones.name);
938
1094
  } else {
939
- // A few variables / constants
940
- const tsCurrent = Date.now(); // the current timestamp
941
- let doContinue = true; // flag if we can continue.
942
-
943
- // First – check if current time is within the schedule times
944
- if (doContinue) {
945
- doContinue = this.adapter.x.helper.scheduleIsTimeStampWithinPeriod(
946
- tsCurrent,
947
- lpRow.start,
948
- lpRow.end,
949
- lpRowZones.name,
950
- );
951
- }
952
-
953
- // Next, check if current day is within the mon-sun options as set in schedules tables.
954
- if (doContinue) {
955
- doContinue = this.adapter.x.helper.scheduleIsWeekdayMatching(
956
- lpRow,
957
- tsCurrent,
958
- lpRowZones.name,
959
- );
960
- }
961
-
962
- // Next, check additional conditions (like Public Holiday, etc. -- as set in conditions table)
963
- if (doContinue) {
964
- doContinue = await this.asyncAreScheduleConditionsMet(
965
- 'Zone Execution: Additional Conditions',
966
- lpRow.additionalConditions,
967
- lpRow.additionalConditionsAll,
968
- );
969
- }
970
-
971
- // Next, check conditions "Never if"
972
- if (doContinue) {
973
- doContinue = await this.asyncAreScheduleConditionsMet(
974
- 'Zone Execution: "never if" Conditions',
975
- lpRow.never,
976
- lpRow.neverAll,
977
- true,
978
- );
979
- }
980
-
981
- // All checks done.
982
- if (doContinue) {
983
- this.adapter.log.debug(
984
- `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row *is* meeting conditions`,
985
- );
986
- /* isHit == true; */
987
- this.zoneNames.push(lpRowZones.name); // set matching zone name
988
- } else {
989
- this.adapter.log.debug(
990
- `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row is *not* meeting conditions`,
991
- );
992
- }
1095
+ this.adapter.log.debug(
1096
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row is *not* meeting conditions`,
1097
+ );
993
1098
  }
994
1099
  }
995
1100
  }
@@ -1043,7 +1148,7 @@ class Trigger {
1043
1148
  for (const lpTimerObjId of timerObjIds) {
1044
1149
  const lpTimeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.adapter.x[lpTimerObjId][zoneName]);
1045
1150
  if (this.triggerIsMotion && lpTimeLeft > -1) {
1046
- clearTimeout(this.adapter.x[lpTimerObjId][zoneName]);
1151
+ this.adapter.clearTimeout(this.adapter.x[lpTimerObjId][zoneName]);
1047
1152
  this.adapter.x[lpTimerObjId][zoneName] = null;
1048
1153
  this.adapter.log.debug(
1049
1154
  `Trigger [${this.triggerName}] Zone '${zoneName}': Clearing timer '${lpTimerObjId}', which was still running for ${(lpTimeLeft / 1000).toFixed(0)} seconds.`,
@@ -1071,7 +1176,7 @@ class Trigger {
1071
1176
  this.adapter.x.zonesIsOn[zoneName] = false;
1072
1177
 
1073
1178
  // Clear timer 'timersZoneOn'
1074
- clearTimeout(this.adapter.x.timersZoneOn[zoneName]);
1179
+ this.adapter.clearTimeout(this.adapter.x.timersZoneOn[zoneName]);
1075
1180
  this.adapter.x.timersZoneOn[zoneName] = null;
1076
1181
 
1077
1182
  const lTargetDevicesSwitchedOff = []; // For Log
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const { isNumComparatorMatching } = require('./num-comparator');
4
+
5
+ /**
6
+ * Prüft, ob der aktuelle Datenpunkt-Wert noch zum Auslöser passt.
7
+ *
8
+ * Warum: Nach „Zone an nach x Sekunden“ muss der Adapter nochmal schauen,
9
+ * z. B. ob das Fenster noch offen ist (#4). Die Regeln sind dieselben wie
10
+ * beim ersten Auslösen in main.js (Vergleichsoperatoren, sonst ==).
11
+ *
12
+ * Zeit-Auslöser haben keinen Live-Datenpunkt → immer true.
13
+ *
14
+ * @param {unknown} currentVal aktueller State-Wert
15
+ * @param {unknown} configuredVal Wert aus der Auslöser-Tabelle
16
+ * @param {string} [tableId] tableTriggerDevices | tableTriggerMotion | tableTriggerTimes
17
+ * @returns {boolean} true wenn der aktuelle Wert noch zum Auslöser passt
18
+ */
19
+ function isTriggerStateMatching(currentVal, configuredVal, tableId) {
20
+ if (tableId === 'tableTriggerTimes') {
21
+ return true;
22
+ }
23
+
24
+ // Andere Auslöser: `> 20`, `<= -5` usw.
25
+ if (tableId === 'tableTriggerDevices' && typeof configuredVal === 'string') {
26
+ const res = isNumComparatorMatching(currentVal, configuredVal);
27
+ if (res.isComparator) {
28
+ return !!res.result;
29
+ }
30
+ }
31
+
32
+ // wie main.js: lockerer Vergleich (!=), damit Zahl 1 und '1' zusammenpassen
33
+ if (configuredVal != undefined && configuredVal != currentVal) {
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+
39
+ /**
40
+ * Zone-Option „nach Verzögerung nochmal prüfen“ – nur bei explizit true.
41
+ *
42
+ * Warum: Standard muss wie früher bleiben (Issue-Review #370). Alte Configs
43
+ * haben das Feld nicht → undefined zählt als aus.
44
+ *
45
+ * @param {unknown} zoneOption Wert der Zone-Spalte recheckAfterDelay
46
+ * @returns {boolean}
47
+ */
48
+ function isRecheckAfterDelayEnabled(zoneOption) {
49
+ return zoneOption === true;
50
+ }
51
+
52
+ /**
53
+ * Den aktuellen Auslöser-Datenpunkt nach der Wartezeit nochmal lesen?
54
+ *
55
+ * Warum: BWM und Toggle/Taster sind oft nur kurz true. Nach onAfter wäre
56
+ * der State schon wieder false – dann würde die Zone nie mehr angehen.
57
+ *
58
+ * @param {{ triggerIsMotion?: boolean, triggerIsToggle?: boolean, mimicMotion?: boolean, triggerIsTime?: boolean }} trigger
59
+ * @returns {boolean}
60
+ */
61
+ function shouldRecheckTriggerState(trigger) {
62
+ if (!trigger) {
63
+ return false;
64
+ }
65
+ // Impuls: Bewegung, Taster (isToggle), verknüpfter Schalter, Zeit ohne State
66
+ if (trigger.triggerIsMotion || trigger.triggerIsToggle || trigger.mimicMotion || trigger.triggerIsTime) {
67
+ return false;
68
+ }
69
+ return true;
70
+ }
71
+
72
+ module.exports = {
73
+ isTriggerStateMatching,
74
+ isRecheckAfterDelayEnabled,
75
+ shouldRecheckTriggerState,
76
+ };