-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
6450 lines (6097 loc) · 285 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';
/*
* Created with @iobroker/create-adapter v2.1.0
*/
// 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 http = require('http');
const axios = require('axios').default;
const schedule = require('node-schedule');
const adapterName = require('./package.json').name.split('.').pop();
// const { info } = require('console');
// const { default: axios } = require('axios');
// const { join } = require('path');
// const { nextTick } = require('process');
// const { stringify } = require('querystring');
// const { networkInterfaces } = require('os');
// my own modules
const {
adapterChannels,
calculatedStates,
StatisticStates,
DeviceParameters,
initStates,
alarmPeriod,
shortPeriod,
longPeriode,
sensorPresence
} = require('./lib/device-parameters');
const {
channelsRootNameFS,
AdapterChannelsFS,
DeviceParametersFS
} = require('./lib/device-parametersFS');
/* cron definitions for the varius cron timers.
(cron timers are for statistik data collection) */
const cron_Year = '0 0 1 1 *';
const cron_Month = '0 0 1 * *';
const cron_Week = '0 0 * * 1';
const cron_Day = '0 0 * * *';
const corn_FloorSensor_short = '*/15 * * * * *'; // Every 15 Seconds
const corn_FloorSensor_long = '*/2 * * * *'; // Every 2 minutes
const FloorSenso1_LoopTimeout = 5;
const FloorSenso2_LoopTimeout = 5;
const FloorSenso3_LoopTimeout = 5;
const FloorSenso4_LoopTimeout = 5;
const Parameter_FACTORY_Mode = 'ADM/(2)f';
const Parameter_SERVICE_Mode = 'ADM/(1)';
const Parameter_Clear_SERVICE_FACTORY_Mode = 'ADM';
// Values for further calculations
let _WaterTemperature = 0;
let _WaterPressure = 0;
let _WaterConductivity = 0;
let _WaterConductivity_EC25 = 0;
//Reference to my own adapter
let myAdapter;
// Variable for Timer IDs
let alarm_Intervall_ID;
let short_Intervall_ID;
let long_Intervall_ID;
let very_long_Intervall_ID;
let delay_Timer_ID;
let delay_reconnection;
let timeout_axios_request;
let sensor_temperature_present = false;
let sensor_pressure_present = false;
let sensor_conductivity_present = false;
let valuesInfoMessages = true;
let moreMessages = false;
let hideTriggerMessages = false;
let apiResponseInfoMessages = false;
let allow_SERVICE_and_FACTORY_changes = false;
let interfaceBusy;
let interfaceBusyCounter = 0;
const interfaceBusyMaxBeforeReaset = 10;
let SystemLanguage;
let MainValveJammProtection_running = false;
const NetworkDevices = {
LeakageDevice_responding: false,
FS_1_responding: false,
FS_2_responding: false,
FS_3_responding: false,
FS_4_responding: false
};
class wamo extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: String(adapterName),
});
// Axios Clients
this.syrApiClient = null;
this.syrSaveFloor1APIClient = null;
this.syrSaveFloor2APIClient = null;
this.syrSaveFloor3APIClient = null;
this.syrSaveFloor4APIClient = null;
// test
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
// this.on('objectChange', this.onObjectChange.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() {
// avoide unused var
if(_WaterTemperature === null){_WaterTemperature = 0;}
if(_WaterPressure === null){_WaterPressure = 0;}
if(_WaterConductivity === null){_WaterConductivity = 0;}
if(_WaterConductivity_EC25 === null){_WaterConductivity_EC25 = 0;}
// The adapters config (in the instance object everything under the attribute "native") is accessible via
// this.config:
moreMessages = this.config.moremessages;
hideTriggerMessages = this.config.hidetriggerinfomessages;
apiResponseInfoMessages = this.config.apiresponsemessages;
valuesInfoMessages = this.config.valueinfomessages;
delay_reconnection = this.config.reconnectingdelaytime;
timeout_axios_request = this.config.requesttimeout;
allow_SERVICE_and_FACTORY_changes = this.config.allow_service_and_factory_changes;
this.log.debug('config Device IP: ' + String(this.config.device_ip));
this.log.debug('config Device Port: ' + String(this.config.device_port));
this.log.debug('More log messages: ' + String(this.config.moremessages));
this.log.debug('show API response messages: ' + String(this.config.apiresponsemessages));
this.log.debug('show value messages from device: ' + String(this.config.valueinfomessages));
this.log.debug('Reconnection time after lost connection to the device is ' + String(this.config.reconnectingdelaytime) + ' seconds');
this.log.debug('Timeout for axios requests is ' + String(this.config.requesttimeout) + ' seconds');
this.log.debug('Main valve jam Protection: ' + String(this.config.regularmainvalvemovement));
this.log.debug('Cron settings main valve jam protection ' + String(this.config.regularemovementcron));
//=================================================================================================
// getting system language
//=================================================================================================
try {
const systemSettings = await this.getForeignObjectAsync('system.config');
if (systemSettings != null) {
SystemLanguage = String(systemSettings.common.language);
this.log.debug('System language is ' + String(systemSettings.common.language));
}
else {
// we set language to default english
SystemLanguage = String('en');
this.log.error('systemSettings objekt is null');
}
} catch (err) {
// we set language to default; english
SystemLanguage = String('en');
this.log.error('ERROR getting system config: ' + err);
}
//=================================================================================================
//=== Create the "Device" object and all channel objects ===
//=================================================================================================
try {
if (this.config.device_ip != '0.0.0.0' && this.config.device_ip != ''){
await this.initDevicesAndChanels();
}
else{
this.log.warn('No "Leakage Protection Device" configured!');
}
} catch (err) {
this.log.error('Error initStatesAndChanels: ' + err);
}
//=================================================================================================
//=== Create the "Floorsensor.X" object and all channel objects ===
//=================================================================================================
try {
if (this.config.safefloor_1_ip != '0.0.0.0' && this.config.safefloor_1_ip != '') {
await this.initFloorsensorAndChanels(1);
}
if (this.config.safefloor_2_ip != '0.0.0.0' && this.config.safefloor_2_ip != '') {
await this.initFloorsensorAndChanels(2);
}
if (this.config.safefloor_3_ip != '0.0.0.0' && this.config.safefloor_3_ip != '') {
await this.initFloorsensorAndChanels(3);
}
if (this.config.safefloor_4_ip != '0.0.0.0' && this.config.safefloor_4_ip != '') {
await this.initFloorsensorAndChanels(4);
}
} catch (err) {
this.log.error('Error initFloorsensorAndChanels: ' + err);
}
//=================================================================================================
//=== Create All state Objects in order to avoid later use of "setObjectNotExistsAsync" ===
//=================================================================================================
try {
if (this.config.device_ip != '0.0.0.0' && this.config.device_ip != ''){
await this.createAlloObjects();
}
} catch (err) {
this.log.error('Error createAlloObjects: ' + err);
}
//=================================================================================================================
//=== Create All state Objects for Floor Sensors in order to avoid later use of "setObjectNotExistsAsync" ===
//=================================================================================================================
try {
if (this.config.safefloor_1_ip != '0.0.0.0' && this.config.safefloor_1_ip != '') {
await this.createAlloFloorsensorObjects(1);
}
if (this.config.safefloor_2_ip != '0.0.0.0' && this.config.safefloor_2_ip != '') {
await this.createAlloFloorsensorObjects(2);
}
if (this.config.safefloor_3_ip != '0.0.0.0' && this.config.safefloor_3_ip != '') {
await this.createAlloFloorsensorObjects(3);
}
if (this.config.safefloor_4_ip != '0.0.0.0' && this.config.safefloor_4_ip != '') {
await this.createAlloFloorsensorObjects(4);
}
} catch (err) {
this.log.error('Error createAlloFloorsensorObjects: ' + err);
}
//=================================================================================================
//=== Initialise additional runtime states ===
//=================================================================================================
if (this.config.device_ip != '0.0.0.0' && this.config.device_ip != '') {
// Jam protection running Flag
this.setStateAsync(DeviceParameters.JPR.statePath + '.' + DeviceParameters.JPR.id, { val: false, ack: true });
// Jam protection activated
this.setStateAsync(DeviceParameters.JPE.statePath + '.' + DeviceParameters.JPE.id, { val: this.config.regularmainvalvemovement, ack: true });
// Jam protection Cron Timing
this.setStateAsync(DeviceParameters.JPT.statePath + '.' + DeviceParameters.JPT.id, { val: this.config.regularemovementcron, ack: true });
}
//=================================================================================================
// Initialize Axios Client (this client will be used to communicate with the device) ===
//=================================================================================================
if (this.config.device_ip != '0.0.0.0' && this.config.device_ip != '') {
this.syrApiClient = axios.create({
baseURL: `http://${this.config.device_ip}:${this.config.device_port}/safe-tec/`,
timeout: timeout_axios_request * 1000,
responseType: 'json',
responseEncoding: 'utf8',
httpAgent: new http.Agent({
keepAlive: true
})
});
}
//=====================================================================================================================
// Initialize Axios Client for SafeFloor Units (this client will be used to communicate with the SafeFloor units) ===
//=====================================================================================================================
if (this.config.safefloor_1_ip != '0.0.0.0' && this.config.safefloor_1_ip != '') {
this.log.info('SafeFloor Connect Unit 1 IP-Address: ' + String(this.config.safefloor_1_ip) + ':' + String(this.config.device_port));
this.syrSaveFloor1APIClient = axios.create({
baseURL: `http://${this.config.safefloor_1_ip}:${this.config.device_port}/floorsensor/`,
timeout: FloorSenso1_LoopTimeout * 1000,
responseType: 'json',
responseEncoding: 'utf8',
httpAgent: new http.Agent({
keepAlive: true
})
});
this.log.debug('SafeFloor Connect Unit 1 baseURL: ' + String(this.syrSaveFloor1APIClient.defaults.baseURL));
}
if (this.config.safefloor_2_ip != '0.0.0.0' && this.config.safefloor_2_ip != '') {
this.log.info('SafeFloor Connect Unit 2 IP-Address: ' + String(this.config.safefloor_2_ip) + ':' + String(this.config.device_port));
this.syrSaveFloor2APIClient = axios.create({
baseURL: `http://${this.config.safefloor_2_ip}:${this.config.device_port}/floorsensor/`,
timeout: FloorSenso2_LoopTimeout * 1000,
responseType: 'json',
responseEncoding: 'utf8',
httpAgent: new http.Agent({
keepAlive: true
})
});
this.log.debug('SafeFloor Connect Unit 2 baseURL: ' + String(this.syrSaveFloor2APIClient.defaults.baseURL));
}
if (this.config.safefloor_3_ip != '0.0.0.0' && this.config.safefloor_3_ip != '') {
this.log.info('SafeFloor Connect Unit 3 IP-Address: ' + String(this.config.safefloor_3_ip) + ':' + String(this.config.device_port));
this.syrSaveFloor3APIClient = axios.create({
baseURL: `http://${this.config.safefloor_3_ip}:${this.config.device_port}/floorsensor/`,
timeout: FloorSenso3_LoopTimeout * 1000,
responseType: 'json',
responseEncoding: 'utf8',
httpAgent: new http.Agent({
keepAlive: true
})
});
this.log.debug('SafeFloor Connect Unit 3 baseURL: ' + String(this.syrSaveFloor3APIClient.defaults.baseURL));
}
if (this.config.safefloor_4_ip != '0.0.0.0' && this.config.safefloor_4_ip != '') {
this.log.info('SafeFloor Connect Unit 4 IP-Address: ' + String(this.config.safefloor_4_ip) + ':' + String(this.config.device_port));
this.syrSaveFloor4APIClient = axios.create({
baseURL: `http://${this.config.safefloor_4_ip}:${this.config.device_port}/floorsensor/`,
timeout: FloorSenso4_LoopTimeout * 1000,
responseType: 'json',
responseEncoding: 'utf8',
httpAgent: new http.Agent({
keepAlive: true
})
});
this.log.debug('SafeFloor Connect Unit 4 baseURL: ' + String(this.syrSaveFloor4APIClient.defaults.baseURL));
}
//=================================================================================================
// Test if device is responding ===
//=================================================================================================
if (this.syrApiClient != null) {
try {
while (!await this.devicePing()) {
this.log.warn('waiting till device becomes available again ...');
}
this.log.info('Leakage protection device is present at: ' + String(this.config.device_ip) + ':' + String(this.config.device_port));
}
catch (err) {
this.log.error(err);
return;
}
}
//=================================================================================================
//=== Getting sensor presence ===
//=================================================================================================
let gotSensorPreasence = false;
if (this.syrApiClient != null) {
while (!gotSensorPreasence) {
try {
this.log.info('checking sensor presence ...');
this.log.debug('async onReady() at "while (!gotSensorPreasence)" -> Getting sensor presence');
//==================================================================
//= Getting data for 'DeviceParameters' in [const sensorPresence] =
//==================================================================
if (moreMessages) {this.log.info('reading device parameters defined in object [sensorPresence]');}
await this.getData(sensorPresence);
gotSensorPreasence = true;
await this.delay(3000); // we need to wait some seconds to make sure sensor objects are created
// now we can create the sensor specific objects
await this.createSensorSpecificObjects();
}
catch (err) {
this.log.error('this.getData(sensorPresence) ERROR: ' + err);
}
}
}
//=================================================================================================
//=== Getting device data ===
//=================================================================================================
let gotDeviceData = false;
if (this.syrApiClient != null) {
while (!gotDeviceData) {
try {
this.log.info('initial reading device data ...');
this.log.debug('async onReady() at "while (!gotDeviceData)" -> Getting initial data');
//==================================================================
//= Getting all datas for 'DeviceParameters' in [const initStates] =
//==================================================================
if (moreMessages) {this.log.info('reading device parameters defined in object [initStates]');}
await this.getData(initStates);
gotDeviceData = true;
}
catch (err) {
this.log.error('this.getData(initStates) ERROR: ' + err);
}
}
}
//=================================================================
// update state: German hardnes calculation factor from settings
//=================================================================
if (this.syrApiClient != null) {
await this.updateHardnesFactorObject();
}
//=================================================================================================
//=== Getting device Profiles data ===
//=================================================================================================
let gotDeviceProfileData = false;
if (this.syrApiClient != null) {
while (!gotDeviceProfileData) {
try {
this.log.info('initial reading profile data ...');
// Device Profiles Initialisation
this.log.debug('async onReady() - getDeviceProfilesData -> Getting Profiles data from device at ' + this.config.device_ip + ':' + this.config.device_port);
//===============================================
//= Getting all Profile 'DeviceParameters' data =
//===============================================
const responseInitProfiles = await this.getDeviceProfilesData();
this.log.debug(`[async onReady() - getDeviceProfilesData -> getDeviceProfilesData] Response: ${responseInitProfiles}`);
gotDeviceProfileData = true;
}
catch (err) {
this.log.error('getDeviceProfilesData() ERROR: ' + err);
}
}
}
//=========================
//=== Timer starten ===
//=========================
try {
await this.timerStarts();
} catch (err) {
this.log.error('Timer start error ... exit ' + err);
return;
}
/*
For every state in the system there has to be also an object of type state
Here a simple template for a boolean variable named "testVariable"
Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables
*//*
await this.setObjectNotExistsAsync('testVariable', {
type: 'state',
common: {
name: 'testVariable',
type: 'boolean',
role: 'indicator',
read: true,
write: true,
},
native: {},
});
*/
//==========================================
//=== Subscribe to user changable states ===
//==========================================
if (this.syrApiClient != null) {
this.subscribeStates(DeviceParameters.CLP.statePath + '.' + DeviceParameters.CLP.id); // [CLP] Cluster Profile
this.subscribeStates(DeviceParameters.CNF.statePath + '.' + DeviceParameters.CNF.id); // [CNF] Conductivity factor
this.subscribeStates(DeviceParameters.CNL.statePath + '.' + DeviceParameters.CNL.id); // [CNL] Conductivity limit
this.subscribeStates(DeviceParameters.DTT.statePath + '.' + DeviceParameters.DTT.id); // [DTT] Micro-Leakage-Test start time
this.subscribeStates(DeviceParameters.HTD.statePath + '.' + DeviceParameters.HTD.id); // [HTD] Disable HTTPS connection (only MQTT)
this.subscribeStates(DeviceParameters.MQT.statePath + '.' + DeviceParameters.MQT.id); // [MQT] MQTT connection type
this.subscribeStates(DeviceParameters.T2.statePath + '.' + DeviceParameters.T2.id); // [T2] Max flow leakage time
this.subscribeStates(DeviceParameters.UNI.statePath + '.' + DeviceParameters.UNI.id); // [UNI] units
this.subscribeStates(DeviceParameters.AB.statePath + '.' + DeviceParameters.AB.id); // [AB] Shutoff valve
this.subscribeStates(DeviceParameters.BPB.statePath + '.' + DeviceParameters.BPB.id); // [BPB] Enable profile changes by button (0 = blocked, 1 = possible)
this.subscribeStates(DeviceParameters.BSA.statePath + '.' + DeviceParameters.BSA.id); // [BSE] Floor sensor
this.subscribeStates(DeviceParameters.BUZ.statePath + '.' + DeviceParameters.BUZ.id); // [BUZ] Buzzer on alarm
this.subscribeStates(DeviceParameters.DMA.statePath + '.' + DeviceParameters.DMA.id); // [BUZ] Buzzer on alarm
this.subscribeStates(DeviceParameters.DRP.statePath + '.' + DeviceParameters.DRP.id); // [DRP] Micro-Leakage-Test period
this.subscribeStates(DeviceParameters.IDS.statePath + '.' + DeviceParameters.IDS.id); // [IDS] Daylight saving time
this.subscribeStates(DeviceParameters.LNG.statePath + '.' + DeviceParameters.LNG.id); // [LNG] Language
this.subscribeStates(DeviceParameters.TMP.statePath + '.' + DeviceParameters.TMP.id); // [TMP] temporary protection deactivation
this.subscribeStates(DeviceParameters.LWT.statePath + '.' + DeviceParameters.LWT.id); // [LWT] Leakage notification (warning) threshold
this.subscribeStates(DeviceParameters.PRF.statePath + '.' + DeviceParameters.PRF.id); // [PRF] Selected profile
this.subscribeStates(DeviceParameters.SMF.statePath + '.' + DeviceParameters.SMF.id); // [SMF] Self learning minimum flow
this.subscribeStates(DeviceParameters.FSA.statePath + '.' + DeviceParameters.FSA.id); // [FSA] Add (Pair) Floorsensor
this.subscribeStates(DeviceParameters.WFC.statePath + '.' + DeviceParameters.WFC.id); // [WFC] WiFi connect (SSID)
this.subscribeStates(DeviceParameters.WFK.statePath + '.' + DeviceParameters.WFK.id); // [WFK] WiFi key
this.subscribeStates(adapterChannels.DevicePofiles.path + '.*'); // ALL profile states
// only adopt SERVICE and FACTORY events if enabled in adapter Options
if(allow_SERVICE_and_FACTORY_changes){
this.log.info('SERVICE and FACTORY changes are enabled!');
this.subscribeStates(DeviceParameters.MSC.statePath + '.' + DeviceParameters.MSC.id); // [MSC] MQTT reconnect time
this.subscribeStates(DeviceParameters.MRT.statePath + '.' + DeviceParameters.MRT.id); // [MRT] Maintenance (Husty) server connection
this.subscribeStates(DeviceParameters.DTC.statePath + '.' + DeviceParameters.DTC.id); // [DTC] MLT verification cycles
this.subscribeStates(DeviceParameters.DST.statePath + '.' + DeviceParameters.DST.id); // [DST] MLT test time NOPULS
this.subscribeStates(DeviceParameters.DPL.statePath + '.' + DeviceParameters.DPL.id); // [DPL] MLT pulses
this.subscribeStates(DeviceParameters.DOM.statePath + '.' + DeviceParameters.DOM.id); // [DOM] MLT test time open
this.subscribeStates(DeviceParameters.DKI.statePath + '.' + DeviceParameters.DKI.id); // [DKI] Safe-Tec device kind ID
this.subscribeStates(DeviceParameters.WNS.statePath + '.' + DeviceParameters.WNS.id); // [WNS] WiFi AP disabled
this.subscribeStates(DeviceParameters.TYP.statePath + '.' + DeviceParameters.TYP.id); // [TYP] Safe-Tec type
this.subscribeStates(DeviceParameters.TTM.statePath + '.' + DeviceParameters.TTM.id); // [TTM] Turbine no pulse max. time
this.subscribeStates(DeviceParameters.BFT.statePath + '.' + DeviceParameters.BFT.id); // [BFT] Button filter threshold
this.subscribeStates(DeviceParameters.BPT.statePath + '.' + DeviceParameters.BPT.id); // [BPT] Button proximity threshold
this.subscribeStates(DeviceParameters.DBD.statePath + '.' + DeviceParameters.DBD.id); // [DBD] MLT pressure drop
this.subscribeStates(DeviceParameters.DBT.statePath + '.' + DeviceParameters.DBT.id); // [DBT] MLT pressure drop time
this.subscribeStates(DeviceParameters.DCM.statePath + '.' + DeviceParameters.DCM.id); // [DCM] MLT test time close
this.subscribeStates(DeviceParameters.RST.statePath + '.' + DeviceParameters.RST.id); // [RST] System Restart
this.subscribeStates(DeviceParameters.DEX.statePath + '.' + DeviceParameters.DEX.id); // [DEX] Micro-Leakage-Test start
this.subscribeStates(DeviceParameters.SRO.statePath + '.' + DeviceParameters.SRO.id); // [SRO] Screen Rotation
this.subscribeStates(DeviceParameters.CSD.statePath + '.' + DeviceParameters.CSD.id); // [CSD] Deactivate conductivity sensor
this.subscribeStates(DeviceParameters.TSD.statePath + '.' + DeviceParameters.TSD.id); // [TSD] Deactivate temperature sensor
this.subscribeStates(DeviceParameters.PSD.statePath + '.' + DeviceParameters.PSD.id); // [PSD] Deactivate pressure sensor
this.subscribeStates(DeviceParameters.APT.statePath + '.' + DeviceParameters.APT.id); // [APT] WiFi AP timeout
this.subscribeStates(DeviceParameters.ALD.statePath + '.' + DeviceParameters.ALD.id); // [ALD] Alarm duration (signaling time)
this.subscribeStates(DeviceParameters.SLO.statePath + '.' + DeviceParameters.SLO.id); // [SLO] Self learning offset
this.subscribeStates(DeviceParameters.SLP.statePath + '.' + DeviceParameters.SLP.id); // [SLP] Self learning phase
this.subscribeStates(DeviceParameters.SOF.statePath + '.' + DeviceParameters.SOF.id); // [SOF] Self learning offset flow
this.subscribeStates(DeviceParameters.UPG.statePath + '.' + DeviceParameters.UPG.id); // [UPG] Firmware upgrade
this.subscribeStates(DeviceParameters.P71.statePath + '.' + DeviceParameters.P71.id); // [71] LS deactivated
this.subscribeStates(DeviceParameters.TMZ.statePath + '.' + DeviceParameters.TMZ.id); // [TMZ] Time zone
this.subscribeStates(DeviceParameters.CLRALA.statePath + '.' + DeviceParameters.CLRALA.id); // [CLRALA] Clear current alarm
}
}
if(this.syrSaveFloor1APIClient != null)
{
this.subscribeStates(DeviceParametersFS.SLP.statePath.replace('.X.', '.1.') + '.' + DeviceParametersFS.SLP.id); // Floor Sensor 1 [SLP] Send device to sleep
this.subscribeStates(DeviceParametersFS.ADM2f.statePath.replace('.X.', '.1.') + '.' + DeviceParametersFS.ADM2f.id); // Floor Sensor 1 [ADM(2)f] Set device ADMIN mode
}
if(this.syrSaveFloor2APIClient != null)
{
this.subscribeStates(DeviceParametersFS.SLP.statePath.replace('.X.', '.2.') + '.' + DeviceParametersFS.SLP.id); // Floor Sensor 2 [SLP] Send device to sleep
this.subscribeStates(DeviceParametersFS.ADM2f.statePath.replace('.X.', '.2.') + '.' + DeviceParametersFS.ADM2f.id); // Floor Sensor 2 [ADM(2)f] Set device ADMIN mode
}
if(this.syrSaveFloor3APIClient != null)
{
this.subscribeStates(DeviceParametersFS.SLP.statePath.replace('.X.', '.3.') + '.' + DeviceParametersFS.SLP.id); // Floor Sensor 3 [SLP] Send device to sleep
this.subscribeStates(DeviceParametersFS.ADM2f.statePath.replace('.X.', '.3.') + '.' + DeviceParametersFS.ADM2f.id); // Floor Sensor 3 [ADM(2)f] Set device ADMIN mode
}
if(this.syrSaveFloor4APIClient != null)
{
this.subscribeStates(DeviceParametersFS.SLP.statePath.replace('.X.', '.4.') + '.' + DeviceParametersFS.SLP.id); // Floor Sensor 4 [SLP] Send device to sleep
this.subscribeStates(DeviceParametersFS.ADM2f.statePath.replace('.X.', '.4.') + '.' + DeviceParametersFS.ADM2f.id); // Floor Sensor 4 [ADM(2)f] Set device ADMIN mode
}
// reference to Adapter
myAdapter = this;
this.log.info('wamo adapter is running');
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
*/
onUnload(callback) {
this.log.debug('[onUnload(callback)] was hit');
try {
schedule.gracefulShutdown();
} catch (err) {
this.log.error('Error disabeling cron jobs' + err);
}
try {
// clear all intervals
if(alarm_Intervall_ID != null){try { clearInterval(alarm_Intervall_ID); } catch (err) { this.log.error('ERRRO clerring [Alarm Timer] interval ' + err);}}
if(short_Intervall_ID != null){try { clearInterval(short_Intervall_ID); } catch (err) { this.log.error('ERRRO clerring [Short Timer] interval ' + err);}}
if(long_Intervall_ID != null){try { clearInterval(long_Intervall_ID); } catch (err) { this.log.error('ERRRO clerring [Long Timer] interval ' + err);}}
if(very_long_Intervall_ID != null){try { clearInterval(very_long_Intervall_ID); } catch (err) { this.log.error('ERRRO clerring [Very Long Timer] interval ' + err);}}
if(delay_Timer_ID != null){try { clearTimeout(delay_Timer_ID); } catch (err) { this.log.error('ERRRO clerring [Delay Timeout] interval ' + err);}}
callback();
} catch (e) {
this.log.error(e);
callback();
}
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
async onStateChange(id, state) {
try {
if (state) {
this.log.debug('async onStateChange(id, state) -> if (state) hit -> id: ' + String(id) + ' state.val: ' + String(state.val) + ' state.ack: ' + String(state.ack));
const statePrefix = this.name + '.' + String(this.instance) + '.';
// The state was changed
//============================================================================
// SRO Screen Rotation
//============================================================================
if ((id == statePrefix + DeviceParameters.SRO.statePath + '.' + DeviceParameters.SRO.id) && state.ack == false) {
switch (state.val) {
case 0:
case 90:
case 180:
case 270:
try {
await this.set_DevieParameter(DeviceParameters.SRO, String(state.val));
this.log.info('User changed [SRO] Screen rotation to ' + String(state.val) + '°');
}
catch (err) {
this.log.warn('onStateChange(id, state) -> await this.set_DevieParameter(DeviceParameters.SRO ... ERROR: ' + err);
}
break;
default:
this.log.error('Screen rotation value of ' + String(state.val) + '° is not a valid angle!');
break;
}
}
//============================================================================
// ALD Alarm duration (signaling time)
//============================================================================
else if ((id == statePrefix + DeviceParameters.ALD.statePath + '.' + DeviceParameters.ALD.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.ALD.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.ALD.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.ALD, state.val);
this.log.info('User changed parameter ' + DeviceParameters.ALD.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.ALD.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [ALD]: ' + err.message);
}
}
}
//============================================================================
// BFT Button filter threshold
//============================================================================
else if ((id == statePrefix + DeviceParameters.BFT.statePath + '.' + DeviceParameters.BFT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.BFT.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.BFT.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.BFT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.BFT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.BFT.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [BFT]: ' + err.message);
}
}
}
//============================================================================
// BPT Button proximity threshold
//============================================================================
else if ((id == statePrefix + DeviceParameters.BPT.statePath + '.' + DeviceParameters.BPT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.BPT.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.BPT.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.BPT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.BPT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.BPT.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [BPT]: ' + err.message);
}
}
}
//============================================================================
// CLP Cluster profile
//============================================================================
else if ((id == statePrefix + DeviceParameters.CLP.statePath + '.' + DeviceParameters.CLP.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.CLP.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.CLP.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.CLP, state.val);
this.log.info('User changed parameter ' + DeviceParameters.CLP.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.CLP.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [CLP]: ' + err.message);
}
}
}
//============================================================================
// CNF Conductivity factor
//============================================================================
else if ((id == statePrefix + DeviceParameters.CNF.statePath + '.' + DeviceParameters.CNF.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.CNF.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.CNF.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.CNF, state.val);
this.log.info('User changed parameter ' + DeviceParameters.CNF.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.CNF.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [CNF]: ' + err.message);
}
}
}
//============================================================================
// CNL Conductivity limit
//============================================================================
else if ((id == statePrefix + DeviceParameters.CNL.statePath + '.' + DeviceParameters.CNL.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.CNL.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.CNL.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.CNL, state.val);
this.log.info('User changed parameter ' + DeviceParameters.CNL.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.CNL.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [CNL]: ' + err.message);
}
}
}
//============================================================================
// DBD MLT pressure drop
//============================================================================
else if ((id == statePrefix + DeviceParameters.DBD.statePath + '.' + DeviceParameters.DBD.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DBD.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DBD.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DBD, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DBD.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DBD.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DBD]: ' + err.message);
}
}
}
//============================================================================
// DBT MLT pressure drop time
//============================================================================
else if ((id == statePrefix + DeviceParameters.DBT.statePath + '.' + DeviceParameters.DBT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DBT.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DBT.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DBT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DBT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DBT.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DBT]: ' + err.message);
}
}
}
//============================================================================
// DCM MLT test time close
//============================================================================
else if ((id == statePrefix + DeviceParameters.DCM.statePath + '.' + DeviceParameters.DCM.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DCM.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DCM.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DCM, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DCM.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DCM.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DCM]: ' + err.message);
}
}
}
//============================================================================
// TTM Turbine no pulse max. time
//============================================================================
else if ((id == statePrefix + DeviceParameters.TTM.statePath + '.' + DeviceParameters.TTM.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.TTM.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.TTM.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.TTM, state.val);
this.log.info('User changed parameter ' + DeviceParameters.TTM.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.TTM.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [TTM]: ' + err.message);
}
}
}
//============================================================================
// TMZ Time zone
//============================================================================
else if ((id == statePrefix + DeviceParameters.TMZ.statePath + '.' + DeviceParameters.TMZ.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.TMZ.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.TMZ.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.TMZ, state.val);
this.log.info('User changed parameter ' + DeviceParameters.TMZ.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.TMZ.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [TMZ]: ' + err.message);
}
}
}
//============================================================================
// WFC WiFi connect (SSID)
//============================================================================
else if ((id == statePrefix + DeviceParameters.WFC.statePath + '.' + DeviceParameters.WFC.id) && (state.ack == false)) {
if (state.val != null && String(state.val).length > 0 && String(state.val).length <= 32) {
try {
await this.set_DevieParameter(DeviceParameters.WFC, state.val);
this.log.info('User changed parameter ' + DeviceParameters.WFC.id + ' to ' + String(state.val));
} catch (err) {
this.log.error('ERROR setting [WFC]: ' + err.message);
}
}
else { this.log.error(DeviceParameters.WFC.id + ' new value [' + String(state.val) + '] is out of range! New WiFi name is empty or to longe. Max SSID length is 32 characters!'); }
}
//============================================================================
// WFK WiFi key
//============================================================================
else if ((id == statePrefix + DeviceParameters.WFK.statePath + '.' + DeviceParameters.WFK.id) && (state.ack == false)) {
if (state.val != null && String(state.val).length > 0 && String(state.val).length <= 32) {
try {
await this.set_DevieParameter(DeviceParameters.WFK, state.val);
this.log.info('User changed parameter ' + DeviceParameters.WFK.id + ' (WiFi key)');
} catch (err) {
this.log.error('ERROR setting [WFK]: ' + err.message);
}
// after transmitting of the WiFi key we have to clear the state object imediatly
try {
await this.set_DevieParameter(DeviceParameters.WFK, '');
this.log.info('WiFi key state object ' + DeviceParameters.WFK.id + ' cleared');
} catch (err) {
this.log.error('ERROR setting [WFK]: ' + err.message);
}
}
else { this.log.error(DeviceParameters.WFK.id + ' new value [' + String(state.val) + '] is out of range! WiFi key is empty, to short or to longe. WIFI key 8-64 characters!'); }
}
//============================================================================
// TYP Safe-Tec type
//============================================================================
else if ((id == statePrefix + DeviceParameters.TYP.statePath + '.' + DeviceParameters.TYP.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.TYP.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.TYP.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.TYP, state.val);
this.log.info('User changed parameter ' + DeviceParameters.TYP.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.TYP.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [TYP]: ' + err.message);
}
}
}
//============================================================================
// WNS WiFi AP disabled
//============================================================================
else if ((id == statePrefix + DeviceParameters.WNS.statePath + '.' + DeviceParameters.WNS.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.WNS.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.WNS.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.WNS, state.val);
this.log.info('User changed parameter ' + DeviceParameters.WNS.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.WNS.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [WNS]: ' + err.message);
}
}
}
//============================================================================
// DKI Safe-Tec device kind ID
//============================================================================
else if ((id == statePrefix + DeviceParameters.DKI.statePath + '.' + DeviceParameters.DKI.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DKI.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DKI.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DKI, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DKI.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DKI.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DKI]: ' + err.message);
}
}
}
//============================================================================
// DOM MLT test time open
//============================================================================
else if ((id == statePrefix + DeviceParameters.DOM.statePath + '.' + DeviceParameters.DOM.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DOM.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DOM.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DOM, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DOM.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DOM.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DOM]: ' + err.message);
}
}
}
//============================================================================
// DPL MLT pulses
//============================================================================
else if ((id == statePrefix + DeviceParameters.DPL.statePath + '.' + DeviceParameters.DPL.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DPL.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DPL.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DPL, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DPL.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DPL.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DPL]: ' + err.message);
}
}
}
//============================================================================
// DST MLT test time NOPULS
//============================================================================
else if ((id == statePrefix + DeviceParameters.DST.statePath + '.' + DeviceParameters.DST.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DST.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DST.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DST, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DST.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DST.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DST]: ' + err.message);
}
}
}
//============================================================================
// DTC MLT verification cycles
//============================================================================
else if ((id == statePrefix + DeviceParameters.DTC.statePath + '.' + DeviceParameters.DTC.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.DTC.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.DTC.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.DTC, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DTC.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DTC.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [DTC]: ' + err.message);
}
}
}
//============================================================================
// DTT Micro-Leakage-Test start time
//============================================================================
else if ((id == statePrefix + DeviceParameters.DTT.statePath + '.' + DeviceParameters.DTT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if(String(state.val).length == 5 && String(state.val).substring(2,3) == ':' && !isNaN(parseFloat(String(state.val).substring(0,2))) && !isNaN(parseFloat(String(state.val).substring(3,5)))){
await this.set_DevieParameter(DeviceParameters.DTT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.DTT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.DTT.id + ' new value [' + String(state.val) + '] is not a valid Time string eg "04:35"!'); }
} catch (err) {
this.log.error('ERROR setting [DTT]: ' + err.message);
}
}
}
//============================================================================
// HTD Disable HTTPS connection (only MQTT)
//============================================================================
else if ((id == statePrefix + DeviceParameters.HTD.statePath + '.' + DeviceParameters.HTD.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.HTD.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.HTD.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.HTD, state.val);
this.log.info('User changed parameter ' + DeviceParameters.HTD.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.HTD.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [HTD]: ' + err.message);
}
}
}
//============================================================================
// MQT MQTT connection type
//============================================================================
else if ((id == statePrefix + DeviceParameters.MQT.statePath + '.' + DeviceParameters.MQT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.MQT.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.MQT.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.MQT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.MQT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.MQT.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [MQT]: ' + err.message);
}
}
}
//============================================================================
// MRT MQTT reconnect time
//============================================================================
else if ((id == statePrefix + DeviceParameters.MRT.statePath + '.' + DeviceParameters.MRT.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.MRT.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.MRT.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.MRT, state.val);
this.log.info('User changed parameter ' + DeviceParameters.MRT.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.MRT.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [MRT]: ' + err.message);
}
}
}
//============================================================================
// MSC Maintenance (Husty) server connection
//============================================================================
else if ((id == statePrefix + DeviceParameters.MSC.statePath + '.' + DeviceParameters.MSC.id) && (state.ack == false)) {
if (state.val != null) {
try {
if ((Number(state.val) >= Number(DeviceParameters.MSC.objectdefinition.common.min)) && Number(state.val) <= Number(DeviceParameters.MSC.objectdefinition.common.max)) {
await this.set_DevieParameter(DeviceParameters.MSC, state.val);
this.log.info('User changed parameter ' + DeviceParameters.MSC.id + ' to ' + String(state.val));
}
else { this.log.error(DeviceParameters.MSC.id + ' new value [' + String(state.val) + '] is out of range!'); }
} catch (err) {
this.log.error('ERROR setting [MSC]: ' + err.message);
}
}
}
//============================================================================
// AB Shutoff valve AB
//============================================================================
else if ((id == statePrefix + DeviceParameters.AB.statePath + '.' + DeviceParameters.AB.id) && state.ack == false) {
switch (state.val) {
case 1: