iobroker.alarm 3.3.1 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/io-package.json +40 -13
- package/main.js +107 -138
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
******************************************************************************************
|
|
26
26
|
<!--
|
|
27
27
|
Placeholder for the next version (at the beginning of the line):
|
|
28
|
-
|
|
28
|
+
### **WORK IN PROGRESS**
|
|
29
29
|
-->
|
|
30
|
+
### 3.3.4 (2022-12-22)
|
|
31
|
+
* (misanorot) fixed issues
|
|
30
32
|
|
|
31
|
-
## Changelog
|
|
32
33
|
### 3.3.1 (2022-12-22)
|
|
33
34
|
* (misanorot) update files to last creator pattern
|
|
34
35
|
* (misanorot) fixed zones
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "alarm",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.4",
|
|
5
5
|
"news": {
|
|
6
|
+
"3.3.4": {
|
|
7
|
+
"en": "fixed issues",
|
|
8
|
+
"de": "feste probleme",
|
|
9
|
+
"ru": "фиксированные вопросы",
|
|
10
|
+
"pt": "problemas",
|
|
11
|
+
"nl": "_",
|
|
12
|
+
"fr": "questions fixes",
|
|
13
|
+
"it": "questioni fisse",
|
|
14
|
+
"es": "cuestiones fijas",
|
|
15
|
+
"pl": "ustalenie",
|
|
16
|
+
"uk": "виправлені питання",
|
|
17
|
+
"zh-cn": "固定问题"
|
|
18
|
+
},
|
|
19
|
+
"3.3.3": {
|
|
20
|
+
"en": "fixed issues",
|
|
21
|
+
"de": "feste probleme",
|
|
22
|
+
"ru": "фиксированные вопросы",
|
|
23
|
+
"pt": "problemas",
|
|
24
|
+
"nl": "_",
|
|
25
|
+
"fr": "questions fixes",
|
|
26
|
+
"it": "questioni fisse",
|
|
27
|
+
"es": "cuestiones fijas",
|
|
28
|
+
"pl": "ustalenie",
|
|
29
|
+
"uk": "виправлені питання",
|
|
30
|
+
"zh-cn": "固定问题"
|
|
31
|
+
},
|
|
32
|
+
"3.3.2": {
|
|
33
|
+
"en": "fixed issues",
|
|
34
|
+
"de": "feste probleme",
|
|
35
|
+
"ru": "фиксированные вопросы",
|
|
36
|
+
"pt": "problemas",
|
|
37
|
+
"nl": "_",
|
|
38
|
+
"fr": "questions fixes",
|
|
39
|
+
"it": "questioni fisse",
|
|
40
|
+
"es": "cuestiones fijas",
|
|
41
|
+
"pl": "ustalenie",
|
|
42
|
+
"uk": "виправлені питання",
|
|
43
|
+
"zh-cn": "固定问题"
|
|
44
|
+
},
|
|
6
45
|
"3.3.1": {
|
|
7
46
|
"en": "* update files to last creator pattern\n* fixed zones\n* translate states names and discription\n* added password state for deactivation\n\n#### 3.2.0 (15.10.2022)\n* fixed enableable\n* added presence simulation\n* added zones\n* fixed set number states",
|
|
8
47
|
"de": "* aktualisieren von dateien zum letzten schöpfermuster\n* festzonen\n* übersetzen namen und discription\n* passwort-zustand zur deaktivierung hinzugefügt\n\n3,2.0 (15.10.2022)\n* feststellbar\n* zusätzliche präsenzsimulation\n* zusätzliche zonen\n* feste set-nummern",
|
|
@@ -53,18 +92,6 @@
|
|
|
53
92
|
"es": "intervalo de tiempo añadido para la salida del habla de alarma",
|
|
54
93
|
"pl": "dodać czas trwania mowy alarmowej",
|
|
55
94
|
"zh-cn": "警觉产出增加时间"
|
|
56
|
-
},
|
|
57
|
-
"3.1.0": {
|
|
58
|
-
"en": "added speech delay",
|
|
59
|
-
"de": "Sprachverzögerung hinzugefügt",
|
|
60
|
-
"ru": "добавлена задержка речи",
|
|
61
|
-
"pt": "atraso de fala adicionado",
|
|
62
|
-
"nl": "spraakvertraging toegevoegd",
|
|
63
|
-
"fr": "délai de parole ajouté",
|
|
64
|
-
"it": "aggiunto ritardo del discorso",
|
|
65
|
-
"es": "retardo de voz añadido",
|
|
66
|
-
"pl": "dodano opóźnienie mowy",
|
|
67
|
-
"zh-cn": "增加语音延迟"
|
|
68
95
|
}
|
|
69
96
|
},
|
|
70
97
|
"title": "Alarm",
|
package/main.js
CHANGED
|
@@ -70,8 +70,9 @@ let activated = false,
|
|
|
70
70
|
inside = false,
|
|
71
71
|
burgle = false;
|
|
72
72
|
|
|
73
|
-
let timer = null
|
|
74
|
-
|
|
73
|
+
let timer = null;
|
|
74
|
+
|
|
75
|
+
let speech_timeout = null,
|
|
75
76
|
silent_timer = null,
|
|
76
77
|
siren_inside_timer = null,
|
|
77
78
|
timer_notification_changes = null,
|
|
@@ -159,7 +160,7 @@ class Alarm extends utils.Adapter {
|
|
|
159
160
|
onStateChange(id, state) {
|
|
160
161
|
if (state) {
|
|
161
162
|
// The state was changed
|
|
162
|
-
this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
|
|
163
|
+
//this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
|
|
163
164
|
this.change(id, state);
|
|
164
165
|
} else {
|
|
165
166
|
// The state was deleted
|
|
@@ -190,60 +191,31 @@ class Alarm extends utils.Adapter {
|
|
|
190
191
|
shorts_in = this.config.shorts_in;
|
|
191
192
|
alarm_repeat = parseInt(this.config.alarm_repeat);
|
|
192
193
|
//changes_repeat = parseInt(this.config.changes_repeat);
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
opt_presence = false;
|
|
214
|
-
this.setState('presence.on_off', false, true);
|
|
215
|
-
} else opt_presence = state.val;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
this.getState('status.sleep', (err, state) => {
|
|
219
|
-
if (err) {
|
|
220
|
-
this.log.error(err);
|
|
221
|
-
//this.setState('info.connection', false, true);
|
|
222
|
-
return;
|
|
223
|
-
} else {
|
|
224
|
-
if (state == null) {
|
|
225
|
-
night_rest = false;
|
|
226
|
-
this.setState('status.sleep', false, true);
|
|
227
|
-
} else night_rest = state.val;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
this.getState('status.sharp_inside_activated', (err, state) => {
|
|
231
|
-
if (err) {
|
|
232
|
-
this.log.error(err);
|
|
233
|
-
//this.setState('info.connection', false, true);
|
|
234
|
-
return;
|
|
235
|
-
} else {
|
|
236
|
-
if (state == null) {
|
|
237
|
-
inside = false;
|
|
238
|
-
this.setState('status.sharp_inside_activated', false, true);
|
|
239
|
-
} else inside = state.val;
|
|
240
|
-
}
|
|
241
|
-
});
|
|
194
|
+
const stateA = await this.getStateAsync('status.activated').catch((e) => this.log.warn(e));
|
|
195
|
+
if (stateA == null) {
|
|
196
|
+
activated = false;
|
|
197
|
+
this.setState('status.activated', false, true);
|
|
198
|
+
} else activated = stateA.val;
|
|
199
|
+
const stateP = await this.getStateAsync('presence.on_off').catch((e) => this.log.warn(e));
|
|
200
|
+
if (stateP == null) {
|
|
201
|
+
opt_presence = false;
|
|
202
|
+
this.setState('presence.on_off', false, true);
|
|
203
|
+
} else opt_presence = stateP.val;
|
|
204
|
+
const stateS = await this.getStateAsync('status.sleep').catch((e) => this.log.warn(e));
|
|
205
|
+
if (stateS == null) {
|
|
206
|
+
night_rest = false;
|
|
207
|
+
this.setState('status.sleep', false, true);
|
|
208
|
+
} else night_rest = stateS.val;
|
|
209
|
+
const stateI = await this.getStateAsync('status.sharp_inside_activated').catch((e) => this.log.warn(e));
|
|
210
|
+
if (stateI == null) {
|
|
211
|
+
inside = false;
|
|
212
|
+
this.setState('status.sharp_inside_activated', false, true);
|
|
213
|
+
} else inside = stateI.val;
|
|
242
214
|
if (this.config.circuits) this.split_states(this.config.circuits);
|
|
243
215
|
else this.log.info('no states configured!');
|
|
244
|
-
send_instances =
|
|
216
|
+
send_instances = this.split_arr(this.config.sendTo);
|
|
245
217
|
this.log.debug(`Messages to: ${JSON.stringify(send_instances)}`);
|
|
246
|
-
ids_shorts_input =
|
|
218
|
+
ids_shorts_input = this.get_short_ids(shorts_in);
|
|
247
219
|
await this.get_ids();
|
|
248
220
|
await this.get_states();
|
|
249
221
|
await this.get_other_states();
|
|
@@ -255,7 +227,7 @@ class Alarm extends utils.Adapter {
|
|
|
255
227
|
}
|
|
256
228
|
//################# ENABLE ####################################################
|
|
257
229
|
|
|
258
|
-
|
|
230
|
+
enableSystem(_id, _state) {
|
|
259
231
|
if (activated || burgle) return;
|
|
260
232
|
let say = this.config.text_failed;
|
|
261
233
|
if (timer) {
|
|
@@ -306,7 +278,7 @@ class Alarm extends utils.Adapter {
|
|
|
306
278
|
|
|
307
279
|
//################# DISABLE ####################################################
|
|
308
280
|
|
|
309
|
-
|
|
281
|
+
disableSystem() {
|
|
310
282
|
burgle = false;
|
|
311
283
|
clearTimeout(silent_timer);
|
|
312
284
|
clearTimeout(siren_timer);
|
|
@@ -345,7 +317,7 @@ class Alarm extends utils.Adapter {
|
|
|
345
317
|
|
|
346
318
|
//################# BURGALARY ####################################################
|
|
347
319
|
|
|
348
|
-
|
|
320
|
+
burglary(id, _state, silent, indoor) {
|
|
349
321
|
if (burgle) return;
|
|
350
322
|
if (silent_timer && silent) return;
|
|
351
323
|
let count = 0;
|
|
@@ -459,7 +431,7 @@ class Alarm extends utils.Adapter {
|
|
|
459
431
|
|
|
460
432
|
//################# PANIC ####################################################
|
|
461
433
|
|
|
462
|
-
|
|
434
|
+
panic() {
|
|
463
435
|
let count = 0;
|
|
464
436
|
is_panic = true;
|
|
465
437
|
this.setState('info.log', `${this.config.log_panic}`, true);
|
|
@@ -499,7 +471,7 @@ class Alarm extends utils.Adapter {
|
|
|
499
471
|
|
|
500
472
|
//################# CHANGES ####################################################
|
|
501
473
|
|
|
502
|
-
|
|
474
|
+
change(id, state) {
|
|
503
475
|
let is_not_change = false;
|
|
504
476
|
for (const i in states) {
|
|
505
477
|
if (i === id) {
|
|
@@ -574,7 +546,7 @@ class Alarm extends utils.Adapter {
|
|
|
574
546
|
this.countdown(false);
|
|
575
547
|
break;
|
|
576
548
|
case 1:
|
|
577
|
-
if (!activated) this.
|
|
549
|
+
if (!activated) this.enableSystem(id, state);
|
|
578
550
|
break;
|
|
579
551
|
case 2:
|
|
580
552
|
this.inside_begins();
|
|
@@ -598,7 +570,7 @@ class Alarm extends utils.Adapter {
|
|
|
598
570
|
this.inside_begins();
|
|
599
571
|
break;
|
|
600
572
|
case 1:
|
|
601
|
-
if (!activated) this.
|
|
573
|
+
if (!activated) this.enableSystem(id, state);
|
|
602
574
|
break;
|
|
603
575
|
case 2:
|
|
604
576
|
this.sleep_begin();
|
|
@@ -619,7 +591,7 @@ class Alarm extends utils.Adapter {
|
|
|
619
591
|
if (opt_presence) {
|
|
620
592
|
presenceDelay_timer = setTimeout(() => {
|
|
621
593
|
this.setAllPresenceTimer(() => {
|
|
622
|
-
presenceInterval = setInterval(this.checkPresence, 60000);
|
|
594
|
+
presenceInterval = setInterval(() => { this.checkPresence(); }, 60000);
|
|
623
595
|
});
|
|
624
596
|
}, this.timeMode(this.config.presence_activate_delay_select) * this.config.presence_activate_delay);
|
|
625
597
|
}
|
|
@@ -720,7 +692,7 @@ class Alarm extends utils.Adapter {
|
|
|
720
692
|
return;
|
|
721
693
|
}
|
|
722
694
|
else if (id === this.namespace + '.use.enable' && state.val) {
|
|
723
|
-
this.
|
|
695
|
+
this.enableSystem(id, state);
|
|
724
696
|
return;
|
|
725
697
|
}
|
|
726
698
|
else if (id === this.namespace + '.use.disable' && state.val) {
|
|
@@ -745,7 +717,7 @@ class Alarm extends utils.Adapter {
|
|
|
745
717
|
}
|
|
746
718
|
else if (id === this.namespace + '.use.disable_password') {
|
|
747
719
|
if (state.val == '') return;
|
|
748
|
-
if (
|
|
720
|
+
if (this.checkMyPassword(state.val, 'use.disable_password') && (activated || inside)) {
|
|
749
721
|
this.countdown(false);
|
|
750
722
|
return;
|
|
751
723
|
} else {
|
|
@@ -762,10 +734,10 @@ class Alarm extends utils.Adapter {
|
|
|
762
734
|
}
|
|
763
735
|
else if (id === this.namespace + '.use.toggle_password') {
|
|
764
736
|
if (state.val == '') return;
|
|
765
|
-
if (
|
|
766
|
-
this.
|
|
737
|
+
if (this.checkMyPassword(state.val, 'use.toggle_password') && !activated) {
|
|
738
|
+
this.enableSystem(id, state);
|
|
767
739
|
return;
|
|
768
|
-
} else if (
|
|
740
|
+
} else if (this.checkMyPassword(state.val, 'use.toggle_password') && activated) {
|
|
769
741
|
this.countdown(false);
|
|
770
742
|
//disableSystem();
|
|
771
743
|
return;
|
|
@@ -783,10 +755,10 @@ class Alarm extends utils.Adapter {
|
|
|
783
755
|
}
|
|
784
756
|
else if (id === this.namespace + '.use.toggle_with_delay_and_password') {
|
|
785
757
|
if (state.val == '') return;
|
|
786
|
-
if (
|
|
758
|
+
if (this.checkMyPassword(state.val, 'use.toggle_with_delay_and_password') && !activated) {
|
|
787
759
|
this.countdown(true);
|
|
788
760
|
return;
|
|
789
|
-
} else if (
|
|
761
|
+
} else if (this.checkMyPassword(state.val, 'use.toggle_with_delay_and_password') && activated) {
|
|
790
762
|
this.countdown(false);
|
|
791
763
|
//disableSystem();
|
|
792
764
|
return;
|
|
@@ -814,15 +786,15 @@ class Alarm extends utils.Adapter {
|
|
|
814
786
|
this.leaving(id, state);
|
|
815
787
|
return;
|
|
816
788
|
}
|
|
817
|
-
if (alarm_ids.includes(id) && activated &&
|
|
789
|
+
if (alarm_ids.includes(id) && activated && this.isTrue(id, state, 'main')) {
|
|
818
790
|
this.burglary(id, state, this.isSilent(id));
|
|
819
791
|
return;
|
|
820
792
|
}
|
|
821
|
-
if (inside_ids.includes(id) && inside &&
|
|
793
|
+
if (inside_ids.includes(id) && inside && this.isTrue(id, state, 'main')) {
|
|
822
794
|
this.burglary(id, state, this.isSilent(id, true), true);
|
|
823
795
|
}
|
|
824
796
|
|
|
825
|
-
if (notification_ids.includes(id) &&
|
|
797
|
+
if (notification_ids.includes(id) && this.isTrue(id, state, 'main')) {
|
|
826
798
|
if (!activated && !inside && !night_rest) return;
|
|
827
799
|
const name = this.get_name(id);
|
|
828
800
|
this.setState('info.log', `${this.config.log_warn} ${name}`, true);
|
|
@@ -851,7 +823,7 @@ class Alarm extends utils.Adapter {
|
|
|
851
823
|
this.setState('info.notification_circuit_changes', false, true);
|
|
852
824
|
}, this.timeMode(this.config.time_warning_select) * this.config.time_warning);
|
|
853
825
|
}
|
|
854
|
-
if (one_ids.includes(id) &&
|
|
826
|
+
if (one_ids.includes(id) && this.isTrue(id, state, 'one')) {
|
|
855
827
|
const name = this.get_name(id, 'one');
|
|
856
828
|
let say = this.config.text_one;
|
|
857
829
|
if (log) this.log.info(`${this.config.log_one} ${name}`);
|
|
@@ -862,7 +834,7 @@ class Alarm extends utils.Adapter {
|
|
|
862
834
|
this.sayit(say, 12);
|
|
863
835
|
this.setState('other_alarms.one_changes', true, true);
|
|
864
836
|
}
|
|
865
|
-
if (two_ids.includes(id) &&
|
|
837
|
+
if (two_ids.includes(id) && this.isTrue(id, state, 'two')) {
|
|
866
838
|
const name = this.get_name(id, 'two');
|
|
867
839
|
let say = this.config.text_two;
|
|
868
840
|
if (log) this.log.info(`${this.config.log_two} ${name}`);
|
|
@@ -873,17 +845,17 @@ class Alarm extends utils.Adapter {
|
|
|
873
845
|
this.sayit(say, 13);
|
|
874
846
|
this.setState('other_alarms.two_changes', true, true);
|
|
875
847
|
}
|
|
876
|
-
if (zone_one_ids.includes(id) &&
|
|
848
|
+
if (zone_one_ids.includes(id) && this.isTrue(id, state, 'zone_one')) {
|
|
877
849
|
const name = this.get_name(id, 'zone_one');
|
|
878
850
|
if (log) this.log.info(`${this.config.log_zone_one} ${name}`);
|
|
879
851
|
if (this.config.send_zone_one) this.messages(`${this.config.log_zone_one} ${name}`);
|
|
880
852
|
}
|
|
881
|
-
if (zone_two_ids.includes(id) &&
|
|
853
|
+
if (zone_two_ids.includes(id) && this.isTrue(id, state, 'zone_two')) {
|
|
882
854
|
const name = this.get_name(id, 'zone_two');
|
|
883
855
|
if (log) this.log.info(`${this.config.log_zone_two} ${name}`);
|
|
884
856
|
if (this.config.send_zone_two) this.messages(`${this.config.log_zone_two} ${name}`);
|
|
885
857
|
}
|
|
886
|
-
if (zone_three_ids.includes(id) &&
|
|
858
|
+
if (zone_three_ids.includes(id) && this.isTrue(id, state, 'zone_three')) {
|
|
887
859
|
const name = this.get_name(id, 'zone_three');
|
|
888
860
|
if (log) this.log.info(`${this.config.log_zone_three} ${name}`);
|
|
889
861
|
if (this.config.send_zone_three) this.messages(`${this.config.log_zone_three} ${name}`);
|
|
@@ -964,7 +936,7 @@ class Alarm extends utils.Adapter {
|
|
|
964
936
|
|
|
965
937
|
//################# MESSAGES ###################################################
|
|
966
938
|
|
|
967
|
-
|
|
939
|
+
messages(content) {
|
|
968
940
|
if (send_instances.length) {
|
|
969
941
|
const reg = new RegExp('telegram');
|
|
970
942
|
send_instances.forEach((ele) => {
|
|
@@ -979,7 +951,7 @@ class Alarm extends utils.Adapter {
|
|
|
979
951
|
}
|
|
980
952
|
}
|
|
981
953
|
|
|
982
|
-
|
|
954
|
+
speechOutput(id, message, time) {
|
|
983
955
|
let delay;
|
|
984
956
|
time = parseInt(time);
|
|
985
957
|
if (Number.isInteger(time)) {
|
|
@@ -996,7 +968,7 @@ class Alarm extends utils.Adapter {
|
|
|
996
968
|
}
|
|
997
969
|
|
|
998
970
|
|
|
999
|
-
|
|
971
|
+
sayit(message, opt_val) {
|
|
1000
972
|
const tts_instance = this.config.sayit;
|
|
1001
973
|
if (night_rest && this.config.opt_night_silent) return;
|
|
1002
974
|
if (tts_instance) {
|
|
@@ -1085,7 +1057,7 @@ class Alarm extends utils.Adapter {
|
|
|
1085
1057
|
|
|
1086
1058
|
//################# HELPERS ####################################################
|
|
1087
1059
|
|
|
1088
|
-
|
|
1060
|
+
alarmSiren() {
|
|
1089
1061
|
this.setState('status.siren', true, true);
|
|
1090
1062
|
siren_timer = setTimeout(() => {
|
|
1091
1063
|
this.setState('status.siren', false, true);
|
|
@@ -1093,7 +1065,7 @@ class Alarm extends utils.Adapter {
|
|
|
1093
1065
|
}, this.timeMode(this.config.time_alarm_select) * this.config.time_alarm);
|
|
1094
1066
|
}
|
|
1095
1067
|
|
|
1096
|
-
|
|
1068
|
+
alarmFlash() {
|
|
1097
1069
|
if (this.config.alarm_flash > 0) {
|
|
1098
1070
|
alarm_interval = setInterval(() => {
|
|
1099
1071
|
if (alarm_i) {
|
|
@@ -1107,7 +1079,7 @@ class Alarm extends utils.Adapter {
|
|
|
1107
1079
|
}
|
|
1108
1080
|
}
|
|
1109
1081
|
|
|
1110
|
-
|
|
1082
|
+
disableStates() {
|
|
1111
1083
|
this.setState('status.deactivated', true, true);
|
|
1112
1084
|
this.setState('status.state', 'deactivated', true);
|
|
1113
1085
|
this.setState('status.state_list', 0, true);
|
|
@@ -1145,7 +1117,7 @@ class Alarm extends utils.Adapter {
|
|
|
1145
1117
|
|
|
1146
1118
|
}
|
|
1147
1119
|
|
|
1148
|
-
|
|
1120
|
+
isSilent(id, indoor) {
|
|
1149
1121
|
if (indoor) {
|
|
1150
1122
|
const temp = this.config.circuits.findIndex((obj) => {
|
|
1151
1123
|
const reg = new RegExp(id);
|
|
@@ -1162,7 +1134,7 @@ class Alarm extends utils.Adapter {
|
|
|
1162
1134
|
|
|
1163
1135
|
}
|
|
1164
1136
|
|
|
1165
|
-
|
|
1137
|
+
timeMode(value) {
|
|
1166
1138
|
let temp;
|
|
1167
1139
|
switch (value) {
|
|
1168
1140
|
case 'sec':
|
|
@@ -1178,7 +1150,7 @@ class Alarm extends utils.Adapter {
|
|
|
1178
1150
|
}
|
|
1179
1151
|
|
|
1180
1152
|
|
|
1181
|
-
|
|
1153
|
+
inside_begins() {
|
|
1182
1154
|
if (!inside && !burgle) {
|
|
1183
1155
|
activated = false;
|
|
1184
1156
|
inside = true;
|
|
@@ -1209,7 +1181,7 @@ class Alarm extends utils.Adapter {
|
|
|
1209
1181
|
}
|
|
1210
1182
|
}
|
|
1211
1183
|
|
|
1212
|
-
|
|
1184
|
+
inside_ends(off) {
|
|
1213
1185
|
if (inside) {
|
|
1214
1186
|
inside = false;
|
|
1215
1187
|
if (off) {
|
|
@@ -1226,7 +1198,7 @@ class Alarm extends utils.Adapter {
|
|
|
1226
1198
|
}
|
|
1227
1199
|
}
|
|
1228
1200
|
|
|
1229
|
-
|
|
1201
|
+
sleep_begin(auto) {
|
|
1230
1202
|
if (night_rest) return;
|
|
1231
1203
|
if (auto && inside || auto && activated) {
|
|
1232
1204
|
this.log.warn(`Cannot set alarm system to night rest, it is sharp or sharp inside`);
|
|
@@ -1255,7 +1227,7 @@ class Alarm extends utils.Adapter {
|
|
|
1255
1227
|
}
|
|
1256
1228
|
}
|
|
1257
1229
|
|
|
1258
|
-
|
|
1230
|
+
sleep_end(off) {
|
|
1259
1231
|
if (night_rest) {
|
|
1260
1232
|
night_rest = false;
|
|
1261
1233
|
if (off) {
|
|
@@ -1375,7 +1347,7 @@ class Alarm extends utils.Adapter {
|
|
|
1375
1347
|
}
|
|
1376
1348
|
|
|
1377
1349
|
|
|
1378
|
-
|
|
1350
|
+
checkMyPassword(pass, id) {
|
|
1379
1351
|
if (this.config.password === pass) {
|
|
1380
1352
|
this.log.debug(`Password accept`);
|
|
1381
1353
|
this.setState('info.wrong_password', false, true, (err) => {
|
|
@@ -1615,16 +1587,18 @@ class Alarm extends utils.Adapter {
|
|
|
1615
1587
|
this.log.debug(`zone one: ${JSON.stringify(zone_one_states)} zone two: ${JSON.stringify(zone_two_states)} zone three: ${JSON.stringify(zone_three_states)}`);
|
|
1616
1588
|
}
|
|
1617
1589
|
|
|
1618
|
-
|
|
1590
|
+
leaving(_id, _state) {
|
|
1591
|
+
this.log.info(`Leaving state triggerd`);
|
|
1619
1592
|
clearInterval(timer);
|
|
1620
1593
|
timer = null;
|
|
1621
1594
|
this.setState('status.activation_countdown', null, true);
|
|
1622
1595
|
this.setState('status.gets_activated', false, true);
|
|
1623
|
-
this.
|
|
1596
|
+
this.enableSystem();
|
|
1624
1597
|
}
|
|
1625
1598
|
|
|
1626
|
-
|
|
1627
|
-
|
|
1599
|
+
countdown(count) {
|
|
1600
|
+
const time = this.timeMode(this.config.time_activate_select);
|
|
1601
|
+
let counter = this.config.time_activate * time / 1000;
|
|
1628
1602
|
let say = this.config.time_activate + ' ' + this.config.text_countdown;
|
|
1629
1603
|
if (count && !timer && !activated) {
|
|
1630
1604
|
if (is_alarm) {
|
|
@@ -1648,7 +1622,7 @@ class Alarm extends utils.Adapter {
|
|
|
1648
1622
|
timer = null;
|
|
1649
1623
|
this.setState('status.activation_countdown', counter, true);
|
|
1650
1624
|
this.setState('status.gets_activated', false, true);
|
|
1651
|
-
this.
|
|
1625
|
+
this.enableSystem();
|
|
1652
1626
|
}
|
|
1653
1627
|
}, 1000);
|
|
1654
1628
|
} else if (count && timer) {
|
|
@@ -1667,7 +1641,7 @@ class Alarm extends utils.Adapter {
|
|
|
1667
1641
|
}
|
|
1668
1642
|
}
|
|
1669
1643
|
|
|
1670
|
-
|
|
1644
|
+
bools(val) {
|
|
1671
1645
|
switch (val) {
|
|
1672
1646
|
case 'true':
|
|
1673
1647
|
return true;
|
|
@@ -1682,8 +1656,8 @@ class Alarm extends utils.Adapter {
|
|
|
1682
1656
|
}
|
|
1683
1657
|
}
|
|
1684
1658
|
|
|
1685
|
-
|
|
1686
|
-
const change =
|
|
1659
|
+
shortcuts_inside(id, val) {
|
|
1660
|
+
const change = this.is_changed(id, val);
|
|
1687
1661
|
shorts_in.forEach((ele) => {
|
|
1688
1662
|
if (ele.name_id == id) {
|
|
1689
1663
|
if (ele.value === val || this.bools(ele.value) == val) {
|
|
@@ -1698,7 +1672,7 @@ class Alarm extends utils.Adapter {
|
|
|
1698
1672
|
});
|
|
1699
1673
|
}
|
|
1700
1674
|
|
|
1701
|
-
|
|
1675
|
+
get_short_ids(ids) {
|
|
1702
1676
|
const idsArr = ids || [];
|
|
1703
1677
|
const temp_ids = [];
|
|
1704
1678
|
idsArr.forEach((ele) => {
|
|
@@ -1709,8 +1683,8 @@ class Alarm extends utils.Adapter {
|
|
|
1709
1683
|
return temp_ids;
|
|
1710
1684
|
}
|
|
1711
1685
|
|
|
1712
|
-
|
|
1713
|
-
const change =
|
|
1686
|
+
shortcuts(id, val) {
|
|
1687
|
+
const change = this.is_changed(id, val);
|
|
1714
1688
|
let setVal = val;
|
|
1715
1689
|
if (id === 'status.state_list') {
|
|
1716
1690
|
switch (val) {
|
|
@@ -1757,7 +1731,7 @@ class Alarm extends utils.Adapter {
|
|
|
1757
1731
|
}
|
|
1758
1732
|
|
|
1759
1733
|
|
|
1760
|
-
|
|
1734
|
+
is_changed(id, val) {
|
|
1761
1735
|
if (change_ids[id] === val) {
|
|
1762
1736
|
this.log.debug(`No changes inside shortcuts!`);
|
|
1763
1737
|
return false;
|
|
@@ -1768,29 +1742,23 @@ class Alarm extends utils.Adapter {
|
|
|
1768
1742
|
}
|
|
1769
1743
|
|
|
1770
1744
|
|
|
1771
|
-
|
|
1772
|
-
async timeStamp() {
|
|
1745
|
+
timeStamp() {
|
|
1773
1746
|
const date = new Date();
|
|
1774
1747
|
return ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2);
|
|
1775
1748
|
}
|
|
1776
1749
|
|
|
1750
|
+
|
|
1777
1751
|
async logging(content) {
|
|
1778
|
-
this.
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
log_list.unshift(this.timeStamp() + ': ' + content);
|
|
1789
|
-
//if (log_list.length > 25) log_list.splice(0,1);
|
|
1790
|
-
this.setState('info.log_today', log_list.join('<br>'), true);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
});
|
|
1752
|
+
const state = await this.getStateAsync('info.log_today').catch((e) => this.log.warn(e));
|
|
1753
|
+
if (state == null) {
|
|
1754
|
+
log_list = '';
|
|
1755
|
+
} else {
|
|
1756
|
+
log_list = state.val;
|
|
1757
|
+
log_list = log_list.split('<br>');
|
|
1758
|
+
log_list.unshift(this.timeStamp() + ': ' + content);
|
|
1759
|
+
//if (log_list.length > 25) log_list.splice(0,1);
|
|
1760
|
+
this.setState('info.log_today', log_list.join('<br>'), true);
|
|
1761
|
+
}
|
|
1794
1762
|
}
|
|
1795
1763
|
|
|
1796
1764
|
//##############################################################################
|
|
@@ -1798,7 +1766,7 @@ class Alarm extends utils.Adapter {
|
|
|
1798
1766
|
|
|
1799
1767
|
//######################### PRESENCE ###########################################
|
|
1800
1768
|
|
|
1801
|
-
|
|
1769
|
+
setAllPresenceTimer(callback) {
|
|
1802
1770
|
if (this.config.presence) {
|
|
1803
1771
|
this.getAstro();
|
|
1804
1772
|
presenceRun = true;
|
|
@@ -1837,7 +1805,7 @@ class Alarm extends utils.Adapter {
|
|
|
1837
1805
|
|
|
1838
1806
|
|
|
1839
1807
|
|
|
1840
|
-
|
|
1808
|
+
clearAllPresenceTimer() {
|
|
1841
1809
|
presenceRun = false;
|
|
1842
1810
|
clearTimeout(presenceDelay_timer);
|
|
1843
1811
|
clearInterval(presenceInterval);
|
|
@@ -1851,12 +1819,12 @@ class Alarm extends utils.Adapter {
|
|
|
1851
1819
|
}
|
|
1852
1820
|
|
|
1853
1821
|
|
|
1854
|
-
|
|
1822
|
+
checkPresence() {
|
|
1855
1823
|
if (!activated || inside) {
|
|
1856
1824
|
return;
|
|
1857
1825
|
}
|
|
1858
|
-
sunrise =
|
|
1859
|
-
sunset =
|
|
1826
|
+
sunrise = this.timeInRange(sunriseStr, '12:00');
|
|
1827
|
+
sunset = this.timeInRange(sunsetStr, '22:00');
|
|
1860
1828
|
for (const item in presenceTimers) {
|
|
1861
1829
|
// eslint-disable-next-line no-prototype-builtins
|
|
1862
1830
|
if (presenceTimers.hasOwnProperty(item)) {
|
|
@@ -1866,7 +1834,7 @@ class Alarm extends utils.Adapter {
|
|
|
1866
1834
|
this.log.warn(`Please check the times when configuring attendance: ${presenceTimers[item].name_id}`);
|
|
1867
1835
|
return;
|
|
1868
1836
|
}
|
|
1869
|
-
if (
|
|
1837
|
+
if (this.timeInRange(presenceTimers[item].presence_time_from, presenceTimers[item].presence_time_to) && !presenceTimers[item].wasOn) {
|
|
1870
1838
|
this.log.debug(`Delay for: ${presenceTimers[item].name_id} starts ${presenceTimers[item].presence_delay}ms, because time is in range.`);
|
|
1871
1839
|
presenceTimers[item].wasOn = true;
|
|
1872
1840
|
presenceTimers[item].presenceDelayTimer = setTimeout(() => {
|
|
@@ -1927,7 +1895,7 @@ class Alarm extends utils.Adapter {
|
|
|
1927
1895
|
break;
|
|
1928
1896
|
case 'light':
|
|
1929
1897
|
// eslint-disable-next-line no-case-declarations
|
|
1930
|
-
const lightVal =
|
|
1898
|
+
const lightVal = this.getForeignStateAsync(presenceTimers[item].presence_trigger_light).catch((e) => {
|
|
1931
1899
|
this.log.warn(`Check your light ID ${presenceTimers[item].name_id} in presence config! +++ ${e}`);
|
|
1932
1900
|
return;
|
|
1933
1901
|
});
|
|
@@ -1957,7 +1925,7 @@ class Alarm extends utils.Adapter {
|
|
|
1957
1925
|
}
|
|
1958
1926
|
}
|
|
1959
1927
|
|
|
1960
|
-
|
|
1928
|
+
getValType(val) {
|
|
1961
1929
|
switch (val) {
|
|
1962
1930
|
case 'true':
|
|
1963
1931
|
return true;
|
|
@@ -1980,7 +1948,7 @@ class Alarm extends utils.Adapter {
|
|
|
1980
1948
|
|
|
1981
1949
|
async getAstro() {
|
|
1982
1950
|
try {
|
|
1983
|
-
const obj = await this.getForeignObjectAsync('system.config', 'state');
|
|
1951
|
+
const obj = await this.getForeignObjectAsync('system.config', 'state').catch((e) => this.log.warn(e));
|
|
1984
1952
|
|
|
1985
1953
|
if (obj && obj.common && obj.common.longitude && obj.common.latitude) {
|
|
1986
1954
|
const longitude = obj.common.longitude;
|
|
@@ -2013,7 +1981,7 @@ class Alarm extends utils.Adapter {
|
|
|
2013
1981
|
}
|
|
2014
1982
|
}
|
|
2015
1983
|
|
|
2016
|
-
|
|
1984
|
+
getTimeLength(durance, shuffle) {
|
|
2017
1985
|
const low = 1;
|
|
2018
1986
|
const high = shuffle;
|
|
2019
1987
|
return durance * (Math.floor(Math.random() * (high - low + 1)) + low);
|
|
@@ -2023,24 +1991,25 @@ class Alarm extends utils.Adapter {
|
|
|
2023
1991
|
// ################### IS TIME IN RANGE ###############################
|
|
2024
1992
|
// Format 12:10:00
|
|
2025
1993
|
|
|
2026
|
-
|
|
1994
|
+
currentDate() {
|
|
2027
1995
|
const d = new Date();
|
|
2028
1996
|
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
2029
1997
|
}
|
|
2030
|
-
|
|
1998
|
+
addTime(strTime) {
|
|
2031
1999
|
const time = strTime.split(':');
|
|
2032
|
-
const d =
|
|
2000
|
+
const d = this.currentDate();
|
|
2033
2001
|
d.setHours(time[0]);
|
|
2034
2002
|
d.setMinutes(time[1]);
|
|
2035
2003
|
//d.setSeconds(time[2]);
|
|
2036
2004
|
return d;
|
|
2037
2005
|
}
|
|
2038
|
-
|
|
2006
|
+
|
|
2007
|
+
timeInRange(strLower, strUpper) {
|
|
2039
2008
|
const now = new Date();
|
|
2040
2009
|
strLower = strLower.toString();
|
|
2041
2010
|
strUpper = strUpper.toString();
|
|
2042
|
-
const lower =
|
|
2043
|
-
const upper =
|
|
2011
|
+
const lower = this.addTime(strLower);
|
|
2012
|
+
const upper = this.addTime(strUpper);
|
|
2044
2013
|
let inRange = false;
|
|
2045
2014
|
if (upper > lower) {
|
|
2046
2015
|
// opens and closes in same day
|
|
@@ -2058,13 +2027,13 @@ class Alarm extends utils.Adapter {
|
|
|
2058
2027
|
|
|
2059
2028
|
//################# SCHEDULES ####################################################
|
|
2060
2029
|
|
|
2061
|
-
|
|
2030
|
+
set_schedules() {
|
|
2062
2031
|
schedule_reset = schedule.scheduleJob({ hour: '00', minute: '00' }, () => {
|
|
2063
2032
|
this.setState('info.log_today', '', true);
|
|
2064
2033
|
if (opt_presence && activated && presenceRun) {
|
|
2065
2034
|
this.setAllPresenceTimer(() => {
|
|
2066
2035
|
this.log.debug(`Restart presence timers for a new day!`);
|
|
2067
|
-
presenceInterval = setInterval(this.checkPresence, 60000);
|
|
2036
|
+
presenceInterval = setInterval(() => { this.checkPresence(); }, 60000);
|
|
2068
2037
|
});
|
|
2069
2038
|
}
|
|
2070
2039
|
});
|