forked from iobroker-community-adapters/ioBroker.fhem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
3428 lines (3424 loc) · 160 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
/* jshint -W097 */
/* jshint strict:false */
/* jslint node: true */
'use strict';
const utils = require('@iobroker/adapter-core');
const adapterName = require('./package.json').name.split('.').pop();
const Telnet = require('./lib/telnet');
// Telnet sessions
let telnetOut = null; // read config and write values
let telnetIn = null; // receive events
let adapter;
let connected = false;
const eventIOB = [];
const delObj = [];
const eventQueue = [];
const setStateQueue = [];
const setStateLogQueue = [];
let fhemIN = {};
let fhemINs = {};
let fhemIgnore = {};
let fhemIgnoreConfig = {};
let infoObjects = {};
const fhemObjects = {};
const functions = {};
let lastNameQueue;
let lastNameTS = '0';
let iobroker = false;
let firstRun = true;
let synchro = true;
let debug = false;
let aktivQueue = false;
let aktiv = false;
const buildDate = '16.08.21';
const linkREADME = 'https://github.com/iobroker-community-adapters/ioBroker.fhem/blob/master/docs/de/README.md';
const tsStart = Date.now();
let t = '> ';
// info.Debug
let debugNAME = [];
let logDevelop;
let numEvent = 0;
let timeEvent = 0;
let numWriteOut = 0;
let timeWriteOut = 0;
let numWriteValue = 0;
let timeWriteValue = 0;
// info.Configurations
let syncUpdate;
let syncUpdateIOBin;
let advancedFunction;
let autoRole;
let autoFunction;
let autoRoom;
let autoConfigFHEM;
let autoSmartName;
let autoName;
let autoType;
let autoStates;
let autoRest;
let oldState;
let deleteUnusedObjects;
let logNoInfo;
let onlySyncNAME = [];
let onlySyncTYPE = [];
const onlySyncRoomS = ['ioBroker', 'ioB_OUT'];
let onlySyncRoom = [];
const ignoreObjectsInternalsTYPES = [];
let ignoreObjectsInternalsTYPE = [];
const ignoreObjectsInternalsNAMES = ['info'];
let ignoreObjectsInternalsNAME = [];
const ignoreObjectsAttributesRoomS = [];
let ignoreObjectsAttributesRoom = [];
const ignorePossibleSetsS = ['getConfig', 'etRegRaw', 'egBulk', 'regSet', 'deviceMsg', 'CommandAccepted'];
let ignorePossibleSets = [];
const ignoreReadingsS = ['currentTrackPositionSimulated', 'currentTrackPositionSimulatedSec'];
let ignoreReadings = [];
const allowedAttributesS = ['room', 'alias', 'comment'];
let allowedAttributes = [];
const allowedInternalsS = ['TYPE', 'NAME'];
let allowedInternals = [];
const allowedIOBinS = [];
let allowedIOBin = [];
let allowedIOBinExclude = [];
let allowedIOBinExcludeS = [];
const logEventFHEMexcludeS = [];
let logEventFHEMexclude = [];
// info.Settings
let logCheckObject;
let logUpdateChannel;
let logCreateChannel;
let logDeleteChannel;
let logEventIOB;
let logEventFHEM;
let logEventFHEMglobal;
let logEventFHEMreading;
let logEventFHEMstate;
let logUnhandledEventFHEM;
let logIgnoreConfigurations;
// parseObject
const dimPossibleSets = ['pct', 'brightness', 'dim', 'pos']; //08.02.21
const volumePossibleSets = ['Volume', 'volume', 'GroupVolume'];
const temperaturePossibleSets = ['desired-temp'];
const Utemperature = ['temperature', 'measured-temp', 'desired-temp', 'degrees', 'box_cputemp', 'temp_c', 'cpu_temp', 'cpu_temp_avg'];
const rgbPossibleSets = ['rgb'];
const Rindicator = ['reachable', 'presence', 'battery', 'Activity', 'present', 'batteryState'];
//const
function startAdapter(options) {
options = options || {};
Object.assign(options, {name: adapterName});
adapter = new utils.Adapter(options);
// is called when adapter shuts down - callback has to be called under any circumstances!
adapter.on('unload', callback => {
try {
connected = false;
// stop all timers
Object.keys(adapter.__timeouts).forEach(name => {
adapter.__timeouts[name] && clearTimeout(adapter.__timeouts[name]);
adapter.__timeouts[name] = null;
adapter.log.debug('adapter.on.unload: clearTimeout ' + name);
});
adapter.setState('info.connection', false, true);
adapter.setState('info.Info.alive', false, true);
if (telnetOut) {
telnetOut.destroy();
telnetOut = null;
}
if (telnetIn) {
telnetIn.destroy();
telnetIn = null;
}
callback();
} catch (e) {
callback();
}
});
// is called if a subscribed state changes
adapter.on('stateChange', (id, state) => {
let fn = '[stateChange] ';
let ts = Date.now();
// you can use the ack flag to detect if it is status (true) or command (false)
if (!state) {
adapter.log.debug(fn + 'no state - ' + id);
return;
}
let val = state.val;
let ack = state.ack;
logDebug(fn, id, 'stateChange (in): ' + id + ' ' + val + ' ' + JSON.stringify(state), '');
if (!id.startsWith(adapter.namespace)) {
let idFHEM = convertNameIob(fn, id);
if (fhemIN[idFHEM]) {
if (val !== fhemINs[idFHEM].val || syncUpdateIOBin) {
eventIOB.push({
command: 'writeOut',
id: idFHEM,
val: val,
ts: ts
});
fhemINs[idFHEM] = {
id: id,
val: val
};
if (!firstRun)
checkQueue(fn);
return;
} else {
return;
}
}
}
if (ack)
return;
// no ack and from adapter ?
if (!state.ack && id.startsWith(adapter.namespace)) {
if (id === adapter.namespace + '.info.resync') {
logWarn(fn, '----- request restart adapter');
eventIOB.push({
command: 'resync'
});
checkQueue(fn);
return;
} else if (fhemObjects[id] || id.startsWith(adapter.namespace + '.info')) {
logDebug(fn, id, 'stateChange(write): ' + id + ' ' + val + ' ' + JSON.stringify(state), 'D');
eventIOB.push({
command: 'write',
id: id,
val: val,
ts: ts
});
checkQueue(fn);
return;
} else {
logStateChange(fn, id, val, 'stateChange - no match !state.ack && id.startsWith(adapter.namespace) id: ' + id, 'neg');
return;
}
} else {
logDebug(fn + t, id, 'stateChange: ' + id + ' | ' + val + ' | ack: ' + ack, 'D');
return;
}
logStateChange(fn, id, val, 'stateChange - no match ' + JSON.stringify(state), 'neg');
});
// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ...
adapter.on('message', obj => {
if (typeof obj === 'object' && obj.message) {
if (obj.command === 'send') {
// e.g. send email or pushover or whatever
console.log('send command');
// Send response in callback if required
if (obj.callback) {
adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback);
}
}
}
});
// is called when databases are connected and adapter received configuration.
// start here!
adapter.on('ready', main);
adapter.__timeouts = {};
return adapter;
}
//========================================================================================================================================== start
function firstCheck(ff, cb) {
let fn = ff + '[firstCheck] ';
logDebug(fn, '', 'start', 'D');
adapter.setState('info.resync', false, true);
getSetting(fn, 'info.Debug.logDevelop', value => {
logDevelop = value;
getSetting(fn, 'info.Configurations.logNoInfo', value => {
logNoInfo = value;
logDebug(fn, '', 'end', 'D');
cb();
});
});
}
// STEP 01
function myObjects(ff, cb) {
let fn = ff + '[myObjects] ';
logDebug(fn, '', 'start', 'D');
let id;
const newPoints = [
// info.Commands
{_id: 'info.Commands.lastCommand', type: 'state', common: {name: 'Last command to FHEM', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Commands.resultFHEM', type: 'state', common: {name: 'Result of FHEM', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Commands.sendFHEM', type: 'state', common: {name: 'Command to FHEM', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Commands.createSwitch', type: 'state', common: {name: 'Create dummy as switch in room FHEM (NAME room)', type: 'string', read: true, write: true, role: 'state'}, native: {}},
// info.Configurations
{_id: 'info.Configurations.autoConfigFHEM', type: 'state', common: {name: 'FUNCTION - allow special configurations FHEM', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoFunction', type: 'state', common: {name: 'FUNCTION - auto create function of object (use Adapter Material)', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoRoom', type: 'state', common: {name: 'FUNCTION - auto create room of channel (use Adapter Material)', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoRole', type: 'state', common: {name: 'FUNCTION - auto create role of object (use Adapter Material)', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoSmartName', type: 'state', common: {name: 'FUNCTION - (fhem.0) auto create SmartName of object (Adapter Cloud/IoT)', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoName', type: 'state', common: {name: 'FUNCTION - auto create name of object', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoType', type: 'state', common: {name: 'FUNCTION - auto create type of object', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoStates', type: 'state', common: {name: 'FUNCTION - auto create states of object', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.autoRest', type: 'state', common: {name: 'FUNCTION - auto create read,write,min,max,unit of object', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.deleteUnusedObjects', type: 'state', common: {name: 'FUNCTION - delete unused objects automatically', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.oldState', type: 'state', common: {name: 'FUNCTION - old version of state with true/false', type: 'boolean', read: true, write: true, role: 'switch', def: false}, native: {}},
{_id: 'info.Configurations.allowedIOBin', type: 'state', common: {name: 'SYNC - allowed objects send2FHEM', type: 'string', read: true, write: true, role: 'state'}, native: {default: '.'}},
{_id: 'info.Configurations.allowedIOBinExclude', type: 'state', common: {name: 'SYNC - exclude allowedIOBin', type: 'string', read: true, write: true, role: 'state'}, native: {default: '.'}},
{_id: 'info.Configurations.ignoreObjectsInternalsTYPE', type: 'state', common: {name: 'SYNC - ignore device(s) TYPE (default: ' + ignoreObjectsInternalsTYPES + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.ignoreObjectsInternalsNAME', type: 'state', common: {name: 'SYNC - ignore device(s) NAME (default: ' + ignoreObjectsInternalsNAMES + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.ignoreObjectsAttributesroom', type: 'state', common: {name: 'SYNC - ignore device(s) of room(s) (default: ' + ignoreObjectsAttributesRoomS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.allowedAttributes', type: 'state', common: {name: 'SYNC - allowed Attributes (default: ' + allowedAttributesS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.allowedInternals', type: 'state', common: {name: 'SYNC - allowed Internals (default: ' + allowedInternalsS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.ignoreReadings', type: 'state', common: {name: 'SYNC - ignore Readings (default: ' + ignoreReadingsS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.ignorePossibleSets', type: 'state', common: {name: 'SYNC - ignore PossibleSets (default: ' + ignorePossibleSetsS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.onlySyncRoom', type: 'state', common: {name: 'SYNC - only sync device(s) if room exist (default: ' + onlySyncRoomS + ')', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.onlySyncNAME', type: 'state', common: {name: 'SYNC - only sync device(s) NAME', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.onlySyncTYPE', type: 'state', common: {name: 'SYNC - only sync device(s) TYPE', type: 'string', read: true, write: true, role: 'state'}, native: {}},
{_id: 'info.Configurations.logNoInfo', type: 'state', common: {name: 'FUNCTION - no LOG info', type: 'boolean', read: true, write: true, role: 'switch', def: false}, native: {}},
{_id: 'info.Configurations.advancedFunction', type: 'state', common: {name: 'FUNCTION - advanced', type: 'boolean', read: true, write: true, role: 'switch', def: false}, native: {}},
{_id: 'info.Configurations.syncUpdate', type: 'state', common: {name: 'FUNCTION - sync update FHEM reading', type: 'boolean', read: true, write: true, role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.syncUpdateIOBin', type: 'state', common: {name: 'FUNCTION - sync update allowedIOBin', type: 'boolean', read: true, write: true, role: 'switch', def: true}, native: {}},
{_id: 'info.Configurations.logEventFHEMexclude', type: 'state', common: {name: 'SYNC - exclude logEventFHEM', type: 'string', read: true, write: true, role: 'state'}, native: {default: '.'}},
// info.Debug
{_id: 'info.Debug.jsonlist2', type: 'state', common: {name: 'jsonlist2 of FHEM', type: 'string', read: true, write: true, role: 'json'}, native: {}},
{_id: 'info.Debug.meta', type: 'state', common: {name: 'Device NAME of FHEM', type: 'string', read: true, write: true, role: 'text'}, native: {}},
{_id: 'info.Debug.activate', type: 'state', common: {name: 'Debug Mode for Device(s) NAME', type: 'string', read: true, write: true, role: 'text'}, native: {}},
{_id: 'info.Debug.logDevelop', type: 'state', common: {name: 'More info debug', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Debug.numberIn', type: 'state', common: {name: 'Number of events of FHEM last 5 min', type: 'number', read: true, write: false, role: 'value', def: 0}, native: {}},
{_id: 'info.Debug.timeIn', type: 'state', common: {name: 'Average time(ms) of events of FHEM last 5 min', type: 'number', read: true, write: false, role: 'value', def: 0}, native: {}},
{_id: 'info.Debug.numberOut', type: 'state', common: {name: 'Number of stateChanges(s) of ioBroker last 5 min', type: 'number', read: true, write: false, role: 'value', def: 0}, native: {}},
{_id: 'info.Debug.timeOut', type: 'state', common: {name: 'Average time(ms) stateChanges(s) of ioBroker last 5 min', type: 'number', read: true, write: false, role: 'value', def: 0}, native: {}},
{_id: 'info.Debug.fhemObjectsRead', type: 'state', common: {name: 'Device NAME of FHEM', type: 'string', read: true, write: true, role: 'text'}, native: {}},
// info.Info
{_id: 'info.Info.buildDate', type: 'state', common: {name: 'Date of main.js', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Info.roomioBroker', type: 'state', common: {name: 'room of fhem.x.info.Configurations.onlySyncRoom exist', type: 'boolean', read: true, write: false, role: 'indicator'}, native: {}},
{_id: 'info.Info.numberDevicesFHEM', type: 'state', common: {name: 'Number devices of FHEM (jsonlist2)', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.numberDevicesFHEMsync', type: 'state', common: {name: 'Number devices of FHEM (synchronized)', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.numberObjectsIOBout', type: 'state', common: {name: 'Number of objects IOB out (detected)', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.numberObjectsIOBoutSub', type: 'state', common: {name: 'Number of objects IOB out (subscribe)', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.numberObjectsIOBin', type: 'state', common: {name: 'Number of objects IOB in', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.alive', type: 'state', common: {name: 'FHEM alive', type: 'boolean', read: true, write: false, role: 'indicator.connected'}, native: {}},
{_id: 'info.Info.numberDevicesFHEMignored', type: 'state', common: {name: 'Number devices of FHEM (ignored)', type: 'number', read: true, write: false, role: 'value'}, native: {}},
{_id: 'info.Info.lastWarn', type: 'state', common: {name: 'lastWarn', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Info.lastError', type: 'state', common: {name: 'lastError', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Info.lastInfo', type: 'state', common: {name: 'lastInfo', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Info.lastSend2ioB', type: 'state', common: {name: 'lastSend2ioB', type: 'string', read: true, write: false, role: 'text'}, native: {}},
{_id: 'info.Info.lastIOBout', type: 'state', common: {name: 'lastIOBout', type: 'string', read: true, write: false, role: 'text'}, native: {}},
// info.Settings
{_id: 'info.Settings.logCheckObject', type: 'state', common: {name: 'LOG "check channel ....." ', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logCreateChannel', type: 'state', common: {name: 'LOG "Create channel ....." ', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logDeleteChannel', type: 'state', common: {name: 'LOG "Delete channel ....." ', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logEventFHEM', type: 'state', common: {name: 'LOG "event FHEM ....." all events from FHEM over telnet)', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logEventFHEMglobal', type: 'state', common: {name: 'LOG "event FHEM(g) ....." events global from FHEM', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Settings.logEventFHEMreading', type: 'state', common: {name: 'LOG "event FHEM(r) ....." events readings from FHEM', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logEventFHEMstate', type: 'state', common: {name: 'LOG "event FHEM(s) ....." events state from FHEM', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Settings.logEventIOB', type: 'state', common: {name: 'LOG "stateChange: ....." all events ioBroker to FHEM', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Settings.logUnhandledEventFHEM', type: 'state', common: {name: 'LOG "unhandled event FHEM ....." all events unhandled from FHEM', type: 'boolean', role: 'switch', def: true}, native: {}},
{_id: 'info.Settings.logUpdateChannel', type: 'state', common: {name: 'LOG "Update channel ....." ', type: 'boolean', role: 'switch', def: false}, native: {}},
{_id: 'info.Settings.logIgnoreConfigurations', type: 'state', common: {name: 'LOG "ignore FHEM device ....." ignored Devices from FHEM (info.Configurations) ', type: 'boolean', role: 'switch', def: false}, native: {}}
];
id = adapter.namespace + '.info.resync';
infoObjects[id] = {id: id};
id = adapter.namespace + '.info.connection';
infoObjects[id] = {id: id};
logInfo(fn, '> check new/update objects ');
for (let i = 0; i < newPoints.length; i++) {
adapter.getObject(newPoints[i]._id, newPoints[i], (e, obj) => {
e && logError(fn, e);
id = adapter.namespace + '.' + newPoints[i]._id;
infoObjects[id] = {id: id};
if (!obj) {
adapter.setObject(newPoints[i]._id, newPoints[i], e => {
e && logError(fn, e);
logInfo(fn, '> create ' + adapter.namespace + '.' + newPoints[i]._id + ' - ' + newPoints[i].common.name + ' (NEW)', () => {
if (i === newPoints.length - 1) {
deleteMyObjects(ff, i, () => {
logDebug(fn, '', 'end', 'D');
cb();
});
}
});
});
} else {
adapter.extendObject(newPoints[i]._id, newPoints[i], e => {
e && logError(fn, e);
logDebug(fn, '', '> update ' + adapter.namespace + '.' + newPoints[i]._id + ' - ' + newPoints[i].common.name, '', () => {
if (i === newPoints.length - 1) {
deleteMyObjects(ff, i, () => {
logDebug(fn, '', 'end', 'D');
cb();
});
}
});
});
}
});
}
}
function deleteMyObjects(ff, i, cb) {
let fn = ff + '[deleteMyObjects] ';
logDebug(fn, '', 'start', 'D');
logInfo(fn, '> check old objects and delete');
adapter.getStates(adapter.namespace + '.info.*', (e, states) => {
if (e) {
logError(fn, e);
cb();
} else {
for (const id in states) {
if (!states.hasOwnProperty(id)) {
continue;
}
if (!infoObjects[id]) {
adapter.log.warn(id + ' ' + JSON.stringify(states));
delObj.push({
command: 'delState',
name: id
});
delObj.push({
command: 'delObject',
name: id
});
}
}
logInfo(fn, '> ' + (i + 1) + ' objects ' + adapter.namespace + '.info OK');
logDebug(fn, '', 'end', 'D');
cb();
}
});
}
//STEP 02
function getConfigurationsSYNC(ff, cb) {
let fn = ff + '[getConfigurationsSYNC] ';
logDebug(fn, '', 'start', 'D');
if (!firstRun)
logInfo(fn, 'change Configurations of FUNCTION ===== check ' + adapter.namespace + '.' + 'info.Configurations (true or value) - select function of Adapter and Devices to sync');
allowedIOBin = allowedIOBinS.slice();
getConfig(fn, 'info.Configurations.allowedIOBin', allowedIOBin, () => {
allowedIOBinExclude = allowedIOBinExcludeS.slice();
getConfig(fn, 'info.Configurations.allowedIOBinExclude', allowedIOBinExclude, () => {
ignoreObjectsAttributesRoom = ignoreObjectsAttributesRoomS.slice();
getConfig(fn, 'info.Configurations.ignoreObjectsAttributesroom', ignoreObjectsAttributesRoom, () => {
ignoreObjectsInternalsNAME = ignoreObjectsInternalsNAMES.slice();
getConfig(fn, 'info.Configurations.ignoreObjectsInternalsNAME', ignoreObjectsInternalsNAME, () => {
ignoreObjectsInternalsTYPE = ignoreObjectsInternalsTYPES.slice();
getConfig(fn, 'info.Configurations.ignoreObjectsInternalsTYPE', ignoreObjectsInternalsTYPE, () => {
allowedAttributes = allowedAttributesS.slice();
getConfig(fn, 'info.Configurations.allowedAttributes', allowedAttributes, () => {
allowedInternals = allowedInternalsS.slice();
getConfig(fn, 'info.Configurations.allowedInternals', allowedInternals, () => {
ignoreReadings = ignoreReadingsS.slice();
getConfig(fn, 'info.Configurations.ignoreReadings', ignoreReadings, () => {
ignorePossibleSets = ignorePossibleSetsS.slice();
getConfig(fn, 'info.Configurations.ignorePossibleSets', ignorePossibleSets, () => {
onlySyncNAME = [];
getConfig(fn, 'info.Configurations.onlySyncNAME', onlySyncNAME, () => {
onlySyncTYPE = [];
getConfig(fn, 'info.Configurations.onlySyncTYPE', onlySyncTYPE, () => {
onlySyncRoom = onlySyncRoomS.slice();
getConfig(fn, 'info.Configurations.onlySyncRoom', onlySyncRoom, () => {
//25.06.21
logEventFHEMexclude = logEventFHEMexcludeS.slice();
getConfig(fn, 'info.Configurations.logEventFHEMexclude', logEventFHEMexclude, () => {
logDebug(fn, '', 'end', 'D');
cb && cb();
});
});
});
});
});
});
});
});
});
});
});
});
});
}
//STEP 03
function getConfigurationsFUNCTION(ff, cb) {
let fn = ff + '[getConfigurationsFUNCTION] ';
logDebug(fn, '', 'start', 'D');
if (!firstRun)
logInfo(fn, 'change Configurations of FUNCTION ===== check ' + adapter.namespace + '.' + 'info.Configurations (value) - Devices to sync');
getSetting(fn, 'info.Configurations.autoRole', value => autoRole = value);
getSetting(fn, 'info.Configurations.autoFunction', value => autoFunction = value);
getSetting(fn, 'info.Configurations.autoRoom', value => autoRoom = value);
getSetting(fn, 'info.Configurations.autoConfigFHEM', value => autoConfigFHEM = value);
getSetting(fn, 'info.Configurations.autoSmartName', value => autoSmartName = value);
getSetting(fn, 'info.Configurations.autoName', value => autoName = value);
getSetting(fn, 'info.Configurations.autoType', value => autoType = value);
getSetting(fn, 'info.Configurations.autoStates', value => autoStates = value);
getSetting(fn, 'info.Configurations.autoRest', value => autoRest = value);
getSetting(fn, 'info.Configurations.deleteUnusedObjects', value => deleteUnusedObjects = value);
getSetting(fn, 'info.Configurations.advancedFunction', value => advancedFunction = value);
getSetting(fn, 'info.Configurations.syncUpdate', value => syncUpdate = value);
getSetting(fn, 'info.Configurations.syncUpdateIOBin', value => syncUpdateIOBin = value); //29.01.21
getSetting(fn, 'info.Configurations.oldState', value => {
oldState = value;
adapter.setState('info.Info.buildDate', buildDate, true);
let start = '----- start FHEM Adapter Instanz ' + adapter.namespace;
let text;
if (advancedFunction) {
text = start;
} else {
text = '----- not in use - info.Configurations.advancedFunction(false)';
}
adapter.setState('info.Info.lastWarn', text, true);
adapter.setState('info.Info.lastError', text, true);
adapter.setState('info.Info.lastInfo', text, true);
adapter.setState('info.Info.lastSend2ioB', text, true);
adapter.setState('info.Info.lastIOBout', text, true);
adapter.setState('info.Commands.lastCommand', start, true);
logDebug(fn, '', 'end', 'D');
cb && cb();
});
}
//STEP 04
function getSettings(ff, cb) {
let fn = ff + '[getSettings] ';
logDebug(fn, '', 'start', 'D');
if (!firstRun)
logInfo(fn, 'change Settings ===== check ' + adapter.namespace + '.' + 'info.Settings (true) - select message ioBroker admin > LOG');
getSetting(fn, 'info.Settings.logCheckObject', value => logCheckObject = value);
getSetting(fn, 'info.Settings.logUpdateChannel', value => logUpdateChannel = value);
getSetting(fn, 'info.Settings.logCreateChannel', value => logCreateChannel = value);
getSetting(fn, 'info.Settings.logDeleteChannel', value => logDeleteChannel = value);
getSetting(fn, 'info.Settings.logEventIOB', value => logEventIOB = value);
getSetting(fn, 'info.Settings.logEventFHEM', value => logEventFHEM = value);
getSetting(fn, 'info.Settings.logEventFHEMglobal', value => logEventFHEMglobal = value);
getSetting(fn, 'info.Settings.logEventFHEMreading', value => logEventFHEMreading = value);
getSetting(fn, 'info.Settings.logEventFHEMstate', value => logEventFHEMstate = value);
getSetting(fn, 'info.Settings.logUnhandledEventFHEM', value => logUnhandledEventFHEM = value);
getSetting(fn, 'info.Settings.logIgnoreConfigurations', value => {
logIgnoreConfigurations = value;
logDebug(fn, '', 'end', 'D');
cb && cb();
});
}
// more
function getSetting(ff, id, cb) {
let fn = ff + '[getSetting] ';
logDebug(fn, '', id, 'D');
adapter.getObject(id, (e, obj) => {
e && logError(fn, e);
if (obj) {
adapter.getState(id, (e, state) => {
e && logError(fn, e);
if (state) {
logDebug(fn, '', id + ' ' + state.val, '');
state.val && logInfo(fn, '> ' + obj.common.name + ' - ' + id + ' (' + state.val + ')');
adapter.setState(id, state.val, true);
cb(state.val);
} else {
logDebug(fn, '', id + ' - no state found', '');
cb();
}
});
} else {
logDebug(fn, '', id + ' - no object found', '');
cb();
}
});
}
function getConfig(ff, id, config, cb) {
let fn = ff + '[getConfig] ';
adapter.log.debug(fn + id + ' (' + config + ')');
adapter.getObject(id, (e, obj) => {
e && logError(fn, e);
if (obj) {
adapter.getState(id, (e, state) => {
e && logError(fn, e);
adapter.log.debug(fn + id + ': ' + JSON.stringify(state));
if (state && state.val) {
adapter.setState(id, state.val, true);
const part = state.val.split(",");
if (part[0]) {
for (const i in part) {
config.push(part[i].trim());
}
}
config.length && logInfo(fn, '> ' + obj.common.name + ' - ' + id + ' (' + config + ')');
cb && cb();
} else {
cb && cb();
}
});
}
});
}
//STEP 05
function getDebug(ff, cb) {
let fn = ff + '[getDebug] ';
logDebug(fn, '', 'start', 'D');
if (!firstRun)
logInfo(fn, 'CHANGE debug ===== check ' + adapter.namespace + '.' + 'info.Debug - Activate Debug-Mode for channel(s)');
debugNAME = [];
adapter.getState('info.Debug.activate', (e, state) => {
e && logError(fn, e);
if (state) {
const part = state.val.split(",");
if (part[0]) {
for (const i in part) {
debugNAME.push(part[i].trim());
}
}
if (debugNAME.length) {
logInfo(fn, '> ' + adapter.namespace + '.' + 'info.Debug.activate' + ' = ' + debugNAME);
} else {
logInfo(fn, '> no sync - ' + adapter.namespace + '.' + 'info.Debug.activate');
}
logDebug(fn, '', fn + 'with obj - end', 'D');
cb && cb();
} else {
logDebug(fn, '', fn + 'end', 'D');
cb && cb();
}
});
}
//STEP 06
function checkSubscribe(ff, cb) {
let fn = ff + '[checkSubscribe] ';
logDebug(fn, '', 'start', 'D');
if (!allowedIOBin.length) {
logInfo(fn, '> no sync - ' + adapter.namespace + '.info.Configurations.allowedIOBin');
adapter.setState('info.Info.numberObjectsIOBoutSub', 0, true);
cb && cb();
return;
}
let end = 0;
allowedIOBin.forEach(search => {
adapter.getForeignStates(search + '*', (e, states) => {
if (e) {
logError(fn, 'error: ' + e);
} else {
logDebug(fn, '', fn + 'detected' + JSON.stringify(states), 'D');
logInfo(fn, '> detected ' + Object.keys(states).length + ' state(s) of "' + search + '"');
for (const id in states) {
if (!states.hasOwnProperty(id)) {
continue;
}
let foundEx = false;
let end1 = 0;
if (!allowedIOBinExclude.length)
allowedIOBinExclude = ['?'];
allowedIOBinExclude.forEach(searchEx => {
if (id.startsWith(searchEx)) {
logInfo(fn, '>> excluded ' + id);
foundEx = true;
}
end1++;
if (end1 === allowedIOBinExclude.length && !foundEx) {
let idFHEM = convertNameIob(fn, id);
let val;
try {
val = states[id].val;
} catch (e) {
val = '???';
}
fhemINs[idFHEM] = {
id: id,
val: val
};
fhemIgnore[idFHEM] = {id: id};
logDebug(fn, '', fn + 'found ' + id, '');
foundEx = false;
end1 = 0;
}
});
}
end++;
if (end === allowedIOBin.length) {
adapter.setState('info.Info.numberObjectsIOBoutSub', Object.keys(fhemINs).length, true);
logDebug(fn, '', 'end', 'D');
cb && cb();
}
}
});
});
}
// STEP 07-09
function syncFHEM(ff, cb) {
let fn = ff + '[syncFHEM] ';
logDebug(fn, '', 'start', 'D');
let send = 'jsonlist2';
if (onlySyncNAME.length) {
send = send + ' ' + onlySyncNAME + ',' + adapter.namespce + '.send2ioB';
logInfo(fn, '> only jsonlist2 ' + onlySyncNAME + ' - ' + adapter.namespace + '.info.Configurations.onlySyncNAME (' + onlySyncNAME + ')');
}
if (!connected) {
logInfo(fn, '> Connected FHEM telnet ' + adapter.config.host + ':' + adapter.config.port + ' - send telnet "' + send + '"');
connected = true;
adapter.setState('info.connection', true, true);
}
telnetOut.send(send, (e, result) => {
e && logError(fn, 'telnetOut.send: ' + e);
if (result) {
logInfo(fn, '> result of jsonlist2 OK');
let objects = null;
try {
objects = JSON.parse(result);
} catch (e) {
if (e.name === 'SyntaxError' && e.message.startsWith('Unexpected token')) {
let stelle = Number(e.message.replace(/[^0-9]/g, ""));
let stelleN = result.lastIndexOf('NAME', stelle);
let stelleName = result.indexOf(',', stelleN);
logError(fn, '> SyntaxError jsonlist2 of FHEM device ' + result.substr(stelleN, stelleName - stelleN) + ' --> stop instance ' + adapter.namespace);
let stelleE = result.indexOf('Name', stelleN);
adapter.log.debug(fn + 'SyntaxError: ' + result.substr(stelleN, stelleE - stelleN));
} else {
logError(fn, 'Cannot parse answer for jsonlist2: ' + e);
}
if (firstRun)
adapter.setForeignState('system.adapter.fhem.1.alive', false, false);
}
if (objects) {
logInfo(fn, '> get ' + objects.Results.length + ' Device(s) of FHEM');
if (connected) {
parseObjects(fn, objects.Results, () => {
logDebug(fn, '', fn + 'end', 'D');
cb && cb();
});
} else {
cb && cb();
}
} else {
logDebug(fn, '', fn + 'no objects - end', 'D');
cb && cb();
}
} else {
logDebug(fn, '', fn + 'no result - end', 'D');
cb && cb();
}
});
}
function parseObjects(ff, objs, cb) {
let fn = ff + '[parseObjects] ';
logDebug(fn, '', 'start', 'D');
const rooms = {};
const objects = [];
const states = [];
let id;
let obj;
let alias;
let suche = 'no';
let text;
const debugShow = '';
if (firstRun) {
for (let i = 0; i < objs.length; i++) {
try {
if (iobroker) {
continue;
}
if (objs[i].Attributes.room) {
suche = objs[i].Attributes.room.split(',');
for (const r in suche) {
if (onlySyncRoom.indexOf(suche[r]) !== -1) {
adapter.log.debug(fn + 'detected room ' + onlySyncRoom + ' / ' + i + ' > iobroker=true');
iobroker = true;
}
}
}
} catch (e) {
logError(fn, 'Cannot check room of object: ' + JSON.stringify(objs[i]) + ' ' + e);
}
}
adapter.setState('info.Info.numberDevicesFHEM', objs.length, true);
firstRun && logInfo(fn, 'STEP 08 ===== parse Objects - check ' + objs.length + ' Device(s) of FHEM detected');
adapter.setState('info.Info.roomioBroker', iobroker, true);
iobroker && logInfo(fn, '> only sync device(s) from room(s) = ' + onlySyncRoom + ' - ' + adapter.namespace + '.info.Info.roomioBroker (' + iobroker + ')');
onlySyncNAME.length && logInfo(fn, '> only sync device(s) = ' + onlySyncNAME + ' - ' + adapter.namespace + '.info.Configurations.onlySyncNAME (' + onlySyncNAME + ')');
ignoreObjectsAttributesRoom.length && logInfo(fn, '> no sync device(s) of room(s) = ' + ignoreObjectsAttributesRoom + ' - ' + adapter.namespace + '.info.Configurations.ignoreObjectsAttributesroom (' + ignoreObjectsAttributesRoom + ')');
ignoreObjectsInternalsNAME.length && logInfo(fn, '> no sync device(s) with Internals:NAME = ' + ignoreObjectsInternalsNAME + ' - ' + adapter.namespace + '.info.Configurations.ignoreObjectsInternalsNAME (' + ignoreObjectsInternalsNAME + ')');
ignoreObjectsInternalsTYPE.length && logInfo(fn, '> no sync device(s) with Internals:TYPE = ' + ignoreObjectsInternalsTYPE + ' - ' + adapter.namespace + '.info.Configurations.ignoreObjectsInternalsTYPE (' + ignoreObjectsInternalsTYPE + ')');
}
for (let i = 0; i < objs.length; i++) {
const device = objs[i].Name;
const debugN = device + ' | ';
if (!connected) {
(cb);
return;
}
try {
// Auto-created by ioBroker ?
if (objs[i].Attributes.comment && objs[i].Attributes.comment.startsWith('Auto-created by ioBroker fhem')) {
// nicht eigene Instanz?
if (objs[i].Attributes.comment.indexOf('Auto-created by ioBroker ' + adapter.namespace)) {
fhemIgnore[device] = {id: device};
fhemIgnoreConfig[device] = {id: device};
logIgnoreConfig(fn, device, 'comment: ' + objs[i].Attributes.comment, i, objs.length);
continue;
}
if (!fhemINs[device] && objs[i].Attributes.room.startsWith('ioB_IN')) {
logIgnoreConfig(fn, device, 'comment: ' + objs[i].Attributes.comment, i, objs.length);
sendFHEM(fn, 'delete ' + device);
continue;
}
if (fhemINs[device] && objs[i].Attributes.room.startsWith('ioB_IN')) {
fhemIN[device] = {id: device};
fhemIgnore[device] = {id: device};
logIgnoreConfig(fn, device, 'comment: ' + objs[i].Attributes.comment, i, objs.length);
continue;
}
if (device.indexOf('alive') !== -1) {
fhemIgnore[device] = {id: device};
logIgnoreConfig(fn, device, 'comment: ' + objs[i].Attributes.comment, i, objs.length);
continue;
}
if (device.indexOf('send2ioB') !== -1) {
fhemIgnore[device] = {id: device};
logIgnoreConfig(fn, device, 'comment: ' + objs[i].Attributes.comment, i, objs.length);
continue;
}
}
if (objs[i].Attributes && iobroker) {
if (!objs[i].Attributes.room) {
logIgnoreConfig(fn, device, 'no room, iobroker=true', i, objs.length);
continue;
} else {
let weiter = true;
let searchRoom = objs[i].Attributes.room.split(',');
for (const r in searchRoom) {
if (onlySyncRoom.indexOf(searchRoom[r]) !== -1 || searchRoom[r] === 'ioB_System') {
logDebug(fn, device, 'detected room ' + searchRoom[r] + '/' + r + ' of FHEM device "' + device + '"', 'D');
weiter = false;
}
}
if (weiter && !synchro) {
unusedObjects(fn, convertNameFHEM(fn, device) + '.*', cb);
}
if (weiter) {
logIgnoreConfig(fn, device, 'room <> ' + onlySyncRoom, i, objs.length);
continue;
}
}
}
if (onlySyncNAME.length && onlySyncNAME.indexOf(objs[i].Internals.NAME) === -1) {
logIgnoreConfig(fn, device, 'NAME <> ' + onlySyncNAME, i, objs.length);
continue;
}
if (onlySyncTYPE.length && onlySyncTYPE.indexOf(objs[i].Internals.TYPE) === -1) {
logIgnoreConfig(fn, device, 'TYPE <> ' + onlySyncTYPE, i, objs.length);
continue;
}
if (ignoreObjectsInternalsTYPE.indexOf(objs[i].Internals.TYPE) !== -1) {
logIgnoreConfig(fn, device, 'TYPE: ' + ignoreObjectsInternalsTYPE, i, objs.length);
continue;
}
if (ignoreObjectsInternalsNAME.indexOf(objs[i].Internals.NAME) !== -1) {
logIgnoreConfig(fn, device, 'NAME: ' + ignoreObjectsInternalsNAME, i, objs.length);
continue;
}
if (ignoreObjectsAttributesRoom.indexOf(objs[i].Attributes.room) !== -1) {
logIgnoreConfig(fn, device, 'room: ' + ignoreObjectsAttributesRoom, i, objs.length);
continue;
}
if (objs[i].Attributes && objs[i].Attributes.room === 'hidden') {
logIgnoreConfig(fn, device, 'room: hidden', i, objs.length);
continue;
}
logDebug(fn, device, 'detected FHEM device "' + device + '" to sync', 'D');
let isOn = false;
let isOff = false;
let setStates = {};
let Funktion = 'no';
let id;
const nameIob = convertNameFHEM(fn, device);
const channel = adapter.namespace + '.' + nameIob;
//alias?
if (objs[i].Attributes && objs[i].Attributes.alias) {
alias = objs[i].Attributes.alias;
} else {
alias = device;
}
obj = {
_id: channel,
type: 'channel',
common: {
name: alias
},
native: objs[i]
};
if (objs[i].Internals.TYPE === 'HUEBridge') {
if (!objs[i].Attributes.createGroupReadings) {
sendFHEM(fn, 'attr ' + device + ' createGroupReadings 1', 'TYPE:HUEBridge');
}
}
if (objs[i].Internals.TYPE === 'HUEDevice') {
Funktion = 'light';
if (objs[i].Internals.type) {
if (objs[i].Internals.type.indexOf('ZLL') !== -1 || objs[i].Internals.type === 'MotionDetector') {
Funktion = 'sensor';
}
}
}
if (objs[i].Internals.TYPE === 'SONOSPLAYER') {
Funktion = 'audio';
obj.common.role = 'media.music';
if (!objs[i].Attributes.generateVolumeEvent) {
sendFHEM(fn, 'attr ' + device + ' generateVolumeEvent 1', 'TYPE:SONOSPLAYER');
}
}
if (objs[i].Attributes.model === 'HM-CC-RT-DN') {
Funktion = 'heating';
obj.common.role = 'thermostate';
}
if (objs[i].Attributes.subType === 'thermostat') {
Funktion = 'heating';
}
if (objs[i].Attributes.subType === 'smokeDetector') {
Funktion = 'security';
}
if (objs[i].Attributes.subType === 'blindActuator') {
Funktion = 'blind';
}
// Functions
if (Funktion !== 'no' && autoFunction && objs[i].Attributes.room) {
setFunction(channel, Funktion);
}
objects.push(obj);
text = 'check channel ' + channel + ' | name: ' + alias + ' | room: ' + objs[i].Attributes.room + ' | role: ' + obj.common.role + ' | function: ' + Funktion + ' | ' + ' ' + (i + 1) + '/' + objs.length;
if (logCheckObject && debugNAME.indexOf(device) === -1) {
logInfo(fn, text);
} else {
logDebug(fn, device, text, '');
}
// Rooms
if (objs[i].Attributes && objs[i].Attributes.room && autoRoom) {
const rrr = objs[i].Attributes.room.split(',');
for (let r = 0; r < rrr.length; r++) {
rrr[r] = rrr[r].trim();
rooms[rrr[r]] = rooms[rrr[r]] || [];
rooms[rrr[r]].push(channel);
}
}
// Attributes
if (objs[i].Attributes) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.info(debugN + ' > check Attributes');
if (!objs[i].Attributes.alias) {
adapter.log.debug('check alias of ' + device + ' > not detected! set alias automatically in FHEM');
sendFHEM(fn, 'attr ' + device + ' alias ' + device);
}
for (const attr in objs[i].Attributes) {
// allowed Attributes?
if (allowedAttributes.indexOf(attr) === -1) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.warn(debugN + ' >> ' + attr + ' = ' + objs[i].Attributes[attr] + ' > no sync - not included in ' + adapter.namespace + '.info.Config.allowedAttributes');
continue;
}
const val = objs[i].Attributes[attr];
obj = {
_id: channel + '.' + 'Attributes.' + convertNameFHEM(fn, attr),
type: 'state',
common: {
name: alias + ' ' + attr,
type: 'string',
role: 'text',
read: true,
write: true
},
native: {
Name: device,
Attribute: attr,
Attributes: true
}
};
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.info(debugN + ' >> ' + attr + ' = ' + objs[i].Attributes[attr] + ' > ' + obj._id + ' = ' + val + ' | type: ' + obj.common.type + ' | read: ' + obj.common.read + ' | write: ' + obj.common.write + ' | role: ' + obj.common.role);
objects.push(obj);
states.push({
id: obj._id,
val: val,
ts: Date.now(),
ack: true
});
}
}
// Internals
if (objs[i].Internals) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.info(debugN + ' > check Internals');
for (const attr in objs[i].Internals) {
// allowed Internals?
if (!objs[i].Internals.hasOwnProperty(attr) || allowedInternals.indexOf(attr) === -1) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.warn(debugN + ' >> ' + attr + ' = ' + objs[i].Internals[attr] + ' > no sync - not included in ' + adapter.namespace + '.info.Config.allowedInternals');
continue;
}
const val = objs[i].Internals[attr];
obj = {
_id: channel + '.' + 'Internals.' + convertNameFHEM(fn, attr),
type: 'state',
common: {
name: alias + ' ' + attr,
type: 'string',
role: 'text',
read: true,
write: false
},
native: {
Name: device,
Attribute: attr,
Internals: true
}
};
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.info(debugN + ' >> ' + attr + ' = ' + objs[i].Internals[attr] + ' > ' + obj._id + ' = ' + val + ' | type: ' + obj.common.type + ' | read: ' + obj.common.read + ' | role: ' + obj.common.role);
objects.push(obj);
states.push({
id: obj._id,
val: val,
ts: Date.now(),
ack: true
});
}
}
// Possible Sets
if (objs[i].PossibleSets && objs[i].PossibleSets.length > 1) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.info(debugN + ' > check PossibleSets');
const attrs = objs[i].PossibleSets.split(' ');
for (let a = 0; a < attrs.length; a++) {
if (!attrs[a]) {
continue;
}
const parts = attrs[a].split(':');
let Cstates = true;
// ignore PossibleSets
if (ignorePossibleSets.indexOf(parts[0]) !== -1) {
(debugNAME.indexOf(device) !== -1 || debug) && adapter.log.warn(debugN + ' >> ' + parts[0] + ' > no sync - included in ' + adapter.namespace + '.info.Config.ignorePossibleSets');
continue;
}
const stateName = convertNameFHEM(fn, parts[0]); //KNX
if (parts[0] === 'off')
isOff = true;
if (parts[0] === 'on')
isOn = true;
obj = {
_id: channel + '.' + stateName,
type: 'state',
common: {
name: alias + ' ' + parts[0],
type: 'string',
role: 'state',
read: false,
write: true
},
native: {
Name: device,
Attribute: parts[0],
possibleSets: true
}
};
//special FS20
if (objs[i].Internals.TYPE === 'FS20' && !parts[1]) {