-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-Homematic.js
686 lines (623 loc) · 26.4 KB
/
MMM-Homematic.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
/* global Module */
/* global Log */
/* global config */
/*
* Magic Mirror
* Module: MMM-Homematic
*
* By Sickboy78, spitzlbergerj
* GPL Licensed.
*/
Module.register('MMM-Homematic',{
// default module config
defaults: {
initialLoadDelay: 0,
updateInterval: 30,
animationSpeed: 1000,
tempUnit: '°C',
humUnit: '%',
shutterUnit: '%',
ampUnit: ' mA',
voltUnit: ' V',
pwrUnit: ' W',
energyUnit: ' Wh',
energyUnitK: ' kWh',
freqUnit: ' Hz',
locale: config.language,
ccuProtocol: 'http://',
ccuHost: 'ccu3-webui',
ccuXmlApiUrl: '/addons/xmlapi',
ccuXmlApiTokenId: '',
ccuStateServiceUrl: '/state.cgi',
ccuSysvarServiceUrl: '/sysvar.cgi',
ccuDatapointIdParameter: '?datapoint_id=',
ccuIseIdParameter: '?ise_id=',
style: 'lines',
useShortText: 'false',
showText: 'true',
showValue: 'true',
},
// start scheduler
start: function() {
Log.info('Starting module: ' + this.name);
this.scheduleUpdate(this.config.initialLoadDelay);
},
// get additional scripts
getScripts: function() {
return [
'https://code.jquery.com/jquery-1.12.4.min.js', // this file will be loaded from the jquery servers.
];
},
// get additional styles
getStyles: function() {
return [
'MMM-Homematic.css',
];
},
// return tranlation files
getTranslations: function() {
return {
en: 'translations/en.json',
de: 'translations/de.json'
};
},
// Override dom generator.
getDom: function() {
const _self = this;
// main wrapper
const wrapper = $('<div/>',{class: 'small'});
// add table class for style table_*
if(_self.config.style.startsWith('table')) {
wrapper.addClass('table');
if(_self.config.style === 'table_rows' || _self.config.style === 'single_line') {
wrapper.addClass('table-rows');
}
if(_self.config.style === 'table_columns') {
wrapper.addClass('table-columns');
}
}
// rows for style table_columns
const rowArray = [$('<div/>',{class: 'table-row'}),$('<div/>',{class: 'table-row'}),$('<div/>',{class: 'table-row'})];
if(typeof(_self.homematicData) !== 'undefined') {
if(typeof(this.config.datapoints) === 'object') {
// loop over datapoints
$.each(this.config.datapoints,function() {
// check name, id and type is set for datapoint
if(typeof(this.name) === 'string' && typeof(this.id) === 'string' && typeof(this.type) === 'string') {
// row or line for style lines and single_line and table_rows
const row = $('<div/>');
// row counter for style table_columns
let rowCounter = 0;
// raw value of datapoint
let value = _self.homematicData[_self.removeSpecialChars(this.name) + '_' + _self.removeSpecialChars(this.id)];
// text value of datapoint
let value_text = '';
// whether short or long text values are used
const use_short_text = _self.config.useShortText === 'true';
// css class for text
let text_class = '';
// css class for text with icon
let text_with_icon_class = '';
// css class for icon
let icon_class = '';
// default warn color for text and icon
let warn_color = 'red';
// default warn class for text
let warn_class = 'bright red';
// default color for icon
let icon_color = 'white';
// default icon size
let icon_size = 'medium';
// default icon position
let icon_position = 'left';
// icon dom element
let icon_element;
// add class table-row for style table_*
if(_self.config.style.startsWith('table')) {
row.addClass('table-row');
}
// add class single_line for style single_line
if(_self.config.style === 'single_line') {
row.addClass('single-line');
}
// ------------------------------------
// consider config values for datapoint
// ------------------------------------
// Introduction numberUnit
// @spitzlbergerj, 20190624
const numberUnit = typeof(this.numberUnit) === 'string' ? this.numberUnit : '';
// hide element is default when warnOnly is true
if((this.type.indexOf('warn') !== -1) && ((typeof(this.warnOnly) === 'string') && (this.warnOnly === 'true'))) {
text_class = 'hide';
}
// Setting warning color
// @spitzlbergerj, 20190127
if(typeof(this.warnColor) === 'string') {
warn_color = this.warnColor;
warn_class = 'bright ' + warn_color;
}
if(typeof(this.iconColor) === 'string') {
icon_color = this.iconColor;
}
// -----------------------------------------------------------
// read values from devices and sysvars and compose value text
// -----------------------------------------------------------
// devices
if(this.type.startsWith('window')) {
// window/door
// @spitzlberger: for HM-Sec-SCo added testing of Boolean value
if((value === '0') || (value === 'false')) {
value_text = _self.translateLoS('IS_CLOSED');
if(this.type === 'window_warn_closed') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_OPEN');
if(this.type === 'window_warn_open') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('temp')) {
// temperature sensor
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: 1, maximumFractionDigits: 1});
if(this.type.startsWith('temp_') && typeof(this.threshold) === 'number') {
if(this.type === 'temp_warn_high' && value >= this.threshold) {
value_text = _self.translateLoS('IS_TOO_HIGH') + (use_short_text ? '' : ' (' + valueStr + _self.config.tempUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else if(this.type === 'temp_warn_low' && value <= this.threshold) {
value_text = _self.translateLoS('IS_TOO_LOW') + (use_short_text ? '' : ' (' + valueStr + _self.config.tempUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else {
value_text = _self.translateLoS('IS_OK') + (use_short_text ? '' : ' (' + valueStr + _self.config.tempUnit + ')');
}
} else {
value_text = (use_short_text ? '' : _self.translateLoS('IS') + ' ') + valueStr + _self.config.tempUnit;
}
} else if(this.type.startsWith('hum')) {
// humidity sensor
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: 0, maximumFractionDigits: 0});
if(this.type.startsWith('hum_') && typeof(this.threshold) === 'number') {
if(this.type === 'hum_warn_high' && value >= this.threshold) {
value_text = _self.translateLoS('IS_TOO_HIGH') + (use_short_text ? '' : ' (' + valueStr + _self.config.humUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else if(this.type === 'hum_warn_low' && value <= this.threshold) {
value_text = _self.translateLoS('IS_TOO_LOW') + (use_short_text ? '' : ' (' + valueStr + _self.config.humUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else {
value_text = _self.translateLoS('IS_OK') + (use_short_text ? '' : ' (' + valueStr + _self.config.humUnit + ')');
}
} else {
value_text = (use_short_text ? '' : _self.translateLoS('IS') + ' ') + valueStr + _self.config.humUnit;
}
} else if(this.type.startsWith('shutter')) {
// shutter actuator
value = value*100;
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: 0, maximumFractionDigits: 0});
if(this.type.startsWith('shutter_') && typeof(this.threshold) === 'number') {
if(this.type === 'shutter_warn_high' && value >= this.threshold) {
value_text = _self.translateLoS('IS_TOO_HIGH') + (use_short_text ? '' : ' (' + valueStr + _self.config.shutterUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else if(this.type === 'shutter_warn_low' && value <= this.threshold) {
value_text = _self.translateLoS('IS_TOO_LOW') + (use_short_text ? '' : ' (' + valueStr + _self.config.shutterUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else {
value_text = _self.translateLoS('IS_OK') + (use_short_text ? '' : ' (' + valueStr + _self.config.shutterUnit + ')');
}
} else {
value_text = (use_short_text ? '' : _self.translateLoS('IS') + ' ') + valueStr + _self.config.shutterUnit;
}
// Switch and energie
// @spitzlbergerj, 20190206
} else if(this.type.startsWith('switch')) {
// switch actuator
if(value === 'false') {
value_text = _self.translateLoS('IS_OFF');
if(this.type === 'switch_warn_off') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_ON');
if(this.type === 'switch_warn_on') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('energie')) {
// switch actuator with power metering
let valueUnit = '';
let precision = 0;
if(typeof(this.precision) === 'number') {
precision = this.precision;
}
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: precision, maximumFractionDigits: precision});
if (this.type.startsWith('energie_a')) {
valueUnit = _self.config.ampUnit;
} else if (this.type.startsWith('energie_v')) {
valueUnit = _self.config.voltUnit;
} else if (this.type.startsWith('energie_p')) {
valueUnit = _self.config.pwrUnit;
} else if (this.type.startsWith('energie_ek')) {
valueUnit = _self.config.energyUnitK;
} else if (this.type.startsWith('energie_e')) {
valueUnit = _self.config.energyUnit;
} else if (this.type.startsWith('energie_f')) {
valueUnit = _self.config.freqUnit;
}
if( ( this.type.endsWith('_high') || this.type.endsWith('_low') ) && typeof(this.threshold) === 'number') {
if(this.type.endsWith('_high') && value >= this.threshold) {
value_text = _self.translateLoS('IS_TOO_HIGH') + (use_short_text ? '' : ' (' + valueStr + valueUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else if(this.type.endsWith('_low') && value <= this.threshold) {
value_text = _self.translateLoS('IS_TOO_LOW') + (use_short_text ? '' : ' (' + valueStr + valueUnit + ')');
text_class = warn_class;
icon_color = warn_color;
} else {
value_text = valueStr + valueUnit;
}
} else {
value_text = valueStr + valueUnit;
}
} else if(this.type.startsWith('other')) {
// other sensor/actuator
let precision = 0;
if(typeof(this.precision) === 'number') {
precision = this.precision;
}
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: precision, maximumFractionDigits: precision});
if(this.type.startsWith('other_') && typeof(this.threshold) === 'number') {
if(this.type === 'other_warn_high' && value >= this.threshold) {
value_text = _self.translateLoS('IS_TOO_HIGH') + (use_short_text ? '' : ' (' + valueStr + ')');
text_class = warn_class;
icon_color = warn_color;
} else if(this.type === 'other_warn_low' && value <= this.threshold) {
value_text = _self.translateLoS('IS_TOO_LOW') + (use_short_text ? '' : ' (' + valueStr + ')');
text_class = warn_class;
icon_color = warn_color;
} else {
value_text = _self.translateLoS('IS_OK') + (use_short_text ? '' : ' (' + valueStr + ')');
}
} else {
// Introduction numberUnit
// @spitzlbergerj, 20190624
value_text = (use_short_text ? '' : _self.translateLoS('IS') + ' ') + valueStr + ' ' + numberUnit;
}
}
// sysvars
// @spitzlbergerj, 20190127
else if(this.type.startsWith('sysvar_boolean')) {
// SysVar boolean
if(value === 'false') {
value_text = _self.translateLoS('IS_FALSE');
if(this.type === 'sysvar_boolean_warn_false') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_TRUE');
if(this.type === 'sysvar_boolean_warn_true') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('sysvar_alarm')) {
// SysVar alarm
if(value === 'false') {
value_text = _self.translateLoS('IS_NOT_TRIGGERED');
if(this.type === 'sysvar_alarm_warn_not_triggered') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_TRIGGERED');
if(this.type === 'sysvar_alarm_warn_triggered') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('sysvar_mashine')) {
// SysVar Boolean; Special type machine that can run or not run
if(value === 'false') {
value_text = _self.translateLoS('IS_NOT_RUNNING');
if(this.type === 'sysvar_mashine_warn_not_running') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_RUNNING');
if(this.type === 'sysvar_mashine_warn_running') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('sysvar_presence')) {
// SysVar boolean, special type presence that can accept the values here or not here
if(value === 'false') {
value_text = _self.translateLoS('IS_AWAY');
if(this.type === 'sysvar_presence_warn_away') {
text_class = warn_class;
icon_color = warn_color;
}
} else {
value_text = _self.translateLoS('IS_HERE');
if(this.type === 'sysvar_presence_warn_here') {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('sysvar_string')) {
// SysVar String Value
value_text = value;
if(this.type === 'sysvar_string_warn_empty' && (value === '' || value === '???')) {
text_class = warn_class;
icon_color = warn_color;
} else if (this.type === 'sysvar_string_warn_not_empty' && (value !== '' && value !== '???')) {
text_class = warn_class;
icon_color = warn_color;
}
} else if(this.type.startsWith('sysvar_valuelist')) {
// SysVar value list
value_text = _self.translateLoS('IS') + ' ' + value;
if(this.type.startsWith('sysvar_valuelist_') && typeof(this.reference) !== 'undefined') {
if(this.type === 'sysvar_valuelist_warn_equals' && (value === this.reference)) {
text_class = warn_class;
icon_color = warn_color;
} else if (this.type === 'sysvar_valuelist_warn_not_equals' && (value !== this.reference)) {
text_class = warn_class;
icon_color = warn_color;
}
}
} else if(this.type.startsWith('sysvar_number')) {
// SysVar number
let precision = 0;
if(typeof(this.precision) === 'number') {
precision = this.precision;
}
const valueStr = Number(value).toLocaleString(_self.config.locale, {minimumFractionDigits: precision, maximumFractionDigits: precision});
if(this.type.startsWith('sysvar_number_') && typeof(this.threshold) === 'number') {
if(this.type === 'sysvar_number_warn_high' && value >= this.threshold) {
text_class = warn_class;
icon_color = warn_color;
} else if(this.type === 'sysvar_number_warn_low' && value <= this.threshold) {
text_class = warn_class;
icon_color = warn_color;
}
}
// Introduction numberUnit
// @spitzlbergerj, 20190624
value_text = valueStr + ' ' + numberUnit;
}
// ------------
// compose icon
// ------------
if((typeof(this.iconPosition) === 'string')) {
icon_position = this.iconPosition;
}
if(typeof(this.icon) === 'string') {
// show icon
let icon_url;
if((typeof(this.iconSize) === 'string')) {
icon_size = this.iconSize;
}
icon_class = ' icon icon-' + icon_size + ' icon-' + icon_position + ' icon-' + icon_color;
if(icon_position !== 'center' || _self.config.style.startsWith('table')) {
text_with_icon_class = ' text-with-icon text-with-icon-' + icon_size;
}
if(this.icon.startsWith('fa-')){
icon_element = $('<i/>',{id: _self.identifier + '-' + _self.removeSpecialChars(this.name) + '-icon',class: text_class + icon_class + ' fa fa-fw ' + this.icon});
}
else
{
if(this.icon.startsWith('default_')){
// integrated icon
icon_url = _self.data.path + 'icons/' + this.icon.substr(8) + '.png';
} else {
// external icon url
icon_url = this.icon;
}
icon_element = $('<div/>',{id: _self.identifier + '-' + _self.removeSpecialChars(this.name) + '-icon',class: text_class + icon_class,style: 'background-image: url(' + icon_url + ');'});
}
if(_self.config.style.startsWith('table')) {
icon_element = $('<div/>').append(icon_element);
icon_element.addClass(text_class + ' table-cell align-top');
if(this.icon.startsWith('fa-')){
//icon_element.addClass("align-top");
}
}
} else {
icon_element = $('<div/>',{id: _self.identifier + '-' + _self.removeSpecialChars(this.name) + '-icon',class: text_class});
if(_self.config.style.startsWith('table')) {
icon_element.addClass('table-cell');
}
}
// ---------------------------------
// combine icon, name and value text
// ---------------------------------
// icon left/top or center for style lines
if(icon_position === 'left' || icon_position === 'top') {
if(_self.config.style === 'lines' && typeof(this.icon) === 'string') {
row.append(icon_element);
}
if(_self.config.style === 'table_rows' || _self.config.style === 'single_line') {
row.append(icon_element);
}
if(_self.config.style === 'table_columns') {
rowArray[rowCounter++].append(icon_element);
}
}
if(icon_position === 'center') {
if(_self.config.style === 'lines' && typeof(this.icon) === 'string') {
row.append(icon_element);
row.append($('<br/>',{class: text_class}));
}
}
// text
if(_self.config.showText === 'true') {
const textHtml = $('<div/>',{id: _self.identifier + '-' + _self.removeSpecialChars(this.name) + '-text'});
if((typeof(this.iconOnly) !== 'string') || (this.iconOnly !== 'true')) {
textHtml.addClass(text_class + text_with_icon_class + ' text-lines');
if(this.replaceNameWithDatapointId != undefined && typeof(this.replaceNameWithDatapointId) === 'string' && _self.homematicData[_self.removeSpecialChars(this.name) + '_' + _self.removeSpecialChars(this.replaceNameWithDatapointId)] != undefined) {
textHtml.html(_self.homematicData[_self.removeSpecialChars(this.name) + '_' + _self.removeSpecialChars(this.replaceNameWithDatapointId)]);
} else {
textHtml.html(this.name);
}
if(_self.config.style.startsWith('table')) {
textHtml.addClass('table-cell');
}
} else {
if(_self.config.style.startsWith('table')) {
textHtml.addClass('table-cell');
}
}
if(_self.config.style === 'table_columns') {
rowArray[rowCounter++].append(textHtml);
} else {
row.append(textHtml);
}
}
// icon center for styles table_*
if(icon_position === 'center'){
if(_self.config.style === 'table_columns') {
rowArray[rowCounter++].append(icon_element);
} else if(_self.config.style === 'table_rows' || _self.config.style === 'single_line') {
row.append(icon_element);
}
}
// value
if(_self.config.showValue === 'true') {
const valueHtml = $('<div/>',{id: _self.identifier + '-' + _self.removeSpecialChars(this.name) + '-value'});
if((typeof(this.iconOnly) !== 'string') || (this.iconOnly !== 'true')) {
valueHtml.addClass(text_class + text_with_icon_class + ' text-lines');
valueHtml.html(' ' + value_text);
if(_self.config.style.startsWith('table')) {
valueHtml.addClass('table-cell');
}
} else {
if(_self.config.style.startsWith('table')) {
valueHtml.addClass('table-cell');
}
}
if(_self.config.style === 'table_columns') {
rowArray[rowCounter++].append(valueHtml);
} else {
row.append(valueHtml);
}
}
// icon right/bottom
if(icon_position === 'right' || icon_position === 'bottom') {
if((_self.config.style === 'lines' && typeof(this.icon) === 'string') || _self.config.style === 'table_rows' || _self.config.style === 'single_line') {
row.append(icon_element);
}
if(_self.config.style === 'table_columns') {
rowArray[rowCounter++].append(icon_element);
}
}
// output for style lines and single_line and table_rows
if(_self.config.style !== 'table_columns') {
wrapper.append(row);
}
}
}); // end of loop over datapoints
// output for style table_columns
if(_self.config.style === 'table_columns') {
wrapper.append(rowArray);
}
}
} else {
// loading screen
const textHtml = $('<div/>',{id: _self.identifier + '-loading'});
textHtml.html('Loading ...');
wrapper.append(textHtml);
}
return wrapper[0];
},
// notification recieved
socketNotificationReceived: function (notification, payload) {
const _self = this;
this.debug = '';
if (notification === 'HOMEMATIC_DATA_RECIEVED') {
// make sure notification is intended for this isntance
let containsAllConfigDatapoints = false;
if(typeof(payload) === 'object' && typeof(this.config.datapoints) === 'object' && this.config.datapoints.length > 0) {
containsAllConfigDatapoints = true;
this.config.datapoints.forEach(function(datapoint){
let containsConfigDatapoint = false;
payload.forEach(function(data){
if((data.type === 'datapoint' || data.type === 'sysvar') && data.datapoint.name == datapoint.name && data.datapoint.id == datapoint.id) {
containsConfigDatapoint = true;
}
});
if(datapoint.replaceNameWithDatapointId != undefined && typeof(datapoint.replaceNameWithDatapointId) === 'string') {
let containsConfigReplaceDatapoint = false;
payload.forEach(function(data){
if(data.type === 'datapoint_replace_name' && data.datapoint.name == datapoint.name && data.datapoint.id == datapoint.id && data.datapoint.replaceNameWithDatapointId == datapoint.replaceNameWithDatapointId) {
containsConfigReplaceDatapoint = true;
}
});
containsConfigDatapoint = containsConfigReplaceDatapoint && containsConfigDatapoint;
}
containsAllConfigDatapoints = containsConfigDatapoint && containsAllConfigDatapoints;
});
}
if(containsAllConfigDatapoints) {
if(typeof(this.homematicData) === 'undefined') {
this.homematicData = [];
}
try {
payload.forEach(function(data){
const xmlData = $.parseXML(data.value);
let value = xmlData.childNodes[0].childNodes[0].attributes.value.value;
if(data.type.startsWith('sysvar')) {
value = xmlData.childNodes[0].childNodes[0].attributes.value_list.value.split(';')[value];
}
if(data.type === 'datapoint' || data.type === 'sysvar') {
_self.homematicData[_self.removeSpecialChars(data.datapoint.name) + '_' + _self.removeSpecialChars(data.datapoint.id)] = value;
_self.debug = _self.debug + _self.removeSpecialChars(data.datapoint.name) + '_' + _self.removeSpecialChars(data.datapoint.id) + '-';
} else if(data.type === 'datapoint_replace_name') {
_self.homematicData[_self.removeSpecialChars(data.datapoint.name) + '_' + _self.removeSpecialChars(data.datapoint.replaceNameWithDatapointId)] = value;
_self.debug = _self.debug + _self.removeSpecialChars(data.datapoint.name) + '_' + _self.removeSpecialChars(data.datapoint.replaceNameWithDatapointId) + '-';
}
});
if (this.config.debug) {
console.log('[' + new Date().toLocaleString() + '] Info: homematic data recieved for: ' + this.debug);
}
this.updateDom(this.config.animationSpeed);
} catch(err) {
console.log('[' + new Date().toLocaleString() + '] Error: Could not parse recieved data because: ' + err);
}
}
}
},
// schedules next update
scheduleUpdate: function(delay) {
const _self = this;
const nextLoad = (delay != undefined && delay >= 0) ? delay : this.config.updateInterval;
setTimeout(function() {
const payload = {};
payload.config = _self.config;
if (_self.config.debug) {
console.log('[' + new Date().toLocaleString() + '] Info: sending homematic data request.');
}
_self.sendSocketNotification('GET_HOMEMATIC_DATA', payload);
_self.scheduleUpdate();
}, nextLoad * 1000);
},
// removes special chars and whitespaces
removeSpecialChars: function(text) {
return text.replace(/[^\w]/gi, '');
},
// translate long or short version depending on config
translateLoS: function(text) {
const _self = this;
return _self.translate(text + (_self.config.useShortText === 'true' ? '_SHORT': ''));
},
});