-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
4542 lines (4113 loc) · 247 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
const utils = require('@iobroker/adapter-core');
const { default: axios } = require('axios');
const schedule = require('cron').CronJob; // Cron Scheduler
const SunCalc = require('suncalc2');
const object = require('./lib/object_definition');
const device_Folder_Object = object['object_device_Folder_definitions'];
const main_Object = object['object_main_definitions'];
const command_Object = object['object_commands_definitions'];
const device_info_Object = object['object_device_info_definitions'];
const memory_Object = object['object_memory_definitions'];
const kiosk_Object = object['object_kiosk_definitions'];
const vis_View_object = object['object_vis_View_definitions'];
//Timeout init
let requestTimeout = null;
let automatic_briTimeout = null;
let viewTimer = null;
let ScreensaverReturn = null;
const foregroundAppTimer = [];
const logMessageTimer = [];
const kioskPinTimeout = [];
let BriRequestTimeout = null;
const captureTimeout = [];
//global variables
const ip = [];
const User = [];
const port = [];
const password = [];
const deviceInfo = [];
const tabletName = [];
let day_Time = null;
const deviceEnabled = [];
let fireTabletInterval = null;
let interval = null;
let imageTimeout = null;
let checkInterval = null;
let brightnessControlEnabled = null;
const telegramStatus = [];
const foregroundStart = [];
const messageSend = [];
const AlertMessageSend = [];
const logMessage = [];
const messageCharging = [];
const enabledBrightness = [];
const screensaverTimer = [];
const screenSaverTime = [];
const enableScreenSaverBrightness = [];
const viewNumber = [];
let timeMode = null;
const chargeDeviceValue = [];
let homeView = null;
const imageNr = [];
const loop = [];
const wishView = [];
const time = [];
const channelFolder = ['device_info', 'commands'];
const manualBrightnessMode = [];
const motionID = [];
const motionVal = [];
const commandsID = [];
const brightness = [];
const isInScreensaver = [];
const foreground = [];
const versionCheck = [];
const screensaverOnURL = [];
const screensaverOffURL = [];
const motionDetectorStatus = [];
const imageObj = {};
let shareObj = {};
const manuel_screenSaver = [false];
class FullyTabletControl extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: 'fully-tablet-control',
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('message', this.onMessage.bind(this));
this.on('unload', this.onUnload.bind(this));
}
/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
// Initialize your adapter here
// Reset the connection indicator during startup
this.setState('info.connection', false, true);
await this.initialization();
await this.stateRequest();
await this.astroTime();
await this.automatic_bri();
// @ts-ignore
// await this.checkView();
}
async initialization() {
try {
// let hostname = this.host
// console.log(hostname)
this.log.debug(`prepare adapter for initialization`);
this.log.debug(`Adapter config is read out`);
// Interval init
try {
// polling min 5 sec.
interval = this.config.interval * 1000;
if (interval < 10000) {
this.log.warn(
`the request interval time falls below the permitted limit of 10 sec ==> ${interval} ms => ${
interval / 1000
} sec`,
);
interval = 10000;
}
this.log.debug(`Adapter config for request interval readout --> ${interval} ms`);
// polling min 1 min.
checkInterval = this.config['checkInterval'] * 60000;
if (checkInterval < 60000) {
this.log.warn(
`the brightness interval time falls below the permitted limit of 1 min ==> ${checkInterval} ms => ${
checkInterval / 60000
} min`,
);
checkInterval = 60000;
}
this.log.debug(`Adapter config for brightness interval readout --> ${checkInterval} ms`);
// polling min 1 min.
fireTabletInterval = this.config['fireTablet'] * 60000;
if (fireTabletInterval < 60000) {
this.log.warn(
`the fire Tablet Interval time falls below the permitted limit of 1 min ==> ${fireTabletInterval} ms => ${
fireTabletInterval / 60000
} min`,
);
fireTabletInterval = 60000;
}
this.log.debug(`Adapter config for request interval readout --> ${interval} ms`);
// polling min 1 sec / max 5 sec.
imageTimeout = this.config['imageTimeout'] * 1000;
if (imageTimeout < 1000) {
this.log.warn(
`the image Timeout time falls below the permitted limit of 1 sec ==> ${imageTimeout} ms => ${
imageTimeout / 1000
} sec`,
);
imageTimeout = 1000;
}
if (imageTimeout > 5000) {
this.log.warn(
`the image timeout time is greater than 5 sec ==> ${imageTimeout} ms => ${
imageTimeout / 1000
} sec. is reset to 5 sec.`,
);
imageTimeout = 5000;
}
this.log.debug(`Adapter config for image timeout readout --> ${imageTimeout} ms`);
this.log.debug(`Interval initialization has been fully initialized`);
} catch (error) {
this.log.error(
`Interval initialization funktion has a problem: ${error.message}, stack: ${error.stack}`,
);
}
// Login init
try {
//read devices and created httpLink
const login = this.config.devices;
if ((!login && login['length'] !== 0) || (login !== [] && login['length'] !== 0)) {
for (const i in login) {
ip[i] = login[i].ip;
port[i] = login[i].port;
password[i] = encodeURIComponent(login[i].password);
deviceEnabled[i] = login[i].enabled;
tabletName[i] = login[i].name;
deviceInfo[i] = `http://${ip[i]}:${port[i]}/?cmd=deviceInfo&type=json&password=${password[i]}`;
this.log.debug(`the initialization Ip for ${tabletName[i]} was Successfully: ${ip[i]}`);
this.log.debug(`the initialization port for ${tabletName[i]} was Successfully: ${port[i]}`);
this.log.debug(
`the initialization password for ${tabletName[i]} was Successfully: ${password[i]}`,
);
this.log.debug(
`the initialization deviceInfoUrl for ${tabletName[i]} was Successfully: ${deviceInfo[i]}`,
);
this.log.debug(`Check whether the IP address is available for the ${tabletName[i]}`);
deviceEnabled[i] = ip[i] !== '' && deviceEnabled[i];
if (ip[i] === '') this.log.warn(`${tabletName[i]} has no ip address device is not queried`);
if (deviceEnabled[i])
this.log.debug(`the initialization for ${tabletName[i]} was Successfully`);
this.log.debug(`it is checked whether the name of the device is entered`);
// Prepare tablet name
if (tabletName[i] !== '') {
this.log.debug(`the name of the device is entered and is used --> ${tabletName[i]}`);
tabletName[i] = await this.replaceFunction(tabletName[i]);
} else if (deviceEnabled[i]) {
this.log.debug(
`The name of the device is not entered; the IP address is used for the name --> ${ip[i]}`,
);
tabletName[i] = await this.replaceFunction(ip[i]);
}
this.log.debug(`Tablet name is being prepared: ${tabletName[i]}`);
this.log.debug(`${tabletName[i]} login has been fully initialized`);
}
} else {
deviceEnabled[1] = false;
}
} catch (error) {
this.log.error(`login initialization funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// Telegram User init
try {
//read telegram user
this.log.debug(`read out the adapter config for Telegram users`);
const telegramOn = this.config['telegram_enabled'];
const telegramUser = this.config.telegram;
if (telegramOn) {
// @ts-ignore
if (
(!telegramUser && telegramUser.length !== 0) ||
(telegramUser !== [] && telegramUser.length !== 0)
) {
for (const u in telegramUser) {
User[u] = telegramUser[u].telegramUser;
}
this.log.debug(`Telegram users were read out ==> ${JSON.stringify(User)}`);
}
if (telegramOn) this.log.debug(`Telegram messages are switched on`);
if (!telegramOn) this.log.debug(`Telegram messages are switched off`);
}
this.log.debug(`TelegramUser initialization has been fully initialized`);
} catch (error) {
this.log.error(
`Telegram initialization funktion has a problem: ${error.message}, stack: ${error.stack}`,
);
}
//image_funktion init
try {
this.log.debug(`image_funktion is now set to default value 1 for all devices`);
for (const s in deviceEnabled) {
imageNr[s] = 1;
loop[s] = 1;
}
// set a CronJob that resets the variable with the number of stored images to the start value at midnight
const imageSafeCron = new schedule(`1 0 * * * `, async () => {
for (const s in deviceEnabled) {
imageNr[s] = 1;
}
this.log.debug(`imageSafeCron resets the number of stored images. ${new Date()}`);
});
imageSafeCron.start();
this.log.debug(`image_funktion initialization has been fully initialized`);
} catch (error) {
this.log.error(`image_funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
//SendStatus init
try {
this.log.debug(`send status is now set to false for all devices`);
for (const s in deviceEnabled) {
telegramStatus[s] = false;
this.log.debug(`telegramSendStatus set for ${tabletName[s]} to: ${telegramStatus[s]}`);
messageSend[s] = true;
this.log.debug(`message Send status set for ${tabletName[s]} to: ${messageSend[s]}`);
AlertMessageSend[s] = false;
this.log.debug(`AlertMessage Send status set for ${tabletName[s]} to: ${AlertMessageSend[s]}`);
logMessage[s] = false;
this.log.debug(`logMessage status set for ${tabletName[s]} to: ${logMessage[s]}`);
messageCharging[s] = false;
this.log.debug(`messageCharging status set for ${tabletName[s]} to: ${messageCharging[s]}`);
versionCheck[s] = false;
this.log.debug(`versionCheck status set for ${tabletName[s]} to: ${versionCheck[s]}`);
}
this.log.debug(`SendStatus initialization has been fully initialized`);
} catch (error) {
this.log.error(`SendStatus funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// foregroundStatus init
try {
this.log.debug(`foregroundStatus is now set to false for all devices`);
for (const f in deviceEnabled) {
if (deviceEnabled[f]) {
foregroundStart[f] = false;
this.log.debug(
`foregroundStart status set for ${tabletName[f]} to: ${JSON.stringify(telegramStatus)}`,
);
}
}
this.log.debug(`foregroundStatus initialization has been fully initialized`);
} catch (error) {
this.log.error(`foregroundStatus funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// BrightnessControl init
try {
this.log.debug(`Check whether the brightness control is activated`);
brightnessControlEnabled = JSON.parse(this.config['brightness_on']);
const brightnessObject = this.config.brightness;
if (brightnessControlEnabled) {
// @ts-ignore
if (
(!brightnessObject && brightnessObject.length !== 0) ||
(brightnessObject !== [] && brightnessObject.length !== 0)
) {
for (const b in deviceEnabled) {
this.log.debug(`Check whether the brightness control is activated for ${tabletName[b]}`);
if (brightnessObject[b] !== undefined) {
enabledBrightness[b] = brightnessObject[b]['enabledBrightness'];
} else {
this.log.warn(
`Attention the brightness control of ${tabletName[b]} is not activated correctly ==> undefined`,
);
enabledBrightness[b] = false;
this.log.warn(
`it is switched off temporarily, please deactivate it or activate it correctly`,
);
}
manualBrightnessMode[b] = await this.getStateAsync(
`device.${tabletName[b]}.brightness_control_mode`,
);
if (manualBrightnessMode[b] === null) {
manualBrightnessMode[b] = false;
} else {
manualBrightnessMode[b] = manualBrightnessMode[b].val;
}
}
} else {
for (const b in deviceEnabled) {
this.log.debug(
`The brightness settings for the devices are not defined. The manual mode is now switched on`,
);
enabledBrightness[b] = false;
// await this.setStateAsync(`device.${await this.replaceFunction(tabletName[b])}.brightness_control_mode`, true, true);
}
}
} else {
for (const b in deviceEnabled) {
this.log.debug(
`automatic brightness control for ${tabletName[b]} is switched off the manual control is now switched on`,
);
enabledBrightness[b] = false;
}
}
this.log.debug(`BrightnessControl initialization has been fully initialized`);
} catch (error) {
this.log.error(
`BrightnessControl init funktion has a problem: ${error.message}, stack: ${error.stack}`,
);
}
// motion Detector ID
try {
this.log.debug(`motion detector ID is read from the config and subscribed to`);
//read motion ID from Admin and subscribe
const motion = this.config.motion;
const motionSensor_enabled = JSON.parse(this.config.motionSensor_enabled);
if (motionSensor_enabled) {
// @ts-ignore
if ((!motion && motion.length !== 0) || (motion !== [] && motion.length !== 0)) {
for (const sensor in motion) {
this.log.debug(`Check if the sensor is activated`);
if (motion[sensor]['enabled']) {
this.log.debug(`Check whether the sensor has an ID entry`);
if (motion[sensor]['motionid'] !== '') {
this.log.debug(`read out all Motion ID's on the config`);
motionID[sensor] = motion[sensor]['motionid'];
motionVal[sensor] = false;
this.log.debug(`subscribe all Motion ID's`);
this.subscribeForeignStates(motion[sensor]['motionid']);
} else {
this.log.warn(`Attention there is no motion detector ID entered`);
}
} else {
this.log.debug(
`the motion detector with the id: ${motion[sensor]['motionid']} is deactivated !!`,
);
}
}
this.log.debug(`motion Detector ID initialization has been fully initialized`);
} else {
this.log.warn(
`Motion detector is not defined, please define at least one or switch off the motion detector control!`,
);
}
}
} catch (error) {
this.log.error(`motionDetectorID funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// Screensaver init
try {
// read screensaverTimer and screenSaverSelect
this.log.debug(`The screensaver config is now read out`);
const screenSaverON = JSON.parse(this.config['screenSaverON']);
const screenSaverObj = this.config['screenSaver'];
const screenSaverDeletion = JSON.parse(this.config['screenSaverDeletion']);
this.log.debug(`It is checked whether the screensaver control is switched on`);
if (screenSaverON) {
this.log.debug(`Screensaver control is switched on`);
// @ts-ignore
if (
(!screenSaverObj && screenSaverObj.length !== 0) ||
(screenSaverObj !== [] && screenSaverObj.length !== 0)
) {
for (const s in deviceEnabled) {
if (deviceEnabled[s]) {
if (screenSaverObj[s] !== undefined) {
manuel_screenSaver[s] = false;
this.log.debug(`Screensaver time is now read out`);
screenSaverTime[s] = JSON.parse(screenSaverObj[s]['minute']) * 60000;
this.log.debug(
`Screensaver time was successfully read out for ${tabletName[s]} ==> ${screenSaverTime[s]}`,
);
screensaverOnURL[
s
] = `http://${ip[s]}:${port[s]}/?cmd=startScreensaver&password=${password[s]}`;
screensaverOffURL[
s
] = `http://${ip[s]}:${port[s]}/?cmd=stopScreensaver&password=${password[s]}`;
// manuel_screenSaver[s] = false;
this.log.debug(`the screensaver mode is read from the config`);
const screensaverMode = JSON.parse(screenSaverObj[s]['screensaverMode']);
this.log.debug(`the screensaver mode was successfully read from the config`);
this.log.debug(
`Url for the screensaver is now requested for ${tabletName[s]} from the config`,
);
const screenSaverUrl = screenSaverObj[s].url;
this.log.debug(
`Url for ${tabletName[s]} was successfully obtained from the config`,
);
this.log.debug(
`It is now checked whether the screensaver brightness synchronization is switched on for the ${tabletName[s]}`,
);
enableScreenSaverBrightness[s] = screenSaverObj[s]['enabled'];
this.log.debug(
`For the ${tabletName[s]} the screensaver brightness synchronization switched on`,
);
this.log.debug(
`Check for ${tabletName[s]} whether the screensaver brightness synchronization has been correctly initialized`,
);
if (enableScreenSaverBrightness[s] === undefined) {
enableScreenSaverBrightness[s] = false;
this.log.error(
`[ATTENTION] the brightness synchronization for ${tabletName[s]} was not initialized, please check the box and save it.`,
);
} else {
enableScreenSaverBrightness[s] = screenSaverObj[s]['enabled'];
this.log.debug(
`the screensaver brightness synchronization for ${tabletName[s]} was correctly initialized`,
);
}
if (screensaverMode) {
if (screenSaverUrl === '') {
const playlistUrl = [];
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverPlaylist&value=&password=${password[s]}`,
);
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverWallpaperURL&value=fully://color black&password=${password[s]}`,
);
this.log.debug(
`The screensaver url for ${tabletName[s]} is not set the screensaver is set to a black image`,
);
for (const playlistUrlKey in playlistUrl) {
await axios
.get(playlistUrl[playlistUrlKey])
.then(async (result) => {
this.log.debug(
`${tabletName[s]} send status for playlistUrl = status Code: ${result.status} => status Message: ${result.statusText}`,
);
})
.catch(async (error) => {
this.log.error(
`${tabletName[s]} send status for playlistUrl has a problem => ${error.message}, stack: ${error.stack}`,
);
});
}
} else {
const screenUrl = [
{
type: 4,
url: screenSaverUrl,
loopItem: true,
loopFile: false,
fileOrder: 0,
nextItemOnTouch: false,
nextFileOnTouch: false,
nextItemTimer: 0,
nextFileTimer: 0,
},
];
const playlistUrl = `http://${ip[s]}:${
port[s]
}/?cmd=setStringSetting&key=screensaverPlaylist&value=${JSON.stringify(
screenUrl,
)}&password=${password[s]}`;
this.log.debug(
`YouTube Screensaver Url => ${screenSaverUrl} is set for ${tabletName[s]}`,
);
await axios
.get(playlistUrl)
.then(async (result) => {
this.log.debug(
`${tabletName[s]} send status for playlistUrl = status Code: ${result.status} => status Message: ${result.statusText}`,
);
})
.catch(async (error) => {
this.log.error(
`${tabletName[s]} send status for playlistUrl could not be sent => ${error.message}, stack: ${error.stack}`,
);
});
}
} else if (!screensaverMode) {
if (screenSaverUrl === '') {
const playlistUrl = [];
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverPlaylist&value=&password=${password[s]}`,
);
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverWallpaperURL&value=fully://color black&password=${password[s]}`,
);
this.log.debug(
`The screensaver url for ${tabletName[s]} is not set the screensaver is set to a black image`,
);
for (const playlistUrlKey in playlistUrl) {
await axios
.get(playlistUrl[playlistUrlKey])
.then(async (result) => {
this.log.debug(
`${tabletName[s]} send status for playlistUrl = status Code: ${result.status} => status Message: ${result.statusText}`,
);
})
.catch(async (error) => {
this.log.error(
`${tabletName[s]} send status for playlistUrl has a problem => ${error.message}, stack: ${error.stack}`,
);
});
}
} else {
const playlistUrl = [];
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverPlaylist&value=&password=${password[s]}`,
);
playlistUrl.push(
`http://${ip[s]}:${port[s]}/?cmd=setStringSetting&key=screensaverWallpaperURL&value=${screenSaverUrl}&password=${password[s]}`,
);
this.log.debug(
`${tabletName[s]} screensaver is switched on for wallpaper the playlist is now deleted and WallpaperUrl is set`,
);
this.log.debug(
`Wallpaper Screensaver Url => ${screenSaverUrl} is set for ${tabletName[s]}`,
);
for (const playlistUrlKey in playlistUrl) {
await axios
.get(playlistUrl[playlistUrlKey])
.then(async (result) => {
this.log.debug(
`${tabletName[s]} send status for playlistUrl = status Code: ${result.status} => status Message: ${result.statusText}`,
);
})
.catch(async (error) => {
this.log.error(
`${tabletName[s]} send status for playlistUrl has a problem => ${error.message}, stack: ${error.stack}`,
);
});
}
}
}
} else {
manuel_screenSaver[s] = true;
this.log.warn(`There is no screensaver config set for ${tabletName[s]}`);
this.log.warn(
`Please add a screensaver configuration or switch off the screensaver control.`,
);
}
} else {
manuel_screenSaver[s] = true;
}
}
}
} else {
if (screenSaverDeletion) {
for (const deviceEnabledkey in deviceEnabled) {
const playlistUrl = [];
if (deviceEnabled[deviceEnabledkey]) {
playlistUrl.push(
`http://${ip[deviceEnabledkey]}:${port[deviceEnabledkey]}/?cmd=setStringSetting&key=timeToScreensaverV2&value=0&password=${password[deviceEnabledkey]}`,
);
playlistUrl.push(
`http://${ip[deviceEnabledkey]}:${port[deviceEnabledkey]}/?cmd=setStringSetting&key=screensaverPlaylist&value=&password=${password[deviceEnabledkey]}`,
);
playlistUrl.push(
`http://${ip[deviceEnabledkey]}:${port[deviceEnabledkey]}/?cmd=setStringSetting&key=screensaverWallpaperURL&value=fully://color black&password=${password[deviceEnabledkey]}`,
);
}
for (const playlistUrlKey in playlistUrl) {
await axios
.get(playlistUrl[playlistUrlKey])
.then(async (result) => {
this.log.debug(
`${tabletName[deviceEnabledkey]} send status for playlistUrl = status Code: ${result.status} => status Message: ${result.statusText}`,
);
})
.catch(async (error) => {
this.log.error(
`${tabletName[deviceEnabledkey]} send status for playlistUrl has a problem => ${error.message}, stack: ${error.stack}`,
);
});
}
}
}
}
this.log.debug(`Screensaver initialization has been fully initialized`);
} catch (error) {
this.log.error(`Screensaver init funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// visView init
try {
this.log.debug(`Vis View control is now initialized`);
const viewName = [];
this.log.debug(`Check whether the visView control is switched on`);
const view_enabled = JSON.parse(this.config['viewChange_enabled']);
if (view_enabled) {
this.log.debug(`the visView control is switched on `);
this.log.debug(`visView config is now read out`);
const visView = this.config.visView;
this.log.debug(`the visView config was read out successfully`);
this.log.debug(
`now visProjekt / viewName / view Number the homeView / wishView and the time are read out from the config and chamfered together`,
);
for (const view in visView) {
const visProjekt = visView[view]['visProjekt'];
viewName[view] = visView[view]['viewName'];
if (visView[view]['viewNumber'] !== '') {
viewNumber[view] = JSON.parse(visView[view]['viewNumber']);
}
const tempTime = visView[view].time;
homeView = `${visProjekt}/${viewName[0]}`;
wishView[view] = `${visProjekt}/${viewName[view]}`;
if (tempTime === '0' || tempTime === '00') {
time[view] = 0;
} else {
time[view] = JSON.parse(visView[view].time);
}
}
this.log.debug(`the homeView was created successfully => ${homeView}`);
this.log.debug(`the wishView was created successfully => ${wishView}`);
this.log.debug(`the viewNumber was created successfully => ${viewNumber}`);
this.log.debug(`the viewTime was created successfully => ${time}`);
}
this.log.debug(`visView initialization has been fully initialized`);
} catch (error) {
this.log.error(`Screensaver init funktion has a problem: ${error.message}, stack: ${error.stack}`);
}
// AstroTime restart
try {
const astroTimeCron = new schedule(`0 2 * * * `, async () => {
await this.astroTime();
});
astroTimeCron.start();
this.log.debug(`AstroTime restart is set to 2 o'clock in the morning`);
} catch (error) {
this.log.error(
`AstroTime restart init funktion has a problem: ${error.message}, stack: ${error.stack}`,
);
}
} catch (error) {
this.log.error(`[initialization] funktion : ${error.message}, stack: ${error.stack}`);
}
}
async stateRequest() {
try {
if (requestTimeout) clearTimeout(requestTimeout);
if (deviceInfo.length !== 0) {
for (const i in deviceInfo) {
if (deviceEnabled[i]) {
this.log.debug(`device: ${tabletName[i]} enabled`);
const deviceID = await this.replaceFunction(tabletName[i]);
this.log.debug(`API request started ...`);
await axios
.get(deviceInfo[i])
.then(async (apiResult) => {
if (apiResult['status'] === 200) {
if (apiResult['data']['status'] !== 'Error') {
this.log.debug(
`API request ended successfully --> result from api Request: ${JSON.stringify(
apiResult['data'],
)}`,
);
this.log.debug(`State Create is now running ...`);
await this.create_state(i);
this.log.debug(`State Create was carried out`);
this.log.debug(`check if battery level is> = 0 if yes then restart app`);
this.log.debug(`States are now written`);
await this.state_write(apiResult, i, deviceID);
//set is Wallpanel Alive to true if the request was successful
this.setState(`device.${deviceID}.isFullyAlive`, { val: true, ack: true });
this.log.debug(`states were written`);
// clear log message timer
if (logMessageTimer[i]) clearTimeout(logMessageTimer[i]);
this.log.debug(`logMessageTimer for ${tabletName[i]} will be deleted`);
logMessage[i] = false;
this.log.debug(`logMessage set to ${logMessage[i]} for ${tabletName[i]}`);
// await this.charger();
} else {
this.log.error(`${apiResult['data']['statustext']}`);
}
}
})
.catch(async (error) => {
if (!logMessage[i]) {
logMessage[i] = true;
this.log.debug(`logMessage set to ${logMessage[i]} for ${tabletName[i]}`);
this.log.error(`[Request] ${tabletName[i]} Unable to contact: ${error} | ${error}`);
} else if (!logMessageTimer[i]) {
if (logMessageTimer[i]) clearTimeout(logMessageTimer[i]);
this.log.debug(`logMessageTimer for ${tabletName[i]} will be deleted`);
this.log.debug(
`set logMessageTimer for ${tabletName[i]} to ${3600000 / 60000} min`,
);
logMessageTimer[i] = setTimeout(async () => {
logMessage[i] = false;
this.log.debug(`logMessage set to ${logMessage[i]} for ${tabletName[i]}`);
}, 3600000);
}
this.setState(`device.${deviceID}.isFullyAlive`, { val: false, ack: true });
this.log.debug(`set isFullyAlive to false for ${tabletName[i]}`);
});
}
}
}
requestTimeout = setTimeout(async () => {
this.log.debug(`start devices to query for new values`);
await this.stateRequest();
}, interval);
} catch (error) {
this.log.error(`Request function has a problem : ${error.message}, stack: ${error.stack}`);
}
}
/**
* Check on number.
* @param {Object} apiResult
* @param {string|number} index
* @param {string} deviceID
*/
async state_write(apiResult, index, deviceID) {
try {
this.log.debug(`prepare state write`);
const objects = apiResult['data'];
this.log.debug(`[result]: ${JSON.stringify(objects)}`);
for (const obj in objects) {
switch (obj) {
//TODO: alle cases in {} setzen
case 'isInScreensaver':
isInScreensaver[index] = objects['isInScreensaver'];
this.setState(`device.${deviceID}.device_info.isInScreensaver`, {
val: isInScreensaver[index],
ack: true,
});
this.log.debug(`IP state for ${deviceID} : ${isInScreensaver[index]}`);
if (
!JSON.parse(this.config['motionSensor_enabled']) &&
!isInScreensaver[index] &&
!manuel_screenSaver[index]
) {
const screenSaverObj = this.config.screenSaver;
// @ts-ignore
if (
(!screenSaverObj && screenSaverObj.length !== 0) ||
(screenSaverObj !== [] && screenSaverObj.length !== 0)
) {
manuel_screenSaver[index] = true;
await this.screensaverManuel(index);
}
}
break;
case 'currentFragment': {
const currentFragment = objects['currentFragment'];
this.setState(`device.${deviceID}.device_info.currentFragment`, {
val: currentFragment,
ack: true,
});
this.log.debug(`currentFragment state for ${deviceID} : ${currentFragment}`);
break;
}
case 'topFragmentTag': {
// new form App Version 1.40.3
const topFragmentTag = objects['topFragmentTag'];
this.setState(`device.${deviceID}.device_info.currentFragment`, {
val: topFragmentTag,
ack: true,
});
this.log.debug(`currentFragment state for ${deviceID} : ${topFragmentTag}`);
break;
}
case 'deviceModel': {
const deviceModel = objects['deviceModel'];
this.setState(`device.${deviceID}.device_info.deviceModel`, { val: deviceModel, ack: true });
this.log.debug(`deviceModel state for ${deviceID} : ${deviceModel}`);
break;
}
case 'deviceName': {
const deviceName = objects['deviceName'];
this.setState(`device.${deviceID}.device_info.deviceName`, { val: deviceName, ack: true });
this.log.debug(`deviceName state for ${deviceID} : ${deviceName}`);
break;
}
case 'wifiSignalLevel': {
const wifiSignalLevel = objects['wifiSignalLevel'];
this.setState(`device.${deviceID}.device_info.wifiSignalLevel`, {
val: wifiSignalLevel,
ack: true,
});
this.log.debug(`wifiSignalLevel state for ${deviceID} : ${wifiSignalLevel}`);
break;
}
case 'kioskMode': {
const kioskMode = objects['kioskMode'];
this.setState(`device.${deviceID}.device_info.kioskMode`, { val: kioskMode, ack: true });
this.log.debug(`kioskMode state for ${deviceID} : ${kioskMode}`);
break;
}
case 'displayHeightPixels': {
const displayHeightPixels = objects['displayHeightPixels'];
this.setState(`device.${deviceID}.device_info.displayHeightPixels`, {
val: displayHeightPixels,
ack: true,
});
this.log.debug(`displayHeightPixels state for ${deviceID} : ${displayHeightPixels}`);
break;
}
case 'appVersionName': {
const appVersionName = objects['appVersionName'];
this.setState(`device.${deviceID}.device_info.appVersionName`, {
val: appVersionName,
ack: true,
});
this.log.debug(`appVersionName state for ${deviceID} : ${appVersionName}`);
break;
}
case 'maintenanceMode': {
const maintenanceMode = objects['maintenanceMode'];
this.setState(`device.${deviceID}.device_info.maintenanceMode`, {
val: maintenanceMode,
ack: true,
});
this.log.debug(`maintenanceMode state for ${deviceID} : ${maintenanceMode}`);
break;
}
case 'mac': {
const mac = objects.mac;
this.setState(`device.${deviceID}.device_info.mac`, { val: mac, ack: true });
this.log.debug(`mac state for ${deviceID} : ${mac}`);
break;
}
case 'Mac': {
// new form App Version 1.40.3
const Mac = objects[`Mac`];
this.setState(`device.${deviceID}.device_info.mac`, { val: Mac, ack: true });
this.log.debug(`mac state for ${deviceID} : ${Mac}`);
break;
}
case 'startUrl': {
const startUrl = objects['startUrl'];
this.setState(`device.${deviceID}.device_info.startUrl`, { val: startUrl, ack: true });
this.log.debug(`startUrl state for ${deviceID} : ${startUrl}`);
break;
}
case 'currentPage': {
const currentPage = objects['currentPage'];
this.setState(`device.${deviceID}.device_info.currentPage`, { val: currentPage, ack: true });
this.log.debug(`currentPage state for ${deviceID} : ${currentPage}`);
break;
}
case 'screenOrientation': {
const screenOrientation = objects['screenOrientation'];
this.setState(`device.${deviceID}.device_info.screenOrientation`, {
val: screenOrientation,
ack: true,
});
this.log.debug(`screenOrientation state for ${deviceID} : ${screenOrientation}`);
break;
}
case 'isInDaydream': {
const isInDaydream = objects['isInDaydream'];
this.setState(`device.${deviceID}.device_info.isInDaydream`, { val: isInDaydream, ack: true });
this.log.debug(`isInDaydream state for ${deviceID} : ${isInDaydream}`);
break;
}
case 'isLicensed': {