iobroker.smartcontrol 1.3.2 → 2.1.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 (42) hide show
  1. package/LICENSE +2 -0
  2. package/README.md +57 -297
  3. package/admin/css/LICENSE-github-markdown-css.txt +24 -0
  4. package/admin/css/github-markdown-dark.min.css +8 -0
  5. package/admin/css/github-markdown.min.css +8 -0
  6. package/admin/doc-md/table-trigger-motion_de.md +1 -1
  7. package/admin/doc-md/table-trigger-motion_en.md +1 -1
  8. package/admin/doc-md/table-trigger-times_de.md +1 -1
  9. package/admin/doc-md/table-trigger-times_en.md +1 -1
  10. package/admin/i18n/de/translations.json +109 -0
  11. package/admin/i18n/en/translations.json +109 -0
  12. package/admin/i18n/es/translations.json +109 -0
  13. package/admin/i18n/fr/translations.json +109 -0
  14. package/admin/i18n/it/translations.json +109 -0
  15. package/admin/i18n/nl/translations.json +109 -0
  16. package/admin/i18n/pl/translations.json +109 -0
  17. package/admin/i18n/pt/translations.json +109 -0
  18. package/admin/i18n/ru/translations.json +109 -0
  19. package/admin/i18n/zh-cn/translations.json +109 -0
  20. package/admin/index_m.js +207 -3
  21. package/admin/style.css +76 -8
  22. package/admin/tsconfig.json +45 -0
  23. package/io-package.json +44 -31
  24. package/lib/boolean-value.js +30 -0
  25. package/lib/constants.js +299 -65
  26. package/lib/cron-schedule.js +59 -0
  27. package/lib/helper.js +380 -373
  28. package/lib/midnight-reschedule.js +31 -0
  29. package/lib/motion-zone-timer.js +55 -0
  30. package/lib/num-comparator.js +70 -0
  31. package/lib/tools.js +12 -6
  32. package/lib/trigger-class.js +527 -282
  33. package/main.js +954 -626
  34. package/package.json +48 -32
  35. package/.github/ISSUE_TEMPLATE/BugReport.md +0 -36
  36. package/.github/ISSUE_TEMPLATE/Enhancement.md +0 -19
  37. package/.github/auto-merge.yml +0 -17
  38. package/.github/dependabot.yml +0 -12
  39. package/.github/workflows/dependabot-auto-merge.yml +0 -23
  40. package/.github/workflows/test-and-release.yml +0 -99
  41. package/.releaseconfig.json +0 -3
  42. package/main.test.js +0 -30
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
- /* eslint-disable no-inner-declarations -- // cite: *prior to ES6*, a function declaration is only allowed in the first level of a program or the body of another function */
2
+
3
+ const { getOtherMotionTriggerNames, zoneMotionOffTimerAction } = require('./motion-zone-timer');
3
4
 
4
5
  /**
5
- * @class Trigger
6
- * @desc For handling of triggers and their associated target devices.
6
+ * @description For handling of triggers and their associated target devices.
7
7
  * Every instance of this class is a specific trigger (motion sensor/'other device'/time trigger)
8
8
  * @author Mic-M <https://github.com/Mic-M/ioBroker.smartcontrol>
9
9
  * @license MIT
10
- *
10
+ *
11
11
  * Initial Properties:
12
12
  * ---Generic Properties---
13
13
  * {string} triggerName Name of Trigger
@@ -22,7 +22,6 @@
22
22
  * {number} motionDuration Duration (timer) in seconds for motion sensor
23
23
  * {string} motionBriStatePath State Path of brightness state
24
24
  * {number} motionBriThreshold Threshold of brightness
25
- * {object} motionTimer Timer object for motion to switch targets off
26
25
  * {boolean} mimicMotion For trigger devices linked/associated with a motion sensor (tableTriggerMotion -> motionLinkedTrigger)
27
26
  * {string} mimicMotionTriggerName Trigger name of device linked to motion sensor
28
27
  * {boolean} mimicMotionIgnoreMotionOn Ignore motion if motion sensor is set to true
@@ -31,18 +30,16 @@
31
30
  * {string} triggerTime If time trigger: time like '42 * * * *' or 'sunset+30'
32
31
  * {array} triggerTmAdditionCond Array of additional condition names for "Must be fulfilled"
33
32
  * {boolean} triggerTmAddCondAll if true: all conditions must be met, if false: at least one condition must be met
34
- * {string} triggerTmNever Array of additional condition names for "Never" which shall not be
33
+ * {string} triggerTmNever Array of additional condition names for "Never" which shall not be
35
34
  * {boolean} triggerTmNeverAll if true: all conditions must be met, if false: at least one condition must be met
36
35
  *
37
36
  * Properties set by this._asyncUpdateCurrentActiveZones()
38
37
  * {array} zoneNames All zone names that were triggered and meet all conditions
39
38
  * {object} zoneTargetNames All target device names per zone, like {Hallway:['Hallway Light'], Bath:['Light', 'Radio Bath']}
40
- * NOTE: Motion Trigger - If target was already turned on previously by a non-motion trigger:
39
+ * NOTE: Motion Trigger - If target was already turned on previously by a non-motion trigger:
41
40
  * We will remove that device to not schedule timer, if motionNotIfManual
42
- *
43
41
  */
44
42
  class Trigger {
45
-
46
43
  /**
47
44
  * Constructor
48
45
  *
@@ -60,16 +57,14 @@ class Trigger {
60
57
  * Set properties (retrieving from adapter configuration)
61
58
  */
62
59
  _init() {
63
-
64
60
  try {
65
-
66
61
  this.triggerStatePath = undefined; // set below accordingly if state
67
- this.triggerStateVal = undefined; // set below accordingly if state
68
- this.triggerIsMotion = false; // set to true below, if motion
69
- this.triggerIsToggle = false; // set to true below, if tableTriggerDevices.isToggle=true
70
- this.targetOff = false; // set to true below, if activated in other devices or time trigger table
71
- this.mimicMotion = false; // set accordingly in main.js
72
- this.mimicMotionTriggerName = undefined; // set accordingly in main.js
62
+ this.triggerStateVal = undefined; // set below accordingly if state
63
+ this.triggerIsMotion = false; // set to true below, if motion
64
+ this.triggerIsToggle = false; // set to true below, if tableTriggerDevices.isToggle=true
65
+ this.targetOff = false; // set to true below, if activated in other devices or time trigger table
66
+ this.mimicMotion = false; // set accordingly in main.js
67
+ this.mimicMotionTriggerName = undefined; // set accordingly in main.js
73
68
  this.mimicMotionIgnoreMotionOn = false; // set to true below, if tableTriggerMotion.ignoreMotionOn is true
74
69
 
75
70
  /**
@@ -84,11 +79,12 @@ class Trigger {
84
79
  break;
85
80
  }
86
81
  }
87
- if (result.index > -1) break;
82
+ if (result.index > -1) {
83
+ break;
84
+ }
88
85
  }
89
86
 
90
87
  switch (result.tableId) {
91
-
92
88
  case 'tableTriggerDevices':
93
89
  this.triggerTableId = result.tableId;
94
90
  this.triggerStatePath = result.row.stateId;
@@ -100,7 +96,6 @@ class Trigger {
100
96
  case 'tableTriggerMotion':
101
97
  this.triggerTableId = result.tableId;
102
98
  this.triggerIsMotion = true;
103
- this.motionTimer = null;
104
99
  this.triggerStatePath = result.row.stateId;
105
100
  this.triggerStateVal = true; // is always true for motion sensors to indicate if on
106
101
  this.motionNotIfManual = result.row.notIfManual;
@@ -111,7 +106,12 @@ class Trigger {
111
106
  } else {
112
107
  this.motionDuration = 0;
113
108
  }
114
- if (result.row.briThreshold && (parseInt(result.row.briThreshold) > 0) && result.row.briStateId && result.row.briStateId.length > 5) {
109
+ if (
110
+ result.row.briThreshold &&
111
+ parseInt(result.row.briThreshold) > 0 &&
112
+ result.row.briStateId &&
113
+ result.row.briStateId.length > 5
114
+ ) {
115
115
  this.motionBriStatePath = result.row.briStateId;
116
116
  this.motionBriThreshold = parseInt(result.row.briThreshold);
117
117
  } else {
@@ -132,34 +132,37 @@ class Trigger {
132
132
  break;
133
133
 
134
134
  default:
135
- throw (`No active trigger '${this.triggerName}' found in any trigger table.`);
135
+ throw `No active trigger '${this.triggerName}' found in any trigger table.`;
136
136
  }
137
-
138
137
  } catch (error) {
139
138
  this.adapter.x.helper.dumpError('_init()]', error);
140
139
  }
141
-
142
140
  }
143
141
 
144
142
  /**
145
143
  * Set all target devices for all zones
146
144
  * Note: No need to remove duplicates, this is being taken care of by asyncVerifyConfig() function.
145
+ *
147
146
  * @fires _asyncSetTargetDevices_processZone()
148
147
  */
149
148
  async asyncSetTargetDevices() {
150
-
151
149
  try {
152
-
153
150
  await this._asyncUpdateCurrentActiveZones(); // update current active zone properties
154
- if (!this.zoneNames || !this.zoneTargetNames) return;
151
+ if (!this.zoneNames || !this.zoneTargetNames) {
152
+ return;
153
+ }
155
154
 
156
155
  // Timer zoneOn (delay for switching zone on)
157
156
  for (const lpZoneName of this.zoneNames) {
158
157
  clearTimeout(this.adapter.x.timersZoneOn[lpZoneName]);
159
158
  this.adapter.x.timersZoneOn[lpZoneName] = null;
160
- const zoneOnSecs = parseInt(this.adapter.getOptionTableValue('tableZones', 'name', lpZoneName, 'onAfter'));
159
+ const zoneOnSecs = parseInt(
160
+ this.adapter.getOptionTableValue('tableZones', 'name', lpZoneName, 'onAfter'),
161
+ );
161
162
  if (!zoneOnSecs || zoneOnSecs < 1) {
162
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${lpZoneName}' No 'On after x sec' time is set, so we do not set such delay (timer).`);
163
+ this.adapter.log.debug(
164
+ `Trigger [${this.triggerName}] Zone '${lpZoneName}' No 'On after x sec' time is set, so we do not set such delay (timer).`,
165
+ );
163
166
  this._asyncSetTargetDevices_processZone(lpZoneName);
164
167
  } else {
165
168
  this.adapter.x.timersZoneOn[lpZoneName] = setTimeout(() => {
@@ -167,75 +170,99 @@ class Trigger {
167
170
  }, zoneOnSecs * 1000);
168
171
  }
169
172
  }
170
-
171
173
  } catch (error) {
172
174
  this.adapter.x.helper.dumpError('[asyncSetTargetDevices]', error);
173
175
  }
174
-
175
176
  }
176
177
 
177
-
178
178
  /**
179
179
  * Set all target devices: Process zone - Start
180
+ *
180
181
  * @param {string} zoneName - Name of zone
181
182
  */
182
183
  async _asyncSetTargetDevices_processZone(zoneName) {
183
-
184
184
  try {
185
-
186
- if (!this.zoneNames || !this.zoneTargetNames) return;
185
+ if (!this.zoneNames || !this.zoneTargetNames) {
186
+ return;
187
+ }
187
188
 
188
189
  /**
189
190
  * Prepare: If Motion Sensor triggered - verify brightness if bri is set
190
191
  */
191
- if (!this.mimicMotion && this.triggerIsMotion && !this.adapter.x.helper.isLikeEmpty(this.motionBriStatePath) && this.adapter.x.helper.isNumber(this.motionBriThreshold) && this.motionBriThreshold && (this.motionBriThreshold > 0)) {
192
-
192
+ if (
193
+ !this.mimicMotion &&
194
+ this.triggerIsMotion &&
195
+ !this.adapter.x.helper.isLikeEmpty(this.motionBriStatePath) &&
196
+ this.adapter.x.helper.isNumber(this.motionBriThreshold) &&
197
+ this.motionBriThreshold &&
198
+ this.motionBriThreshold > 0
199
+ ) {
193
200
  if (this.adapter.config.motionIgnoreBriIfZoneOn && this.adapter.x.zonesIsOn[zoneName]) {
194
201
  // Disregard Brightness if zone is on (if this.adapter.config.motionIgnoreBriIfZoneOn == true)
195
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${zoneName}' is on and new motion detected, therefore, we disregard any current brightness.`);
202
+ this.adapter.log.debug(
203
+ `Trigger [${this.triggerName}] Zone '${zoneName}' is on and new motion detected, therefore, we disregard any current brightness.`,
204
+ );
196
205
  } else {
197
206
  // Verify brightness
198
207
  const briStateObjCurr = await this.adapter.x.helper.asyncGetForeignState(this.motionBriStatePath); // {val: false, ack: true, ts: 1591117034451, …}
199
208
  const briStateValCurrent = briStateObjCurr.val;
200
- if (this.adapter.x.helper.isLikeEmpty(briStateValCurrent) || !this.adapter.x.helper.isNumber(briStateValCurrent) || parseInt(briStateValCurrent) < 0) {
209
+ if (
210
+ this.adapter.x.helper.isLikeEmpty(briStateValCurrent) ||
211
+ !this.adapter.x.helper.isNumber(briStateValCurrent) ||
212
+ parseInt(briStateValCurrent) < 0
213
+ ) {
201
214
  // Bri not valid, so disregard bri and continue
202
- this.adapter.log.debug(`Trigger [${this.triggerName}] Brightness of ${briStateValCurrent} of ${this.motionBriStatePath} is not valid. State Value: [${briStateValCurrent}]. Therefore, bri will be disregarded and we continue.`);
215
+ this.adapter.log.debug(
216
+ `Trigger [${this.triggerName}] Brightness of ${briStateValCurrent} of ${this.motionBriStatePath} is not valid. State Value: [${briStateValCurrent}]. Therefore, bri will be disregarded and we continue.`,
217
+ );
203
218
  } else if (parseInt(briStateValCurrent) < this.motionBriThreshold) {
204
219
  // continue
205
- this.adapter.log.debug(`Trigger [${this.triggerName}] Brightness of ${briStateValCurrent} is < threshold of ${this.motionBriThreshold}, so we continue.`);
220
+ this.adapter.log.debug(
221
+ `Trigger [${this.triggerName}] Brightness of ${briStateValCurrent} is < threshold of ${this.motionBriThreshold}, so we continue.`,
222
+ );
206
223
  } else {
207
224
  // Brightness condition is not met!
208
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] activated but current brightness of ${briStateValCurrent} is >= threshold of ${this.motionBriThreshold} -> Motion disregarded.`);
225
+ this.adapter.x.helper.logExtendedInfo(
226
+ `Trigger [${this.triggerName}] activated but current brightness of ${briStateValCurrent} is >= threshold of ${this.motionBriThreshold} -> Motion disregarded.`,
227
+ );
209
228
  return; // go out
210
229
  }
211
230
  }
212
231
  } else if (!this.mimicMotion && this.triggerIsMotion) {
213
- this.adapter.log.debug(`Trigger [${this.triggerName}] - no brightness defined for this motion sensor, so continue and do not use bri as an additional criterion.`);
232
+ this.adapter.log.debug(
233
+ `Trigger [${this.triggerName}] - no brightness defined for this motion sensor, so continue and do not use bri as an additional criterion.`,
234
+ );
214
235
  }
215
236
 
216
237
  /**
217
238
  * Ignore motion sensor triggered motion=true, if mimicMotionIgnoreMotionOn set to true
218
239
  */
219
- const timeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.adapter.x.timersMimicMotionTrigger[zoneName]);
240
+ const timeLeft = this.adapter.x.helper.getTimeoutTimeLeft(
241
+ this.adapter.x.timersMimicMotionTrigger[zoneName],
242
+ );
220
243
  if (!this.mimicMotion && this.triggerStateVal && this.triggerIsMotion && this.mimicMotionIgnoreMotionOn) {
221
244
  if (timeLeft > -1) {
222
- this.adapter.log.debug(`Trigger [${this.triggerName}] - Zone ${zoneName}: 'Mimic motion' is active, so we take over`);
245
+ this.adapter.log.debug(
246
+ `Trigger [${this.triggerName}] - Zone ${zoneName}: 'Mimic motion' is active, so we take over`,
247
+ );
223
248
  // timer will be canceled below
224
249
  } else {
225
- this.adapter.log.info(`Trigger [${this.triggerName}] - Zone ${zoneName}: No execution due to activated zone option 'ignore motion on'.`);
250
+ this.adapter.log.info(
251
+ `Trigger [${this.triggerName}] - Zone ${zoneName}: No execution due to activated zone option 'ignore motion on'.`,
252
+ );
226
253
  return;
227
254
  }
228
255
  }
229
256
 
230
257
  // Clear "linked devices" (mimic motion) timer for motion trigger
231
- if (this.triggerIsMotion && (timeLeft > -1)) {
258
+ if (this.triggerIsMotion && timeLeft > -1) {
232
259
  clearTimeout(this.adapter.x.timersMimicMotionTrigger[zoneName]);
233
260
  this.adapter.x.timersMimicMotionTrigger[zoneName] = null;
234
- this.adapter.log.debug(`Clearing timer 'Linked device to motion', which was still running for ${(timeLeft / 1000).toFixed(0)} seconds.`);
261
+ this.adapter.log.debug(
262
+ `Clearing timer 'Linked device to motion', which was still running for ${(timeLeft / 1000).toFixed(0)} seconds.`,
263
+ );
235
264
  }
236
265
 
237
-
238
-
239
266
  /**
240
267
  * -- Main --
241
268
  * Loop thru the target device names and switch accordingly.
@@ -248,12 +275,21 @@ class Trigger {
248
275
  let onOff = 'on'; // for toggle
249
276
 
250
277
  // get delay ('onAfter')
251
- const targetsOverwrite = this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'targetsOverwrite'); // like: {'Hallway.Light':{val:'new val', delay:10}, 'Hallway.Radio':{val:'Radio XYZ'}}
278
+ const targetsOverwrite = this.adapter.getOptionTableValue(
279
+ 'tableZones',
280
+ 'name',
281
+ zoneName,
282
+ 'targetsOverwrite',
283
+ ); // like: {'Hallway.Light':{val:'new val', delay:10}, 'Hallway.Radio':{val:'Radio XYZ'}}
252
284
 
253
285
  let counterDevicesProcessed = 0; // Once all processed, we will call a function
254
286
  for (const lpTargetDeviceName of this.zoneTargetNames[zoneName]) {
255
-
256
- let delay = this.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, 'onAfter');
287
+ let delay = this.adapter.getOptionTableValue(
288
+ 'tableTargetDevices',
289
+ 'name',
290
+ lpTargetDeviceName,
291
+ 'onAfter',
292
+ );
257
293
  if (delay !== undefined && this.adapter.x.helper.isNumber(delay) && parseInt(delay) > 0) {
258
294
  delay = parseInt(delay);
259
295
  } else {
@@ -267,25 +303,30 @@ class Trigger {
267
303
  if (!this.adapter.x.helper.isLikeEmpty(targetsOverwrite[lpTargetDeviceName].val)) {
268
304
  overwriteValue = targetsOverwrite[lpTargetDeviceName].val;
269
305
  }
270
- if (targetsOverwrite[lpTargetDeviceName].delay!==undefined
271
- && this.adapter.x.helper.isNumber(targetsOverwrite[lpTargetDeviceName].delay)
272
- && parseInt(targetsOverwrite[lpTargetDeviceName].delay) > -1) {
306
+ if (
307
+ targetsOverwrite[lpTargetDeviceName].delay !== undefined &&
308
+ this.adapter.x.helper.isNumber(targetsOverwrite[lpTargetDeviceName].delay) &&
309
+ parseInt(targetsOverwrite[lpTargetDeviceName].delay) > -1
310
+ ) {
273
311
  delay = parseInt(targetsOverwrite[lpTargetDeviceName].delay);
274
312
  }
275
313
  }
276
314
 
277
-
278
315
  /**
279
316
  * let's call function switchTargetDevice()
280
317
  */
281
318
  // Timer (delay) to switch device on
282
- if (delay > 0) lDelayedDevices.push(lpTargetDeviceName);
283
- clearTimeout(this.adapter.x.timersZoneDeviceOnDelay[zoneName+'_'+ lpTargetDeviceName]);
284
- this.adapter.x.timersZoneDeviceOnDelay[zoneName+'_'+ lpTargetDeviceName] = null;
319
+ if (delay > 0) {
320
+ lDelayedDevices.push(lpTargetDeviceName);
321
+ }
322
+ clearTimeout(this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`]);
323
+ this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`] = null;
285
324
 
286
325
  if (delay > 0) {
287
326
  // set timeout
288
- this.adapter.x.timersZoneDeviceOnDelay[zoneName+'_'+ lpTargetDeviceName] = setTimeout(()=>{ switchTargetDeviceAsync(this); }, delay * 1000);
327
+ this.adapter.x.timersZoneDeviceOnDelay[`${zoneName}_${lpTargetDeviceName}`] = setTimeout(() => {
328
+ switchTargetDeviceAsync(this);
329
+ }, delay * 1000);
289
330
  } else {
290
331
  // call right away
291
332
  await switchTargetDeviceAsync(this);
@@ -293,63 +334,92 @@ class Trigger {
293
334
 
294
335
  /**
295
336
  * Function switchTargetDevice
337
+ *
296
338
  * @param {object} that - this
297
339
  */
298
340
  async function switchTargetDeviceAsync(that) {
299
-
300
341
  try {
301
-
302
- if (!that.zoneTargetNames) return;
342
+ if (!that.zoneTargetNames) {
343
+ return;
344
+ }
303
345
 
304
346
  counterDevicesProcessed++; // +1
305
347
 
306
348
  // If target device should be switched off, and not on, per config in trigger table
307
349
  // Will be overwritten later if toggle is activated
308
- if (that.targetOff) onOff = 'off';
309
-
350
+ if (that.targetOff) {
351
+ onOff = 'off';
352
+ }
353
+
310
354
  // Toggle
311
355
  if (that.triggerIsToggle) {
312
356
  // If we have Toggle, we are using the ON state/value to check.
313
- const onState = that.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, 'onState');
314
- const onVal = that.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, 'onValue');
357
+ const onState = that.adapter.getOptionTableValue(
358
+ 'tableTargetDevices',
359
+ 'name',
360
+ lpTargetDeviceName,
361
+ 'onState',
362
+ );
363
+ const onVal = that.adapter.getOptionTableValue(
364
+ 'tableTargetDevices',
365
+ 'name',
366
+ lpTargetDeviceName,
367
+ 'onValue',
368
+ );
315
369
  const currentStateVal = await that.adapter.x.helper.asyncGetForeignStateValue(onState);
316
- if (currentStateVal == null) throw (`Could not get current state value for '${onState}' of device '${lpTargetDeviceName}'`);
370
+ if (currentStateVal == null) {
371
+ throw `Could not get current state value for '${onState}' of device '${lpTargetDeviceName}'`;
372
+ }
317
373
  if (onVal == currentStateVal) {
318
374
  onOff = 'off';
319
375
  } else {
320
376
  onOff = 'on';
321
377
  }
322
378
  }
323
-
379
+
324
380
  // Get option values.
325
- const lpTargetState = that.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, onOff + 'State');
326
- let lpTargetVal = that.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, onOff + 'Value');
327
- const noTargetCheckStr = (onOff == 'on') ? 'noTargetOnCheck' : 'noTargetOffCheck';
328
- const doNotCheckTarget = that.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetDeviceName, noTargetCheckStr);
329
-
381
+ const lpTargetState = that.adapter.getOptionTableValue(
382
+ 'tableTargetDevices',
383
+ 'name',
384
+ lpTargetDeviceName,
385
+ `${onOff}State`,
386
+ );
387
+ let lpTargetVal = that.adapter.getOptionTableValue(
388
+ 'tableTargetDevices',
389
+ 'name',
390
+ lpTargetDeviceName,
391
+ `${onOff}Value`,
392
+ );
393
+ const noTargetCheckStr = onOff == 'on' ? 'noTargetOnCheck' : 'noTargetOffCheck';
394
+ const doNotCheckTarget = that.adapter.getOptionTableValue(
395
+ 'tableTargetDevices',
396
+ 'name',
397
+ lpTargetDeviceName,
398
+ noTargetCheckStr,
399
+ );
400
+
330
401
  if (lpTargetState == undefined || lpTargetVal == undefined) {
331
- throw (`Unable to retrieve target '${onOff}' state/value for target device '${lpTargetDeviceName}'`);
402
+ throw `Unable to retrieve target '${onOff}' state/value for target device '${lpTargetDeviceName}'`;
332
403
  }
333
-
404
+
334
405
  // Overwrite target values if according value is set in Zones table
335
406
  if (onOff == 'on' && overwriteValue !== null) {
336
407
  lpTargetVal = overwriteValue;
337
408
  }
338
-
409
+
339
410
  // Let's get current state value
340
411
  let currentStateVal;
341
412
  if (!doNotCheckTarget) {
342
413
  currentStateVal = await that.adapter.x.helper.asyncGetForeignStateValue(lpTargetState);
343
414
  if (currentStateVal == null) {
344
- throw (`Could not get current state value for '${lpTargetState}' of device '${lpTargetDeviceName}'`);
415
+ throw `Could not get current state value for '${lpTargetState}' of device '${lpTargetDeviceName}'`;
345
416
  }
346
417
  }
347
-
418
+
348
419
  // Set target state.
349
420
  // Note: Verification of the state value and conversion as needed was performed already by asyncVerifyConfig()
350
421
  // Check if device is already on.
351
- if (doNotCheckTarget || (!doNotCheckTarget && (currentStateVal != lpTargetVal))) {
352
-
422
+ if (doNotCheckTarget || (!doNotCheckTarget && currentStateVal != lpTargetVal)) {
353
423
  // Set state
354
424
  await that.adapter.setForeignStateAsync(lpTargetState, { val: lpTargetVal, ack: false });
355
425
  //if (delay == 0) lSwitchedDevices.push(lpTargetDeviceName);
@@ -362,7 +432,11 @@ class Trigger {
362
432
  }
363
433
  } else {
364
434
  //Triggered by NON-motion, so remove from that.adapter.x.motionTriggeredDevices
365
- that.adapter.x.motionTriggeredDevices = that.adapter.x.helper.arrayRemoveElementByValue(that.adapter.x.motionTriggeredDevices, lpTargetDeviceName);
435
+ that.adapter.x.motionTriggeredDevices =
436
+ that.adapter.x.helper.arrayRemoveElementByValue(
437
+ that.adapter.x.motionTriggeredDevices,
438
+ lpTargetDeviceName,
439
+ );
366
440
  }
367
441
  }
368
442
  // set json log to smartcontrol.x.info.log.switchedTargetDevices.json
@@ -374,26 +448,31 @@ class Trigger {
374
448
  triggerName: that.triggerName,
375
449
  ts: Date.now(),
376
450
  });
377
-
378
451
  } else {
379
452
  // do not set target state
380
453
  // if (delay == 0) lAlreadyOnDevices.push(lpTargetDeviceName);
381
454
  lAlreadyOnDevices.push(lpTargetDeviceName);
382
455
  }
383
456
 
384
- if (counterDevicesProcessed == that.zoneTargetNames[zoneName].length) {
385
-
457
+ if (counterDevicesProcessed == that.zoneTargetNames[zoneName].length) {
386
458
  /**
387
459
  * All devices processed, so we continue here
388
460
  */
389
- if (!that.zoneTargetNames || !that.zoneNames) return;
461
+ if (!that.zoneTargetNames || !that.zoneNames) {
462
+ return;
463
+ }
390
464
 
391
465
  /**
392
466
  * Motion Trigger: If target was already turned on previously by a non-motion trigger: do not schedule timer.
393
467
  * Also, provide some log info in logMotion
394
468
  */
395
469
  let logMotion = '';
396
- if (!that.mimicMotion && that.triggerIsMotion && that.motionDuration && that.motionDuration > 0) {
470
+ if (
471
+ !that.mimicMotion &&
472
+ that.triggerIsMotion &&
473
+ that.motionDuration &&
474
+ that.motionDuration > 0
475
+ ) {
397
476
  const lRemovedDevices = [];
398
477
  if (that.motionNotIfManual) {
399
478
  for (const lpTargetDevice of lAlreadyOnDevices) {
@@ -402,7 +481,11 @@ class Trigger {
402
481
  } else {
403
482
  // Device was already on, but NO motion triggered before.
404
483
  // Therefore, we will exclude device from the timer
405
- that.zoneTargetNames[zoneName] = that.adapter.x.helper.arrayRemoveElementByValue(that.zoneTargetNames[zoneName], lpTargetDevice);
484
+ that.zoneTargetNames[zoneName] =
485
+ that.adapter.x.helper.arrayRemoveElementByValue(
486
+ that.zoneTargetNames[zoneName],
487
+ lpTargetDevice,
488
+ );
406
489
  lRemovedDevices.push(lpTargetDevice);
407
490
  }
408
491
  }
@@ -418,24 +501,30 @@ class Trigger {
418
501
  }
419
502
  }
420
503
 
421
-
422
504
  /**
423
505
  * Set "always off after" timer if set in Table Zones.
424
506
  */
425
507
  if (that.triggerIsToggle && onOff == 'off') {
426
508
  // Toggle is activated and zone is turned off, so kill/delete the timer.
427
- const zoneOffTimeLeft = that.adapter.x.helper.getTimeoutTimeLeft(that.adapter.x.timersZoneOff[zoneName]);
509
+ const zoneOffTimeLeft = that.adapter.x.helper.getTimeoutTimeLeft(
510
+ that.adapter.x.timersZoneOff[zoneName],
511
+ );
428
512
  if (zoneOffTimeLeft > -1) {
429
- that.adapter.log.debug(`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.`);
513
+ that.adapter.log.debug(
514
+ `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
+ );
430
516
  clearTimeout(that.adapter.x.timersZoneOff[zoneName]);
431
517
  that.adapter.x.timersZoneOff[zoneName] = null;
432
518
  }
433
-
434
519
  } else {
435
- if (that.triggerIsMotion && (that.zoneTargetNames[zoneName].length < 1)) {
436
- that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}], Zone '${that.zoneNames.toString()}': no 'always off after' timer set since device(s) turned on manually before.`);
520
+ if (that.triggerIsMotion && that.zoneTargetNames[zoneName].length < 1) {
521
+ that.adapter.x.helper.logExtendedInfo(
522
+ `Trigger [${that.triggerName}], Zone '${that.zoneNames.toString()}': no 'always off after' timer set since device(s) turned on manually before.`,
523
+ );
437
524
  } else {
438
- const zoneOffSecs = parseInt(that.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'offAfter'));
525
+ const zoneOffSecs = parseInt(
526
+ that.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'offAfter'),
527
+ );
439
528
  that.asyncSetZoneTimer_zoneOff('timersZoneOff', zoneName, zoneOffSecs);
440
529
  }
441
530
  }
@@ -444,75 +533,93 @@ class Trigger {
444
533
  * If "mimic motion": set off timer for zone
445
534
  */
446
535
  if (that.mimicMotion) {
447
- const zoneOffSecs = parseInt(that.adapter.getOptionTableValue('tableTriggerMotion', 'name', that.triggerName, 'motionLinkedDuration'));
448
- that.asyncSetZoneTimer_zoneOff('timersMimicMotionTrigger', zoneName, zoneOffSecs);
536
+ const zoneOffSecs = parseInt(
537
+ that.adapter.getOptionTableValue(
538
+ 'tableTriggerMotion',
539
+ 'name',
540
+ that.triggerName,
541
+ 'motionLinkedDuration',
542
+ ),
543
+ );
544
+ that.asyncSetZoneTimer_zoneOff('timersMimicMotionTrigger', zoneName, zoneOffSecs);
449
545
  }
450
546
 
451
-
452
547
  // Set "Zone is on" status
453
548
  that.adapter.x.zonesIsOn[zoneName] = true;
454
549
 
455
550
  /**
456
551
  * JSON log for info.log.zoneActivations.json
457
552
  */
458
- const alwaysOff = parseInt(that.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'offAfter'));
553
+ const alwaysOff = parseInt(
554
+ that.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'offAfter'),
555
+ );
459
556
  that.adapter.x.helper.setJsonLog('zoneActivations', {
460
557
  ts: Date.now(),
461
558
  time: that.adapter.x.helper.dateToLocalIsoString(new Date()),
462
559
  zone: zoneName,
463
- trigger: (!that.mimicMotion) ? that.triggerName : that.mimicMotionTriggerName,
560
+ trigger: !that.mimicMotion ? that.triggerName : that.mimicMotionTriggerName,
464
561
  targetsAll: that.zoneTargetNames[zoneName].toString(),
465
562
  targetsAllDelays: JSON.stringify(lDelaySecs),
466
563
  targetsSet: lSwitchedDevices.toString(),
467
564
  targetsSkipped: lAlreadyOnDevices.toString(),
468
- motionTimer: (that.motionDuration) ? that.motionDuration : 0,
469
- alwaysOffTimer: (isNaN(alwaysOff)) ? 0 : alwaysOff,
565
+ motionTimer: that.motionDuration ? that.motionDuration : 0,
566
+ alwaysOffTimer: isNaN(alwaysOff) ? 0 : alwaysOff,
470
567
  });
471
568
 
472
569
  // Finalize
473
570
  if (lSwitchedDevices.length > 0) {
474
571
  if (lAlreadyOnDevices.length < 1) {
475
- that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}] activated Zone '${zoneName}'. Turned ${onOff}: ${lSwitchedDevices.toString()}.`);
572
+ that.adapter.x.helper.logExtendedInfo(
573
+ `Trigger [${that.triggerName}] activated Zone '${zoneName}'. Turned ${onOff}: ${lSwitchedDevices.toString()}.`,
574
+ );
476
575
  } else {
477
- that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}] activated Zone '${zoneName}'. Turned ${onOff}: ${lSwitchedDevices.toString()}. Not turned ${onOff} (as already ${onOff}): '${lAlreadyOnDevices.toString()}'`);
576
+ that.adapter.x.helper.logExtendedInfo(
577
+ `Trigger [${that.triggerName}] activated Zone '${zoneName}'. Turned ${onOff}: ${lSwitchedDevices.toString()}. Not turned ${onOff} (as already ${onOff}): '${lAlreadyOnDevices.toString()}'`,
578
+ );
478
579
  }
479
580
  } else {
480
- if (lAlreadyOnDevices.length > 0) that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}] activated Zone '${zoneName}'. However, device(s) '${lAlreadyOnDevices.toString()}' not turned ${onOff} as these are already ${onOff}.`);
581
+ if (lAlreadyOnDevices.length > 0) {
582
+ that.adapter.x.helper.logExtendedInfo(
583
+ `Trigger [${that.triggerName}] activated Zone '${zoneName}'. However, device(s) '${lAlreadyOnDevices.toString()}' not turned ${onOff} as these are already ${onOff}.`,
584
+ );
585
+ }
586
+ }
587
+ if (lDelayedDevices.length > 0) {
588
+ that.adapter.x.helper.logExtendedInfo(
589
+ `Trigger [${that.triggerName}] Following device(s) will be switched ${onOff} later, since a delay was set: ${lDelayedDevices.toString()}.`,
590
+ );
591
+ }
592
+ if (logMotion) {
593
+ that.adapter.x.helper.logExtendedInfo(
594
+ `Trigger [${that.triggerName}] Zone '${zoneName}': ${logMotion}`,
595
+ );
481
596
  }
482
- if (lDelayedDevices.length > 0) that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}] Following device(s) will be switched ${onOff} later, since a delay was set: ${lDelayedDevices.toString()}.`);
483
- if (logMotion) that.adapter.x.helper.logExtendedInfo(`Trigger [${that.triggerName}] Zone '${zoneName}': ${logMotion}`);
484
-
485
597
  }
486
-
487
598
  } catch (error) {
488
599
  that.adapter.x.helper.dumpError(`[switchTargetDevice]`, error);
489
600
  return;
490
601
  }
491
-
492
602
  }
493
-
494
603
  }
495
-
496
-
497
604
  } catch (error) {
498
605
  this.adapter.x.helper.dumpError(`[_asyncSetTargetDevices_processZone]`, error);
499
606
  return;
500
607
  }
501
608
  }
502
609
 
503
-
504
610
  /**
505
611
  * Set timeout to switch devices of a zone off for zoneOff timer
612
+ *
506
613
  * @param {string} timerObjectKey - e.g. 'timersZoneOff' or 'timersMimicMotionTrigger'
507
614
  * @param {string} zoneName - Zone Name
508
615
  * @param {number} zoneOffAfter - Switch zone off after this number of seconds
509
616
  */
510
617
  async asyncSetZoneTimer_zoneOff(timerObjectKey, zoneName, zoneOffAfter) {
511
-
512
618
  try {
513
-
514
619
  if (!zoneOffAfter || zoneOffAfter < 1) {
515
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${zoneName}' No 'Always off after' time is set, so we do not set such timer.`);
620
+ this.adapter.log.debug(
621
+ `Trigger [${this.triggerName}] Zone '${zoneName}' No 'Always off after' time is set, so we do not set such timer.`,
622
+ );
516
623
  return;
517
624
  }
518
625
 
@@ -533,29 +640,42 @@ class Trigger {
533
640
 
534
641
  // Some log
535
642
  if (timeLeft > -1) {
536
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] 'zoneOff' ${zoneOffAfter}s timer still running ${(timeLeft / 1000).toFixed(0)}s. We stop it and set new to ${zoneOffAfter}s.`);
643
+ this.adapter.x.helper.logExtendedInfo(
644
+ `Trigger [${this.triggerName}] 'zoneOff' ${zoneOffAfter}s timer still running ${(timeLeft / 1000).toFixed(0)}s. We stop it and set new to ${zoneOffAfter}s.`,
645
+ );
537
646
  } else {
538
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] 'zoneOff' ${zoneOffAfter}s timer for zone '${zoneName}' initially started.`);
647
+ this.adapter.x.helper.logExtendedInfo(
648
+ `Trigger [${this.triggerName}] 'zoneOff' ${zoneOffAfter}s timer for zone '${zoneName}' initially started.`,
649
+ );
539
650
  }
540
-
541
651
  } catch (error) {
542
652
  this.adapter.x.helper.dumpError(`[asyncSetZoneTimer_zoneOff]`, error);
543
653
  return;
544
654
  }
545
-
546
655
  }
547
656
 
548
-
549
657
  /**
550
658
  * Set timeout to switch devices of a zone off, if a motion sensor was triggered and switch off time (duration) is provided.
659
+ * Ein Timer pro Zone (nicht pro Melder): sonst schaltet der zuerst abgelaufene BWM das Licht aus (#147).
660
+ *
551
661
  * @param {string} zoneName - Zone Name
552
662
  */
553
663
  async asyncSetZoneTimer_motion(zoneName) {
554
-
555
664
  try {
556
-
557
665
  // Go out if no duration is set
558
- if (!this.motionDuration || this.motionDuration <= 0) throw (`No motion duration set for ${this.triggerName}.`);
666
+ if (!this.motionDuration || this.motionDuration <= 0) {
667
+ throw `No motion duration set for ${this.triggerName}.`;
668
+ }
669
+
670
+ // Anderer BWM der Zone noch true? Dann keinen Aus-Timer starten (und laufenden löschen).
671
+ const otherMotionTrueName = await this._asyncGetOtherMotionTrueName(zoneName);
672
+ if (zoneMotionOffTimerAction(!!otherMotionTrueName) === 'skip') {
673
+ this._clearZoneMotionOffTimer(zoneName);
674
+ this.adapter.x.helper.logExtendedInfo(
675
+ `Trigger [${this.triggerName}] Motion sensor '${this.triggerName}', zone '${zoneName}': No more motion, but '${otherMotionTrueName}' still detects motion, so we do not set off timer.`,
676
+ );
677
+ return;
678
+ }
559
679
 
560
680
  // Get current target devices info
561
681
  const targets = await this._asyncGetTargetDevicesInfoOfZone(zoneName); // {statePaths:[Array of state paths], stateValues: [Array of state values], deviceNames: [Array of device names]}
@@ -565,70 +685,128 @@ class Trigger {
565
685
  return; // We already logged in _asyncGetTargetDevicesInfoOfZone()
566
686
  }
567
687
 
568
- // First: clear timers. Note: we use timeLeft since we need this anyways for log.
569
- if (this.motionTimer) {
570
- const timeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.motionTimer);
571
- if (timeLeft > -1) {
572
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${zoneName}': Timer for ${this.triggerName} still running ${(timeLeft / 1000).toFixed(0)} seconds but a new motion from this sensor detected, which is associated to same zone. Therefore, we stop timer and set new.`);
573
- clearTimeout(this.motionTimer);
574
- this.motionTimer = null;
575
- }
688
+ // Bestehenden Zonen-Timer ersetzen (nicht parallel zum Timer eines anderen Melders)
689
+ const timeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.adapter.x.timersMotionOff[zoneName]);
690
+ if (timeLeft > -1) {
691
+ this.adapter.log.debug(
692
+ `Trigger [${this.triggerName}] Zone '${zoneName}': Motion off-timer still running ${(timeLeft / 1000).toFixed(0)} seconds but another 'no motion' of this zone detected. Therefore, we stop timer and set new.`,
693
+ );
694
+ this._clearZoneMotionOffTimer(zoneName);
576
695
  }
577
696
 
578
697
  // Set timer
579
- this.motionTimer = setTimeout(() => {
580
- if (!this.motionDuration) return;
698
+ this.adapter.x.timersMotionOff[zoneName] = setTimeout(() => {
699
+ if (!this.motionDuration) {
700
+ return;
701
+ }
581
702
  this._asyncSetZoneTimer_doOnTimeout(zoneName, 'Motion', targets, this.motionDuration);
582
703
  }, this.motionDuration * 1000);
583
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Motion sensor '${this.triggerName}', zone '${zoneName}': No more motion, so we set ${this.motionDuration}s timer.`);
584
-
704
+ this.adapter.x.helper.logExtendedInfo(
705
+ `Trigger [${this.triggerName}] Motion sensor '${this.triggerName}', zone '${zoneName}': No more motion, so we set ${this.motionDuration}s timer.`,
706
+ );
585
707
  } catch (error) {
586
708
  this.adapter.x.helper.dumpError(`[asyncSetZoneTimer_motion]`, error);
587
709
  return;
588
710
  }
711
+ }
712
+
713
+ /**
714
+ * Laufenden Bewegungs-Aus-Timer dieser Zone löschen (ein Timer pro Zone).
715
+ *
716
+ * @param {string} zoneName
717
+ */
718
+ _clearZoneMotionOffTimer(zoneName) {
719
+ if (this.adapter.x.timersMotionOff[zoneName]) {
720
+ clearTimeout(this.adapter.x.timersMotionOff[zoneName]);
721
+ this.adapter.x.timersMotionOff[zoneName] = null;
722
+ }
723
+ }
589
724
 
725
+ /**
726
+ * Name eines anderen BWM derselben Zone, der noch Bewegung (true) meldet, sonst null.
727
+ *
728
+ * @param {string} zoneName
729
+ * @returns {Promise<string|null>}
730
+ */
731
+ async _asyncGetOtherMotionTrueName(zoneName) {
732
+ const otherNames = getOtherMotionTriggerNames(
733
+ this.adapter.config.tableTriggerMotion,
734
+ this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'triggers'),
735
+ this.triggerName,
736
+ );
737
+ for (const lpName of otherNames) {
738
+ const lpMotionObjId = this.adapter.getOptionTableValue('tableTriggerMotion', 'name', lpName, 'stateId');
739
+ const lpMotionObj = await this.adapter.x.helper.asyncGetForeignStateValue(lpMotionObjId);
740
+ if (lpMotionObj == true) {
741
+ return lpName;
742
+ }
743
+ }
744
+ return null;
590
745
  }
591
746
 
592
747
  /**
593
748
  * Check if additional conditions are met (like Public Holiday, etc. -- as set in conditions table).
594
- *
595
- * @param {string} name - Any name, for logging only
596
- * @param {array} conditionNames - Array of condition names
749
+ *
750
+ * @param {string} name - Any name, for logging only
751
+ * @param {Array} conditionNames - Array of condition names
597
752
  * @param {boolean} allMustMeet - if true: all conditions must be met, if false: one condition is enough
598
753
  * @param {boolean} [inverse] - if true: inverse results (true -> false, and vice versa)
599
- * @return {Promise<boolean>} True if condition(s) met, false if not. Also return true, if empty conditionNames array
754
+ * @returns {Promise<boolean>} True if condition(s) met, false if not. Also return true, if empty conditionNames array
600
755
  */
601
756
  async asyncAreScheduleConditionsMet(name, conditionNames, allMustMeet, inverse = false) {
602
-
603
757
  try {
604
-
605
758
  // If empty array, we return true, as we need to continue if no conditions are set in the options table.
606
759
  if (this.adapter.x.helper.isLikeEmpty(conditionNames)) {
607
- this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - no conditions defined, so we return "true" to continue.`);
760
+ this.adapter.log.debug(
761
+ `Trigger [${this.triggerName}], ${name} - no conditions defined, so we return "true" to continue.`,
762
+ );
608
763
  return true;
609
764
  }
610
765
 
611
766
  let hitCount = 0;
612
767
 
613
- this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - check if conditions met: '${JSON.stringify(conditionNames)}'`);
768
+ this.adapter.log.debug(
769
+ `Trigger [${this.triggerName}], ${name} - check if conditions met: '${JSON.stringify(conditionNames)}'`,
770
+ );
614
771
  const notMetConditionNames = [];
615
772
  for (const lpConditionName of conditionNames) {
773
+ if (hitCount > 0 && allMustMeet == false) {
774
+ break;
775
+ }
616
776
 
617
- if (hitCount > 0 && allMustMeet == false) break;
618
-
619
- const lpConditionStatePath = this.adapter.getOptionTableValue('tableConditions', 'name', lpConditionName, 'conditionState');
620
- const lpConditionStateValue = this.adapter.getOptionTableValue('tableConditions', 'name', lpConditionName, 'conditionValue');
777
+ const lpConditionStatePath = this.adapter.getOptionTableValue(
778
+ 'tableConditions',
779
+ 'name',
780
+ lpConditionName,
781
+ 'conditionState',
782
+ );
783
+ const lpConditionStateValue = this.adapter.getOptionTableValue(
784
+ 'tableConditions',
785
+ 'name',
786
+ lpConditionName,
787
+ 'conditionValue',
788
+ );
621
789
 
622
790
  if (!lpConditionStatePath) {
623
- this.adapter.log.error(`asyncAreScheduleConditionsMet(): condition details for '${lpConditionName}' could not be found.`);
791
+ this.adapter.log.error(
792
+ `asyncAreScheduleConditionsMet(): condition details for '${lpConditionName}' could not be found.`,
793
+ );
624
794
  notMetConditionNames.push(lpConditionName);
625
- if (allMustMeet) { break; } else { continue; }
795
+ if (allMustMeet) {
796
+ break;
797
+ } else {
798
+ continue;
799
+ }
626
800
  }
627
801
 
628
802
  const lpStateVal = await this.adapter.x.helper.asyncGetForeignStateValue(lpConditionStatePath);
629
803
  if (lpStateVal == null) {
630
804
  notMetConditionNames.push(lpConditionName);
631
- if (allMustMeet) { break; } else { continue; }
805
+ if (allMustMeet) {
806
+ break;
807
+ } else {
808
+ continue;
809
+ }
632
810
  }
633
811
 
634
812
  /**
@@ -637,146 +815,205 @@ class Trigger {
637
815
  // First: do we have comparator
638
816
  const res = this.adapter.x.helper.isNumComparatorMatching(lpStateVal, lpConditionStateValue);
639
817
  if (res.isComparator && res.result) {
640
- this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *met* (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`);
818
+ this.adapter.log.debug(
819
+ `Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *met* (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`,
820
+ );
641
821
  hitCount++;
642
- if (allMustMeet) { continue; } else { break; }
822
+ if (allMustMeet) {
823
+ continue;
824
+ } else {
825
+ break;
826
+ }
643
827
 
644
828
  // Next: no comparator, so compare directly with ==
645
829
  } else if (lpConditionStateValue == lpStateVal) {
646
- this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *met* (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`);
830
+ this.adapter.log.debug(
831
+ `Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *met* (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`,
832
+ );
647
833
  hitCount++;
648
- if (allMustMeet) { continue; } else { break; }
834
+ if (allMustMeet) {
835
+ continue;
836
+ } else {
837
+ break;
838
+ }
649
839
  } else {
650
840
  // No hit, so go out!
651
- this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *not* met (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`);
841
+ this.adapter.log.debug(
842
+ `Trigger [${this.triggerName}], ${name} - condition '${lpConditionName}' *not* met (options val = '${lpConditionStateValue}', actual state val = '${lpStateVal}')`,
843
+ );
652
844
  notMetConditionNames.push(lpConditionName);
653
- if (allMustMeet) { break; } else { continue; }
845
+ if (allMustMeet) {
846
+ break;
847
+ } else {
848
+ continue;
849
+ }
654
850
  }
655
-
656
851
  }
657
852
 
658
853
  let result = false;
659
- if ((allMustMeet && (hitCount == conditionNames.length)) || (!allMustMeet && (hitCount > 0)))
854
+ if ((allMustMeet && hitCount == conditionNames.length) || (!allMustMeet && hitCount > 0)) {
660
855
  result = true;
856
+ }
661
857
 
662
- if (inverse) result = !result;
858
+ if (inverse) {
859
+ result = !result;
860
+ }
663
861
 
664
862
  if (result) {
665
863
  this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - final result: condition matching`);
666
864
  return true;
667
- } else {
668
- if (!inverse) this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - final result: *not* matching conditions: ${notMetConditionNames.toString()}`);
669
- if (inverse) this.adapter.log.debug(`Trigger [${this.triggerName}], ${name} - final result: *not* matching conditions`); // to avoid empty 'notMetConditionNames'
670
- return false;
671
865
  }
672
-
866
+ if (!inverse) {
867
+ this.adapter.log.debug(
868
+ `Trigger [${this.triggerName}], ${name} - final result: *not* matching conditions: ${notMetConditionNames.toString()}`,
869
+ );
870
+ }
871
+ if (inverse) {
872
+ this.adapter.log.debug(
873
+ `Trigger [${this.triggerName}], ${name} - final result: *not* matching conditions`,
874
+ );
875
+ } // to avoid empty 'notMetConditionNames'
876
+ return false;
673
877
  } catch (error) {
674
878
  this.adapter.x.helper.dumpError('[asyncAreScheduleConditionsMet()]', error);
675
879
  return false;
676
880
  }
677
-
678
881
  }
679
882
 
680
883
  /**
681
884
  * Set/update zoneNames and zoneTargetNames.
682
885
  * Call once a trigger that was triggered
683
- * @return {Promise<boolean>} true if successful, false if errors
886
+ *
887
+ * @returns {Promise<boolean>} true if successful, false if errors
684
888
  */
685
889
  async _asyncUpdateCurrentActiveZones() {
686
-
687
890
  try {
688
-
689
891
  /**
690
892
  * Get zone names, and zone-specific target names and execution
691
893
  * Loop next iteration, if not successful.
692
894
  */
693
895
 
694
- this.zoneNames = Array(); // Zone names that were triggered and which match with a schedule row name
695
- this.zoneTargetNames = {}; // Target devices per zone, like {Hallway:['Hallway Light'], Bath:['Bath Light', 'Bath Radio']}
896
+ this.zoneNames = []; // Zone names that were triggered and which match with a schedule row name
897
+ this.zoneTargetNames = {}; // Target devices per zone, like {Hallway:['Hallway Light'], Bath:['Bath Light', 'Bath Radio']}
696
898
 
697
899
  for (const lpRowZones of this.adapter.config.tableZones) {
698
-
699
900
  // Loop next if item in table "Zones" is not containing any trigger name in column triggers
700
- if (!(lpRowZones.active && lpRowZones.triggers && Array.isArray(lpRowZones.triggers) && lpRowZones.triggers.includes(this.triggerName))) continue;
901
+ if (!(
902
+ lpRowZones.active &&
903
+ lpRowZones.triggers &&
904
+ Array.isArray(lpRowZones.triggers) &&
905
+ lpRowZones.triggers.includes(this.triggerName)
906
+ )) {
907
+ continue;
908
+ }
701
909
 
702
910
  // Add target devices
703
911
  this.zoneTargetNames[lpRowZones.name] = lpRowZones.targets;
704
912
 
705
913
  // Execution options
706
914
  //const executeAlways = this.adapter.config.execution[lpRowZones.name].executeAlways;
707
- const executeAlways = (lpRowZones.executeAlways) ? true : false;
915
+ const executeAlways = lpRowZones.executeAlways ? true : false;
708
916
  let tablesZoneExecution = [];
709
917
  if (executeAlways) {
710
918
  // we create a dummy to always execute
711
- tablesZoneExecution = [{
712
- active: true,
713
- executeAlways: true // This is a "dummy" key, so that we know to always execute
714
- }];
919
+ tablesZoneExecution = [
920
+ {
921
+ active: true,
922
+ executeAlways: true, // This is a "dummy" key, so that we know to always execute
923
+ },
924
+ ];
715
925
  } else {
716
- tablesZoneExecution = (lpRowZones.executionJson) ? JSON.parse(lpRowZones.executionJson) : [];
926
+ tablesZoneExecution = lpRowZones.executionJson ? JSON.parse(lpRowZones.executionJson) : [];
717
927
  }
718
928
 
719
929
  for (const lpRow of tablesZoneExecution) {
720
-
721
930
  if (lpRow.active) {
722
-
723
931
  this.adapter.log.debug(`Trigger [${this.triggerName}] === check schedule conditions ===`);
724
932
 
725
933
  if (lpRow.executeAlways) {
726
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - 'Execute always is activated, so continue'`);
934
+ this.adapter.log.debug(
935
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - 'Execute always is activated, so continue'`,
936
+ );
727
937
  this.zoneNames.push(lpRowZones.name);
728
938
  } else {
729
-
730
939
  // A few variables / constants
731
- const tsCurrent = Date.now(); // the current timestamp
732
- let doContinue = true; // flag if we can continue.
940
+ const tsCurrent = Date.now(); // the current timestamp
941
+ let doContinue = true; // flag if we can continue.
733
942
 
734
- // First – check if current time is within the schedule times
735
- if (doContinue) doContinue = this.adapter.x.helper.scheduleIsTimeStampWithinPeriod(tsCurrent, lpRow.start, lpRow.end, lpRowZones.name);
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
+ }
736
952
 
737
953
  // Next, check if current day is within the mon-sun options as set in schedules tables.
738
- if (doContinue) doContinue = this.adapter.x.helper.scheduleIsWeekdayMatching(lpRow, tsCurrent, lpRowZones.name);
954
+ if (doContinue) {
955
+ doContinue = this.adapter.x.helper.scheduleIsWeekdayMatching(
956
+ lpRow,
957
+ tsCurrent,
958
+ lpRowZones.name,
959
+ );
960
+ }
739
961
 
740
962
  // Next, check additional conditions (like Public Holiday, etc. -- as set in conditions table)
741
- if (doContinue) doContinue = await this.asyncAreScheduleConditionsMet('Zone Execution: Additional Conditions', lpRow.additionalConditions, lpRow.additionalConditionsAll);
963
+ if (doContinue) {
964
+ doContinue = await this.asyncAreScheduleConditionsMet(
965
+ 'Zone Execution: Additional Conditions',
966
+ lpRow.additionalConditions,
967
+ lpRow.additionalConditionsAll,
968
+ );
969
+ }
742
970
 
743
971
  // Next, check conditions "Never if"
744
- if (doContinue) doContinue = await this.asyncAreScheduleConditionsMet('Zone Execution: "never if" Conditions', lpRow.never, lpRow.neverAll, true);
972
+ if (doContinue) {
973
+ doContinue = await this.asyncAreScheduleConditionsMet(
974
+ 'Zone Execution: "never if" Conditions',
975
+ lpRow.never,
976
+ lpRow.neverAll,
977
+ true,
978
+ );
979
+ }
745
980
 
746
981
  // All checks done.
747
982
  if (doContinue) {
748
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row *is* meeting conditions`);
983
+ this.adapter.log.debug(
984
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row *is* meeting conditions`,
985
+ );
749
986
  /* isHit == true; */
750
987
  this.zoneNames.push(lpRowZones.name); // set matching zone name
751
988
  } else {
752
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row is *not* meeting conditions`);
989
+ this.adapter.log.debug(
990
+ `Trigger [${this.triggerName}] Zone '${lpRowZones.name}' - execution table row is *not* meeting conditions`,
991
+ );
753
992
  }
754
993
  }
755
-
756
994
  }
757
-
758
995
  }
759
-
760
996
  }
761
997
 
762
- if (this.adapter.x.helper.isLikeEmpty(this.zoneNames) || this.adapter.x.helper.isLikeEmpty(this.zoneTargetNames)) {
763
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone(s) will not be activated since no zone found which meets all conditions.`);
998
+ if (
999
+ this.adapter.x.helper.isLikeEmpty(this.zoneNames) ||
1000
+ this.adapter.x.helper.isLikeEmpty(this.zoneTargetNames)
1001
+ ) {
1002
+ this.adapter.log.debug(
1003
+ `Trigger [${this.triggerName}] Zone(s) will not be activated since no zone found which meets all conditions.`,
1004
+ );
764
1005
  return false;
765
- } else {
766
- this.adapter.log.debug(`Trigger [${this.triggerName}] - (${this.zoneNames.length}) rows in Zones table found and assigned execution table rows fetched successfully.`);
767
- return true;
768
1006
  }
769
-
770
-
1007
+ this.adapter.log.debug(
1008
+ `Trigger [${this.triggerName}] - (${this.zoneNames.length}) rows in Zones table found and assigned execution table rows fetched successfully.`,
1009
+ );
1010
+ return true;
771
1011
  } catch (error) {
772
1012
  this.adapter.x.helper.dumpError('[_asyncUpdateCurrentActiveZones]', error);
773
1013
  return false;
774
1014
  }
775
-
776
-
777
1015
  }
778
1016
 
779
-
780
1017
  /**
781
1018
  * @param {string} zoneName - Name of zone
782
1019
  * @param {string} timerTitle - For logging only.
@@ -784,15 +1021,20 @@ class Trigger {
784
1021
  * @param {number} secTimer - Number of seconds of the timer, that was set and now expired. For logging only.
785
1022
  */
786
1023
  async _asyncSetZoneTimer_doOnTimeout(zoneName, timerTitle, targets, secTimer) {
787
-
788
1024
  try {
789
-
790
1025
  // First check if tableZones 'Never switch off if...' is met
791
1026
  const neverOffConditionNames = this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'neverOff');
792
1027
  const allMustMeet = this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'neverOffAll');
793
- const switchOff = await this.asyncAreScheduleConditionsMet('Zones table - "never switch off if" condition', neverOffConditionNames, allMustMeet, true);
1028
+ const switchOff = await this.asyncAreScheduleConditionsMet(
1029
+ 'Zones table - "never switch off if" condition',
1030
+ neverOffConditionNames,
1031
+ allMustMeet,
1032
+ true,
1033
+ );
794
1034
  if (!switchOff) {
795
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Zone '${zoneName}': Timer '${timerTitle}' ended, but 'Never switch off if...' condition(s) true --> Zone will not be switched off.`);
1035
+ this.adapter.x.helper.logExtendedInfo(
1036
+ `Trigger [${this.triggerName}] Zone '${zoneName}': Timer '${timerTitle}' ended, but 'Never switch off if...' condition(s) true --> Zone will not be switched off.`,
1037
+ );
796
1038
  return; // go out
797
1039
  }
798
1040
 
@@ -800,55 +1042,31 @@ class Trigger {
800
1042
  const timerObjIds = ['timersZoneOff', 'timersMimicMotionTrigger'];
801
1043
  for (const lpTimerObjId of timerObjIds) {
802
1044
  const lpTimeLeft = this.adapter.x.helper.getTimeoutTimeLeft(this.adapter.x[lpTimerObjId][zoneName]);
803
- if (this.triggerIsMotion && (lpTimeLeft > -1)) {
1045
+ if (this.triggerIsMotion && lpTimeLeft > -1) {
804
1046
  clearTimeout(this.adapter.x[lpTimerObjId][zoneName]);
805
1047
  this.adapter.x[lpTimerObjId][zoneName] = null;
806
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${zoneName}': Clearing timer '${lpTimerObjId}', which was still running for ${(lpTimeLeft / 1000).toFixed(0)} seconds.`);
1048
+ this.adapter.log.debug(
1049
+ `Trigger [${this.triggerName}] Zone '${zoneName}': Clearing timer '${lpTimerObjId}', which was still running for ${(lpTimeLeft / 1000).toFixed(0)} seconds.`,
1050
+ );
807
1051
  }
808
1052
  }
809
-
810
1053
 
811
1054
  /* ================== START -- RESOLVING ISSUE #45 (https://github.com/Mic-M/ioBroker.smartcontrol/issues/45) */
812
1055
 
813
1056
  /**
814
- * Verify if there are other motion sensors in the same zone.
1057
+ * Verify if there are other motion sensors in the same zone.
815
1058
  * If yes and if a motion detection of one of these is still true: do not switch off zone.
816
1059
  */
817
- // Get all motion sensor trigger names
818
- const allMotionNames = [];
819
- for (const lpMotionRow of this.adapter.config.tableTriggerMotion) {
820
- if (lpMotionRow.active) {
821
- allMotionNames.push(lpMotionRow.name);
822
- }
823
- }
824
- // Get all other motion triggers assigned to zone
825
- const confZoneOtherTriggersMotion = [];
826
- const confZoneTriggersAll = this.adapter.getOptionTableValue('tableZones', 'name', zoneName, 'triggers');
827
- for (const lpTriggerName of confZoneTriggersAll) {
828
- if (allMotionNames.includes(lpTriggerName)) {
829
- if (lpTriggerName !== this.triggerName) {
830
- // we have an additional motion sensor trigger
831
- confZoneOtherTriggersMotion.push(lpTriggerName);
832
- }
833
- }
834
- }
835
-
836
- // Now check if motion state of any other motion timer is still true
837
- if (confZoneOtherTriggersMotion.length > 0) {
838
- for (const lpName of confZoneOtherTriggersMotion) {
839
- const lpMotionObjId = this.adapter.getOptionTableValue('tableTriggerMotion', 'name', lpName, 'stateId');
840
- const lpMotionObj = await this.adapter.x.helper.asyncGetForeignStateValue(lpMotionObjId);
841
- if (lpMotionObj == true) {
842
- // We have another motion sensor in same zone with motion=true, so go out.
843
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Zone '${zoneName}': Timer '${timerTitle}' ended, but another motion sensor '${lpName}' state value assigned to this zone is still true, so we will not switch off zone.' `);
844
- return; // go out
845
- }
846
- }
1060
+ const otherMotionTrueName = await this._asyncGetOtherMotionTrueName(zoneName);
1061
+ if (otherMotionTrueName) {
1062
+ this.adapter.x.helper.logExtendedInfo(
1063
+ `Trigger [${this.triggerName}] Zone '${zoneName}': Timer '${timerTitle}' ended, but another motion sensor '${otherMotionTrueName}' state value assigned to this zone is still true, so we will not switch off zone.' `,
1064
+ );
1065
+ return; // go out
847
1066
  }
848
1067
 
849
1068
  /* ================== END -- RESOLVING ISSUE #45 (https://github.com/Mic-M/ioBroker.smartcontrol/issues/45) */
850
1069
 
851
-
852
1070
  // Set "is Zone on" status to false
853
1071
  this.adapter.x.zonesIsOn[zoneName] = false;
854
1072
 
@@ -859,59 +1077,81 @@ class Trigger {
859
1077
  const lTargetDevicesSwitchedOff = []; // For Log
860
1078
  const lManualOnDevices = []; // For log
861
1079
  for (let i = 0; i < targets.statePaths.length; i++) {
862
-
863
1080
  // All are having same length and association per each element
864
1081
  const lpStatePath = targets.statePaths[i];
865
1082
  const lpStateValToSet = targets.stateValues[i];
866
1083
  const lpTargetName = targets.deviceNames[i];
867
1084
 
868
1085
  // Remove from this.adapter.x.motionTriggeredDevices
869
- if (this.motionNotIfManual) this.adapter.x.motionTriggeredDevices = this.adapter.x.helper.arrayRemoveElementByValue(this.adapter.x.motionTriggeredDevices, lpTargetName);
870
-
871
- // Check if current value != new value
872
- const targetOffStateValCurrent = await this.adapter.x.helper.asyncGetForeignStateValue(lpStatePath);
873
- if (targetOffStateValCurrent == null) {
874
- this.adapter.log.error(`Timer '${timerTitle}', trigger '${this.triggerName}', target ${lpTargetName}: - Timeout of '${secTimer}' seconds reached, but could not get current state value of '${lpStatePath}', so unable to turn device off.`);
875
- continue;
1086
+ if (this.motionNotIfManual) {
1087
+ this.adapter.x.motionTriggeredDevices = this.adapter.x.helper.arrayRemoveElementByValue(
1088
+ this.adapter.x.motionTriggeredDevices,
1089
+ lpTargetName,
1090
+ );
876
1091
  }
877
- if (lpStateValToSet == targetOffStateValCurrent) {
878
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Timer '${timerTitle}', target ${lpTargetName}: - Timeout of '${secTimer}' seconds reached, target is already turned off, so not turning off again.`);
879
- continue;
1092
+
1093
+ // „Prüfung deaktiv. (aus)“: bei Buttons immer schreiben, auch wenn der Wert schon passt (#7).
1094
+ // Beim Einschalten macht switchTargetDeviceAsync das schon; der Aus-Timer hat das bisher ignoriert.
1095
+ const doNotCheckTargetOff = this.adapter.getOptionTableValue(
1096
+ 'tableTargetDevices',
1097
+ 'name',
1098
+ lpTargetName,
1099
+ 'noTargetOffCheck',
1100
+ );
1101
+ if (!doNotCheckTargetOff) {
1102
+ const targetOffStateValCurrent = await this.adapter.x.helper.asyncGetForeignStateValue(lpStatePath);
1103
+ if (targetOffStateValCurrent == null) {
1104
+ this.adapter.log.error(
1105
+ `Timer '${timerTitle}', trigger '${this.triggerName}', target ${lpTargetName}: - Timeout of '${secTimer}' seconds reached, but could not get current state value of '${lpStatePath}', so unable to turn device off.`,
1106
+ );
1107
+ continue;
1108
+ }
1109
+ if (lpStateValToSet == targetOffStateValCurrent) {
1110
+ this.adapter.x.helper.logExtendedInfo(
1111
+ `Trigger [${this.triggerName}] Timer '${timerTitle}', target ${lpTargetName}: - Timeout of '${secTimer}' seconds reached, target is already turned off, so not turning off again.`,
1112
+ );
1113
+ continue;
1114
+ }
880
1115
  }
881
1116
 
882
1117
  // All passed.
883
1118
  await this.adapter.setForeignStateAsync(lpStatePath, { val: lpStateValToSet, ack: false });
884
1119
  lTargetDevicesSwitchedOff.push(lpTargetName);
885
-
886
1120
  }
887
1121
 
888
1122
  // Log
889
1123
  if (lManualOnDevices.length > 0) {
890
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Timer '${timerTitle}', target(s) '${lManualOnDevices.toString()}': - Timeout of '${secTimer}' seconds reached, target(s) manually turned on while timer was running, so do not turn off.`);
1124
+ this.adapter.x.helper.logExtendedInfo(
1125
+ `Trigger [${this.triggerName}] Timer '${timerTitle}', target(s) '${lManualOnDevices.toString()}': - Timeout of '${secTimer}' seconds reached, target(s) manually turned on while timer was running, so do not turn off.`,
1126
+ );
891
1127
  }
892
1128
  if (lTargetDevicesSwitchedOff.length > 0) {
893
- this.adapter.x.helper.logExtendedInfo(`Trigger [${this.triggerName}] Timer '${timerTitle}', target(s) '${lTargetDevicesSwitchedOff.toString()}': - Turned off per ${secTimer}s timer.`);
1129
+ this.adapter.x.helper.logExtendedInfo(
1130
+ `Trigger [${this.triggerName}] Timer '${timerTitle}', target(s) '${lTargetDevicesSwitchedOff.toString()}': - Turned off per ${secTimer}s timer.`,
1131
+ );
894
1132
  }
895
-
896
-
897
1133
  } catch (error) {
898
1134
  this.adapter.x.helper.dumpError('[asyncSetZoneTimer_doOnTimeout]', error);
899
1135
  return;
900
1136
  }
901
-
902
1137
  }
903
1138
 
904
1139
  /**
905
- * Get target device info for a given zone name.
1140
+ * Get target device info for a given zone name.
1141
+ *
906
1142
  * @param {string} zoneName - Zone Name
907
- * @return {Promise<object|null>} - Object: {statePaths:[Array of state paths], stateValues: [Array of state values], deviceNames: [Array of device names]}. null if not found/errors.
1143
+ * @returns {Promise<object|null>} - Object: {statePaths:[Array of state paths], stateValues: [Array of state values], deviceNames: [Array of device names]}. null if not found/errors.
908
1144
  */
909
1145
  async _asyncGetTargetDevicesInfoOfZone(zoneName) {
910
-
911
1146
  try {
912
-
913
- if (!this.zoneTargetNames || !this.zoneTargetNames[zoneName] || this.adapter.x.helper.isLikeEmpty(this.zoneTargetNames[zoneName])) {
914
- this.adapter.log.debug(`Trigger [${this.triggerName}] Zone '${zoneName}': No current target devices found for timer to switch devices off, likely because all were turned on manually before`);
1147
+ if (
1148
+ !this.zoneTargetNames ||
1149
+ !this.zoneTargetNames[zoneName] ||
1150
+ this.adapter.x.helper.isLikeEmpty(this.zoneTargetNames[zoneName])
1151
+ ) {
1152
+ this.adapter.log.debug(
1153
+ `Trigger [${this.triggerName}] Zone '${zoneName}': No current target devices found for timer to switch devices off, likely because all were turned on manually before`,
1154
+ );
915
1155
  return null;
916
1156
  }
917
1157
  const targetDevices = this.zoneTargetNames[zoneName];
@@ -919,18 +1159,28 @@ class Trigger {
919
1159
 
920
1160
  // Get all target device state paths and values
921
1161
  const targets = {
922
- statePaths: Array(), // Would use [] instead of Array(), but see: https://stackoverflow.com/a/56394664
923
- stateValues: Array(),
924
- deviceNames: Array(),
1162
+ statePaths: [], // Would use [] instead of Array(), but see: https://stackoverflow.com/a/56394664
1163
+ stateValues: [],
1164
+ deviceNames: [],
925
1165
  };
926
1166
 
927
1167
  for (const lpTargetName of targetDevices) {
928
1168
  // Get target device information
929
- const targetOffState = this.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetName, 'offState');
930
- const targetOffVal = this.adapter.getOptionTableValue('tableTargetDevices', 'name', lpTargetName, 'offValue');
1169
+ const targetOffState = this.adapter.getOptionTableValue(
1170
+ 'tableTargetDevices',
1171
+ 'name',
1172
+ lpTargetName,
1173
+ 'offState',
1174
+ );
1175
+ const targetOffVal = this.adapter.getOptionTableValue(
1176
+ 'tableTargetDevices',
1177
+ 'name',
1178
+ lpTargetName,
1179
+ 'offValue',
1180
+ );
931
1181
 
932
1182
  if (targetOffState == undefined || targetOffVal == undefined) {
933
- throw (`Unable to retrieve target off state/value for target device '${lpTargetName}' from adapter config.`);
1183
+ throw `Unable to retrieve target off state/value for target device '${lpTargetName}' from adapter config.`;
934
1184
  }
935
1185
 
936
1186
  // Target Off State
@@ -947,19 +1197,14 @@ class Trigger {
947
1197
 
948
1198
  // Go out if we actually have no devices to turn off
949
1199
  if (this.adapter.x.helper.isLikeEmpty(targets.statePaths)) {
950
- throw (`Zone '${zoneName}': --> No target states found in adapter settings, so no timer will be set to turn off.`);
1200
+ throw `Zone '${zoneName}': --> No target states found in adapter settings, so no timer will be set to turn off.`;
951
1201
  }
952
1202
 
953
1203
  return targets;
954
-
955
1204
  } catch (error) {
956
1205
  this.adapter.x.helper.dumpError(`[asyncGetTargetDevicesInfoOfZone]`, error);
957
1206
  return null;
958
1207
  }
959
-
960
1208
  }
961
-
962
-
963
-
964
1209
  }
965
- module.exports = Trigger;
1210
+ module.exports = Trigger;