iobroker.zigbee2mqtt 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/io-package.json +14 -13
- package/lib/check.js +30 -30
- package/lib/colors.js +442 -443
- package/lib/deviceController.js +235 -232
- package/lib/exposes.js +867 -859
- package/lib/messages.js +31 -31
- package/lib/mqttServerController.js +30 -30
- package/lib/nonGenericDevicesExtension.js +47 -0
- package/lib/rgb.js +227 -203
- package/lib/states.js +6374 -6374
- package/lib/statesController.js +129 -129
- package/lib/utils.js +82 -82
- package/lib/websocketController.js +58 -58
- package/lib/z2mController.js +69 -64
- package/main.js +201 -201
- package/package.json +1 -1
package/lib/exposes.js
CHANGED
|
@@ -6,873 +6,881 @@ const statesDefs = require('./states').states;
|
|
|
6
6
|
const rgb = require('./rgb');
|
|
7
7
|
const utils = require('./utils');
|
|
8
8
|
const colors = require('./colors');
|
|
9
|
-
|
|
10
|
-
const blacklistSimulatedBrightness = ['MFKZQ01LM'];
|
|
9
|
+
const getNonGenDevStatesDefs = require('./nonGenericDevicesExtension').getStateDefinition;
|
|
11
10
|
|
|
12
11
|
function genState(expose, role, name, desc) {
|
|
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
|
-
|
|
12
|
+
let state;
|
|
13
|
+
const readable = true; //expose.access > 0;
|
|
14
|
+
const writable = expose.access > 1;
|
|
15
|
+
const stname = (name || expose.property);
|
|
16
|
+
|
|
17
|
+
if (typeof stname !== 'string') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const stateId = stname.replace(/\*/g, '');
|
|
22
|
+
const stateName = (desc || expose.description || expose.name);
|
|
23
|
+
const propName = expose.property;
|
|
24
|
+
|
|
25
|
+
switch (expose.type) {
|
|
26
|
+
case 'binary':
|
|
27
|
+
state = {
|
|
28
|
+
id: stateId,
|
|
29
|
+
prop: propName,
|
|
30
|
+
name: stateName,
|
|
31
|
+
icon: undefined,
|
|
32
|
+
role: role || 'state',
|
|
33
|
+
write: writable,
|
|
34
|
+
read: true,
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (readable) {
|
|
39
|
+
state.getter = (payload) => (payload[propName] === (expose.value_on || 'ON'));
|
|
40
|
+
} else {
|
|
41
|
+
state.getter = (_payload) => (undefined);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (writable) {
|
|
45
|
+
state.setter = (payload) => (payload) ? (expose.value_on || 'ON') : ((expose.value_off != undefined) ? expose.value_off : 'OFF');
|
|
46
|
+
state.setattr = expose.name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (expose.endpoint) {
|
|
50
|
+
state.epname = expose.endpoint;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case 'numeric':
|
|
56
|
+
state = {
|
|
57
|
+
id: stateId,
|
|
58
|
+
prop: propName,
|
|
59
|
+
name: stateName,
|
|
60
|
+
icon: undefined,
|
|
61
|
+
role: role || 'state',
|
|
62
|
+
write: writable,
|
|
63
|
+
read: true,
|
|
64
|
+
type: 'number',
|
|
65
|
+
min: expose.value_min || 0,
|
|
66
|
+
max: expose.value_max,
|
|
67
|
+
unit: expose.unit,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (expose.endpoint) {
|
|
71
|
+
state.epname = expose.endpoint;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 'enum':
|
|
76
|
+
state = {
|
|
77
|
+
id: stateId,
|
|
78
|
+
prop: propName,
|
|
79
|
+
name: stateName,
|
|
80
|
+
icon: undefined,
|
|
81
|
+
role: role || 'state',
|
|
82
|
+
write: writable,
|
|
83
|
+
read: true,
|
|
84
|
+
type: 'string',
|
|
85
|
+
states: {}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
for (const val of expose.values) {
|
|
89
|
+
state.states[val] = val;
|
|
90
|
+
state.type = typeof (val);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (expose.endpoint) {
|
|
94
|
+
state.epname = expose.endpoint;
|
|
95
|
+
state.setattr = expose.name;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
case 'text':
|
|
100
|
+
state = {
|
|
101
|
+
id: stateId,
|
|
102
|
+
prop: propName,
|
|
103
|
+
name: stateName,
|
|
104
|
+
icon: undefined,
|
|
105
|
+
role: role || 'state',
|
|
106
|
+
write: writable,
|
|
107
|
+
read: true,
|
|
108
|
+
type: 'string',
|
|
109
|
+
};
|
|
110
|
+
if (expose.endpoint) {
|
|
111
|
+
state.epname = expose.endpoint;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return state;
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
function createFromExposes(deviceID, ieee_address, definitions, power_source, scenes, config) {
|
|
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
|
-
|
|
123
|
+
const states = [];
|
|
124
|
+
// make the different (set and get) part of state is updatable if different exposes is used for get and set
|
|
125
|
+
// as example:
|
|
126
|
+
// ...
|
|
127
|
+
// exposes.binary('some_option', ea.STATE, true, false).withDescription('Some Option'),
|
|
128
|
+
// exposes.composite('options', 'options')
|
|
129
|
+
// .withDescription('Some composite Options')
|
|
130
|
+
// .withFeature(exposes.binary('some_option', ea.SET, true, false).withDescription('Some Option'))
|
|
131
|
+
//in this case one state - `some_option` has two different exposes for set an get, we have to combine it ...
|
|
132
|
+
|
|
133
|
+
function pushToStates(state, access) {
|
|
134
|
+
if (state === undefined) {
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
state.readable = true;
|
|
139
|
+
state.writable = access > 1;
|
|
140
|
+
const stateExists = states.findIndex((x, _index, _array) => (x.id === state.id));
|
|
141
|
+
|
|
142
|
+
if (stateExists < 0) {
|
|
143
|
+
state.write = state.writable;
|
|
144
|
+
if (!state.writable) {
|
|
145
|
+
if (state.hasOwnProperty('setter')) {
|
|
146
|
+
delete state.setter;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (state.hasOwnProperty('setattr')) {
|
|
150
|
+
delete state.setattr;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!state.readable) {
|
|
155
|
+
if (state.hasOwnProperty('getter')) {
|
|
156
|
+
//to awid some worning on unprocessed data
|
|
157
|
+
state.getter = _payload => (undefined);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return states.push(state);
|
|
162
|
+
} else {
|
|
163
|
+
|
|
164
|
+
if ((state.readable) && (!states[stateExists].readable)) {
|
|
165
|
+
states[stateExists].read = state.read;
|
|
166
|
+
// as state is readable, it can't be button or event
|
|
167
|
+
if (states[stateExists].role === 'button') {
|
|
168
|
+
states[stateExists].role = state.role;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (states[stateExists].hasOwnProperty('isEvent')) {
|
|
172
|
+
delete states[stateExists].isEvent;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// we have to use the getter from "new" state
|
|
176
|
+
if (state.hasOwnProperty('getter')) {
|
|
177
|
+
states[stateExists].getter = state.getter;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// trying to remove the `prop` property, as main key for get and set,
|
|
181
|
+
// as it can be different in new and old states, and leave only:
|
|
182
|
+
// setattr for old and id for new
|
|
183
|
+
if ((state.hasOwnProperty('prop')) && (state.prop === state.id)) {
|
|
184
|
+
if (states[stateExists].hasOwnProperty('prop')) {
|
|
185
|
+
if (states[stateExists].prop !== states[stateExists].id) {
|
|
186
|
+
if (!states[stateExists].hasOwnProperty('setattr')) {
|
|
187
|
+
states[stateExists].setattr = states[stateExists].prop;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
delete states[stateExists].prop;
|
|
191
|
+
}
|
|
192
|
+
} else if (state.hasOwnProperty('prop')) {
|
|
193
|
+
states[stateExists].prop = state.prop;
|
|
194
|
+
}
|
|
195
|
+
states[stateExists].readable = true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if ((state.writable) && (!states[stateExists].writable)) {
|
|
199
|
+
states[stateExists].write = state.writable;
|
|
200
|
+
// use new state `setter`
|
|
201
|
+
if (state.hasOwnProperty('setter')) {
|
|
202
|
+
states[stateExists].setter = state.setter;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// use new state `setterOpt`
|
|
206
|
+
if (state.hasOwnProperty('setterOpt')) {
|
|
207
|
+
states[stateExists].setterOpt = state.setterOpt;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// use new state `inOptions`
|
|
211
|
+
if (state.hasOwnProperty('inOptions')) {
|
|
212
|
+
states[stateExists].inOptions = state.inOptions;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// as we have new state, responsible for set, we have to use new `isOption`
|
|
216
|
+
// or remove it
|
|
217
|
+
if (((!state.hasOwnProperty('isOption')) || (state.isOptions === false)) && (states[stateExists].hasOwnProperty('isOption'))) {
|
|
218
|
+
delete states[stateExists].isOption;
|
|
219
|
+
} else {
|
|
220
|
+
states[stateExists].isOption = state.isOption;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// use new `setattr` or `prop` as `setattr`
|
|
224
|
+
if (state.hasOwnProperty('setattr')) {
|
|
225
|
+
states[stateExists].setattr = state.setattr;
|
|
226
|
+
} else if (state.hasOwnProperty('prop')) {
|
|
227
|
+
states[stateExists].setattr = state.prop;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// remove `prop` equal to if, due to prop is uses as key in set and get
|
|
231
|
+
if (states[stateExists].prop === states[stateExists].id) {
|
|
232
|
+
delete states[stateExists].prop;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (state.hasOwnProperty('epname')) {
|
|
236
|
+
states[stateExists].epname = state.epname;
|
|
237
|
+
}
|
|
238
|
+
states[stateExists].writable = true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return states.length;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
for (const expose of definitions.exposes) {
|
|
246
|
+
let state;
|
|
247
|
+
|
|
248
|
+
switch (expose.type) {
|
|
249
|
+
case 'light':
|
|
250
|
+
for (const prop of expose.features) {
|
|
251
|
+
switch (prop.name) {
|
|
252
|
+
case 'state': {
|
|
253
|
+
const stateNameS = expose.endpoint ? `state_${expose.endpoint}` : 'state';
|
|
254
|
+
pushToStates({
|
|
255
|
+
id: stateNameS,
|
|
256
|
+
name: `Switch state ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
257
|
+
icon: undefined,
|
|
258
|
+
role: 'switch',
|
|
259
|
+
write: true,
|
|
260
|
+
read: true,
|
|
261
|
+
type: 'boolean',
|
|
262
|
+
getter: (payload) => (payload[stateNameS] === (prop.value_on || 'ON')),
|
|
263
|
+
setter: (value) => (value) ? prop.value_on || 'ON' : ((prop.value_off != undefined) ? prop.value_off : 'OFF'),
|
|
264
|
+
epname: expose.endpoint,
|
|
265
|
+
setattr: 'state',
|
|
266
|
+
}, prop.access);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'brightness': {
|
|
270
|
+
const stateNameB = expose.endpoint ? `brightness_${expose.endpoint}` : 'brightness';
|
|
271
|
+
pushToStates({
|
|
272
|
+
id: stateNameB,
|
|
273
|
+
name: `Brightness ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
274
|
+
icon: undefined,
|
|
275
|
+
role: 'level.dimmer',
|
|
276
|
+
write: true,
|
|
277
|
+
read: true,
|
|
278
|
+
type: 'number',
|
|
279
|
+
min: 0, // ignore expose.value_min
|
|
280
|
+
max: 100, // ignore expose.value_max
|
|
281
|
+
inOptions: true,
|
|
282
|
+
unit: '%',
|
|
283
|
+
getter: (value) => {
|
|
284
|
+
return utils.bulbLevelToAdapterLevel(value[stateNameB]);
|
|
285
|
+
},
|
|
286
|
+
setter: (value) => {
|
|
287
|
+
return utils.adapterLevelToBulbLevel(value);
|
|
288
|
+
},
|
|
289
|
+
setterOpt: (value, options) => {
|
|
290
|
+
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
291
|
+
const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
292
|
+
const preparedOptions = { ...options, transition: transitionTime };
|
|
293
|
+
preparedOptions.brightness = utils.adapterLevelToBulbLevel(value);
|
|
294
|
+
return preparedOptions;
|
|
295
|
+
},
|
|
296
|
+
readResponse: (resp) => {
|
|
297
|
+
const respObj = resp[0];
|
|
298
|
+
if (respObj.status === 0 && respObj.attrData != undefined) {
|
|
299
|
+
return utils.bulbLevelToAdapterLevel(respObj.attrData);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
epname: expose.endpoint,
|
|
303
|
+
setattr: 'brightness',
|
|
304
|
+
}, prop.access);
|
|
305
|
+
pushToStates(statesDefs.brightness_move, prop.access);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case 'color_temp': {
|
|
309
|
+
const stateNameT = expose.endpoint ? `colortemp_${expose.endpoint}` : 'colortemp';
|
|
310
|
+
pushToStates({
|
|
311
|
+
id: stateNameT,
|
|
312
|
+
prop: expose.endpoint ? `color_temp_${expose.endpoint}` : 'color_temp',
|
|
313
|
+
name: `Color temperature ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
314
|
+
icon: undefined,
|
|
315
|
+
role: 'level.color.temperature',
|
|
316
|
+
write: true,
|
|
317
|
+
read: true,
|
|
318
|
+
type: 'number',
|
|
319
|
+
min: config.useKelvin == true ? utils.miredKelvinConversion(prop.value_max) : prop.value_min,
|
|
320
|
+
max: config.useKelvin == true ? utils.miredKelvinConversion(prop.value_min) : prop.value_max,
|
|
321
|
+
unit: config.useKelvin == true ? 'K' : 'mired',
|
|
322
|
+
setter: (value) => {
|
|
323
|
+
return utils.toMired(value);
|
|
324
|
+
},
|
|
325
|
+
// setterOpt: (_value, options) => {
|
|
326
|
+
// const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
327
|
+
// const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
328
|
+
// return { ...options, transition: transitionTime };
|
|
329
|
+
// },
|
|
330
|
+
getter: (payload) => {
|
|
331
|
+
if (payload.color_mode != 'color_temp') {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (config.useKelvin == true) {
|
|
335
|
+
return utils.miredKelvinConversion(payload.color_temp);
|
|
336
|
+
} else {
|
|
337
|
+
return payload.color_temp;
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
epname: expose.endpoint,
|
|
341
|
+
setattr: 'color_temp',
|
|
342
|
+
}, prop.access);
|
|
343
|
+
pushToStates(statesDefs.colortemp_move, prop.access);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case 'color_xy': {
|
|
347
|
+
const stateNameC = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
348
|
+
pushToStates({
|
|
349
|
+
id: stateNameC,
|
|
350
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
351
|
+
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
352
|
+
icon: undefined,
|
|
353
|
+
role: 'level.color.rgb',
|
|
354
|
+
write: true,
|
|
355
|
+
read: true,
|
|
356
|
+
type: 'string',
|
|
357
|
+
setter: (value) => {
|
|
358
|
+
|
|
359
|
+
let xy = [0, 0];
|
|
360
|
+
const rgbcolor = colors.ParseColor(value);
|
|
361
|
+
|
|
362
|
+
xy = rgb.rgb_to_cie(rgbcolor.r, rgbcolor.g, rgbcolor.b);
|
|
363
|
+
return {
|
|
364
|
+
x: xy[0],
|
|
365
|
+
y: xy[1]
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
},
|
|
369
|
+
getter: payload => {
|
|
370
|
+
if (payload.color_mode != 'xy' && config.colorTempSyncColor == false) {
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
if (payload.color && payload.color.hasOwnProperty('x') && payload.color.hasOwnProperty('y')) {
|
|
374
|
+
const colorval = rgb.cie_to_rgb(payload.color.x, payload.color.y);
|
|
375
|
+
return '#' + utils.decimalToHex(colorval[0]) + utils.decimalToHex(colorval[1]) + utils.decimalToHex(colorval[2]);
|
|
376
|
+
} else {
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
epname: expose.endpoint,
|
|
381
|
+
setattr: 'color',
|
|
382
|
+
}, 2);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case 'color_hs': {
|
|
386
|
+
const stateNameH = expose.endpoint ? `color_${expose.endpoint}` : 'color';
|
|
387
|
+
pushToStates({
|
|
388
|
+
id: stateNameH,
|
|
389
|
+
prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
390
|
+
name: `Color ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
391
|
+
icon: undefined,
|
|
392
|
+
role: 'level.color.rgb',
|
|
393
|
+
write: true,
|
|
394
|
+
read: true,
|
|
395
|
+
type: 'string',
|
|
396
|
+
setter: (value) => {
|
|
397
|
+
const _rgb = colors.ParseColor(value);
|
|
398
|
+
const hsv = rgb.rgbToHSV(_rgb.r, _rgb.g, _rgb.b, true);
|
|
399
|
+
return {
|
|
400
|
+
h: Math.min(Math.max(hsv.h, 1), 359),
|
|
401
|
+
s: hsv.s,
|
|
402
|
+
//b: Math.round(hsv.v * 2.55),
|
|
403
|
+
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
getter: payload => {
|
|
407
|
+
if (payload.color_mode != 'hs') {
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
if (payload.color && payload.color.hasOwnProperty('h') && payload.color.hasOwnProperty('s') & payload.color.hasOwnProperty('b')) {
|
|
411
|
+
return rgb.hsvToRGBString(payload.color.h, payload.color.s, Math.round(payload.color.b / 2.55));
|
|
412
|
+
} else {
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
epname: expose.endpoint,
|
|
417
|
+
setattr: 'color',
|
|
418
|
+
}, 2);
|
|
419
|
+
// pushToStates({
|
|
420
|
+
// id: expose.endpoint ? `hue_${expose.endpoint}` : 'hue',
|
|
421
|
+
// prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
422
|
+
// name: `Hue ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
423
|
+
// icon: undefined,
|
|
424
|
+
// role: 'level.color.hue',
|
|
425
|
+
// write: true,
|
|
426
|
+
// read: false,
|
|
427
|
+
// type: 'number',
|
|
428
|
+
// min: 0,
|
|
429
|
+
// max: 360,
|
|
430
|
+
// inOptions: true,
|
|
431
|
+
// setter: (value, options) => {
|
|
432
|
+
// return {
|
|
433
|
+
// hue: value,
|
|
434
|
+
// saturation: options.saturation,
|
|
435
|
+
// };
|
|
436
|
+
// },
|
|
437
|
+
// setterOpt: (_value, options) => {
|
|
438
|
+
// const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
439
|
+
// const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
440
|
+
// const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
441
|
+
// if (hasHueCalibrationTable)
|
|
442
|
+
// try {
|
|
443
|
+
// return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
|
|
444
|
+
// }
|
|
445
|
+
// catch (err) {
|
|
446
|
+
// const hue_correction_table = [];
|
|
447
|
+
// options.hue_calibration.split(',').forEach(element => {
|
|
448
|
+
// const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
449
|
+
// if (match && match.length == 3)
|
|
450
|
+
// hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
|
|
451
|
+
// });
|
|
452
|
+
// if (hue_correction_table.length > 0)
|
|
453
|
+
// return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
|
|
454
|
+
// }
|
|
455
|
+
// return { ...options, transition: transitionTime };
|
|
456
|
+
// },
|
|
457
|
+
|
|
458
|
+
// }, prop.access);
|
|
459
|
+
// pushToStates({
|
|
460
|
+
// id: expose.endpoint ? `saturation_${expose.endpoint}` : 'saturation',
|
|
461
|
+
// prop: expose.endpoint ? `color_${expose.endpoint}` : 'color',
|
|
462
|
+
// name: `Saturation ${expose.endpoint ? expose.endpoint : ''}`.trim(),
|
|
463
|
+
// icon: undefined,
|
|
464
|
+
// role: 'level.color.saturation',
|
|
465
|
+
// write: true,
|
|
466
|
+
// read: false,
|
|
467
|
+
// type: 'number',
|
|
468
|
+
// min: 0,
|
|
469
|
+
// max: 100,
|
|
470
|
+
// inOptions: true,
|
|
471
|
+
// setter: (value, options) => {
|
|
472
|
+
// return {
|
|
473
|
+
// hue: options.hue,
|
|
474
|
+
// saturation: value,
|
|
475
|
+
// };
|
|
476
|
+
// },
|
|
477
|
+
// setterOpt: (_value, options) => {
|
|
478
|
+
// const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
479
|
+
// const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
480
|
+
// const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
481
|
+
// if (hasHueCalibrationTable)
|
|
482
|
+
// try {
|
|
483
|
+
// return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
|
|
484
|
+
// }
|
|
485
|
+
// catch (err) {
|
|
486
|
+
// const hue_correction_table = [];
|
|
487
|
+
// options.hue_calibration.split(',').forEach(element => {
|
|
488
|
+
// const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
489
|
+
// if (match && match.length == 3)
|
|
490
|
+
// hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
|
|
491
|
+
// });
|
|
492
|
+
// if (hue_correction_table.length > 0)
|
|
493
|
+
// return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
|
|
494
|
+
// }
|
|
495
|
+
// return { ...options, transition: transitionTime };
|
|
496
|
+
// },
|
|
497
|
+
|
|
498
|
+
// }, 2);
|
|
499
|
+
// pushToStates(statesDefs.hue_move, 2);
|
|
500
|
+
// pushToStates(statesDefs.saturation_move, 2);
|
|
501
|
+
// pushToStates({
|
|
502
|
+
// id: 'hue_calibration',
|
|
503
|
+
// prop: 'color',
|
|
504
|
+
// name: 'Hue color calibration table',
|
|
505
|
+
// icon: undefined,
|
|
506
|
+
// role: 'table',
|
|
507
|
+
// write: true,
|
|
508
|
+
// read: false,
|
|
509
|
+
// type: 'string',
|
|
510
|
+
// inOptions: true,
|
|
511
|
+
// setter: (_value, options) => {
|
|
512
|
+
// return {
|
|
513
|
+
// hue: options.hue,
|
|
514
|
+
// saturation: options.saturation,
|
|
515
|
+
// };
|
|
516
|
+
// },
|
|
517
|
+
// setterOpt: (_value, options) => {
|
|
518
|
+
// const hasTransitionTime = options && options.hasOwnProperty('transition_time');
|
|
519
|
+
// const transitionTime = hasTransitionTime ? options.transition_time : 0;
|
|
520
|
+
// const hasHueCalibrationTable = options && options.hasOwnProperty('hue_calibration');
|
|
521
|
+
// if (hasHueCalibrationTable)
|
|
522
|
+
// try {
|
|
523
|
+
// return { ...options, transition: transitionTime, hue_correction: JSON.parse(options.hue_calibration) };
|
|
524
|
+
// }
|
|
525
|
+
// catch (err) {
|
|
526
|
+
// const hue_correction_table = [];
|
|
527
|
+
// options.hue_calibration.split(',').forEach(element => {
|
|
528
|
+
// const match = /([0-9]+):([0-9]+)/.exec(element);
|
|
529
|
+
// if (match && match.length == 3)
|
|
530
|
+
// hue_correction_table.push({ in: Number(match[1]), out: Number(match[2]) });
|
|
531
|
+
// });
|
|
532
|
+
// if (hue_correction_table.length > 0)
|
|
533
|
+
// return { ...options, transition: transitionTime, hue_correction: hue_correction_table };
|
|
534
|
+
// }
|
|
535
|
+
// return { ...options, transition: transitionTime };
|
|
536
|
+
// },
|
|
537
|
+
|
|
538
|
+
// }, prop.access);
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
default:
|
|
542
|
+
pushToStates(genState(prop), 2);
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
// First don't create a transition_time datapoint, this will be set in the backend
|
|
547
|
+
//pushToStates(statesDefs.transition_time, 2);
|
|
548
|
+
break;
|
|
549
|
+
|
|
550
|
+
case 'switch':
|
|
551
|
+
for (const prop of expose.features) {
|
|
552
|
+
switch (prop.name) {
|
|
553
|
+
case 'state':
|
|
554
|
+
pushToStates(genState(prop, 'switch'), prop.access);
|
|
555
|
+
break;
|
|
556
|
+
default:
|
|
557
|
+
pushToStates(genState(prop), prop.access);
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
break;
|
|
562
|
+
|
|
563
|
+
case 'numeric':
|
|
564
|
+
if (expose.endpoint) {
|
|
565
|
+
state = genState(expose);
|
|
566
|
+
} else {
|
|
567
|
+
switch (expose.name) {
|
|
568
|
+
case 'linkquality':
|
|
569
|
+
state = statesDefs.link_quality;
|
|
570
|
+
break;
|
|
571
|
+
|
|
572
|
+
case 'battery':
|
|
573
|
+
state = statesDefs.battery;
|
|
574
|
+
break;
|
|
575
|
+
|
|
576
|
+
case 'temperature':
|
|
577
|
+
state = statesDefs.temperature;
|
|
578
|
+
break;
|
|
579
|
+
|
|
580
|
+
case 'device_temperature':
|
|
581
|
+
state = statesDefs.device_temperature;
|
|
582
|
+
break;
|
|
583
|
+
|
|
584
|
+
case 'humidity':
|
|
585
|
+
state = statesDefs.humidity;
|
|
586
|
+
break;
|
|
587
|
+
|
|
588
|
+
case 'pressure':
|
|
589
|
+
state = statesDefs.pressure;
|
|
590
|
+
break;
|
|
591
|
+
|
|
592
|
+
case 'illuminance':
|
|
593
|
+
state = statesDefs.illuminance_raw;
|
|
594
|
+
break;
|
|
595
|
+
|
|
596
|
+
case 'illuminance_lux':
|
|
597
|
+
state = statesDefs.illuminance;
|
|
598
|
+
break;
|
|
599
|
+
|
|
600
|
+
case 'power':
|
|
601
|
+
state = statesDefs.load_power;
|
|
602
|
+
break;
|
|
603
|
+
|
|
604
|
+
case 'current':
|
|
605
|
+
state = statesDefs.load_current;
|
|
606
|
+
break;
|
|
607
|
+
|
|
608
|
+
case 'voltage':
|
|
609
|
+
state = statesDefs.voltage;
|
|
610
|
+
if (power_source == 'Battery') {
|
|
611
|
+
state = statesDefs.battery_voltage;
|
|
612
|
+
}
|
|
613
|
+
if (expose.unit == 'mV') {
|
|
614
|
+
state.getter = payload => payload.voltage / 1000;
|
|
615
|
+
}
|
|
616
|
+
break;
|
|
617
|
+
|
|
618
|
+
case 'energy':
|
|
619
|
+
state = statesDefs.energy;
|
|
620
|
+
break;
|
|
621
|
+
|
|
622
|
+
default:
|
|
623
|
+
state = genState(expose);
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (state) pushToStates(state, expose.access);
|
|
628
|
+
break;
|
|
629
|
+
|
|
630
|
+
case 'enum':
|
|
631
|
+
switch (expose.name) {
|
|
632
|
+
case 'action': {
|
|
633
|
+
|
|
634
|
+
// Ansatz:
|
|
635
|
+
|
|
636
|
+
// Action aufspalten in 2 Blöcke:
|
|
637
|
+
// Action (bekommt text ausser hold und release, auto reset nach 250 ms)
|
|
638
|
+
// Hold: wird gesetzt bei hold, gelöscht bei passendem Release
|
|
639
|
+
|
|
640
|
+
if (!Array.isArray(expose.values)) break;
|
|
641
|
+
const hasHold = expose.values.find((actionName) => actionName.includes('hold'));
|
|
642
|
+
const hasRelease = expose.values.find((actionName) => actionName.includes('release'));
|
|
643
|
+
for (const actionName of expose.values) {
|
|
644
|
+
// is release state ? - skip
|
|
645
|
+
if (hasHold && hasRelease && actionName.includes('release')) continue;
|
|
646
|
+
// is hold state ?
|
|
647
|
+
if (hasHold && hasRelease && actionName.includes('hold')) {
|
|
648
|
+
state = {
|
|
649
|
+
id: actionName.replace(/\*/g, ''),
|
|
650
|
+
prop: 'action',
|
|
651
|
+
name: actionName,
|
|
652
|
+
icon: undefined,
|
|
653
|
+
role: 'button',
|
|
654
|
+
write: false,
|
|
655
|
+
read: true,
|
|
656
|
+
def: false,
|
|
657
|
+
type: 'boolean',
|
|
658
|
+
getter: (payload) => {
|
|
659
|
+
if (payload.action === actionName) {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
if (payload.action === actionName.replace('hold', 'release')) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
if (payload.action === `${actionName}_release`) {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
return undefined;
|
|
669
|
+
},
|
|
670
|
+
};
|
|
671
|
+
} else {
|
|
672
|
+
state = {
|
|
673
|
+
id: actionName.replace(/\*/g, ''),
|
|
674
|
+
prop: 'action',
|
|
675
|
+
name: actionName,
|
|
676
|
+
icon: undefined,
|
|
677
|
+
role: 'button',
|
|
678
|
+
write: false,
|
|
679
|
+
read: true,
|
|
680
|
+
type: 'boolean',
|
|
681
|
+
def: false,
|
|
682
|
+
isEvent: true,
|
|
683
|
+
getter: payload => (payload.action === actionName) ? true : undefined,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
pushToStates(state, expose.access);
|
|
687
|
+
}
|
|
688
|
+
// Can the device simulated_brightness?
|
|
689
|
+
if (definitions.options && definitions.options.find(x => x.property == 'simulated_brightness')) {
|
|
690
|
+
pushToStates({
|
|
691
|
+
id: 'simulated_brightness',
|
|
692
|
+
prop: 'brightness',
|
|
693
|
+
name: 'Simulated brightness',
|
|
694
|
+
icon: undefined,
|
|
695
|
+
role: 'level.dimmer',
|
|
696
|
+
write: true,
|
|
697
|
+
read: true,
|
|
698
|
+
type: 'number',
|
|
699
|
+
unit: '%',
|
|
700
|
+
def: 0,
|
|
701
|
+
getter: payload => {
|
|
702
|
+
return utils.bulbLevelToAdapterLevel(payload.brightness);
|
|
703
|
+
},
|
|
704
|
+
}, 1);
|
|
705
|
+
}
|
|
706
|
+
state = null;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
default:
|
|
710
|
+
state = genState(expose);
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
if (state) pushToStates(state, expose.access);
|
|
714
|
+
break;
|
|
715
|
+
|
|
716
|
+
case 'binary':
|
|
717
|
+
if (expose.endpoint) {
|
|
718
|
+
state = genState(expose);
|
|
719
|
+
} else {
|
|
720
|
+
switch (expose.name) {
|
|
721
|
+
case 'contact':
|
|
722
|
+
state = statesDefs.contact;
|
|
723
|
+
pushToStates(statesDefs.opened, 1);
|
|
724
|
+
break;
|
|
725
|
+
|
|
726
|
+
case 'battery_low':
|
|
727
|
+
state = statesDefs.heiman_batt_low;
|
|
728
|
+
break;
|
|
729
|
+
|
|
730
|
+
case 'tamper':
|
|
731
|
+
state = statesDefs.tamper;
|
|
732
|
+
break;
|
|
733
|
+
|
|
734
|
+
case 'water_leak':
|
|
735
|
+
state = statesDefs.water_detected;
|
|
736
|
+
break;
|
|
737
|
+
|
|
738
|
+
case 'lock':
|
|
739
|
+
state = statesDefs.child_lock;
|
|
740
|
+
break;
|
|
741
|
+
|
|
742
|
+
case 'occupancy':
|
|
743
|
+
state = statesDefs.occupancy;
|
|
744
|
+
break;
|
|
745
|
+
|
|
746
|
+
default:
|
|
747
|
+
state = genState(expose);
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (state) pushToStates(state, expose.access);
|
|
752
|
+
break;
|
|
753
|
+
|
|
754
|
+
case 'text':
|
|
755
|
+
state = genState(expose);
|
|
756
|
+
pushToStates(state, expose.access);
|
|
757
|
+
break;
|
|
758
|
+
|
|
759
|
+
case 'lock':
|
|
760
|
+
case 'fan':
|
|
761
|
+
case 'cover':
|
|
762
|
+
for (const prop of expose.features) {
|
|
763
|
+
switch (prop.name) {
|
|
764
|
+
case 'state':
|
|
765
|
+
pushToStates(genState(prop, 'switch'), prop.access);
|
|
766
|
+
break;
|
|
767
|
+
default:
|
|
768
|
+
pushToStates(genState(prop), prop.access);
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
break;
|
|
773
|
+
|
|
774
|
+
case 'climate':
|
|
775
|
+
for (const prop of expose.features) {
|
|
776
|
+
switch (prop.name) {
|
|
777
|
+
case 'away_mode':
|
|
778
|
+
pushToStates(statesDefs.climate_away_mode, prop.access);
|
|
779
|
+
break;
|
|
780
|
+
case 'system_mode':
|
|
781
|
+
pushToStates(statesDefs.climate_system_mode, prop.access);
|
|
782
|
+
break;
|
|
783
|
+
case 'running_mode':
|
|
784
|
+
pushToStates(statesDefs.climate_running_mode, prop.access);
|
|
785
|
+
break;
|
|
786
|
+
default:
|
|
787
|
+
{
|
|
788
|
+
if (prop.name.includes('heating_setpoint')) {
|
|
789
|
+
pushToStates(genState(prop, 'level.temperature'), prop.access);
|
|
790
|
+
} else {
|
|
791
|
+
pushToStates(genState(prop), prop.access);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
break;
|
|
798
|
+
|
|
799
|
+
case 'composite':
|
|
800
|
+
for (const prop of expose.features) {
|
|
801
|
+
const st = genState(prop);
|
|
802
|
+
st.prop = expose.property;
|
|
803
|
+
st.inOptions = true;
|
|
804
|
+
// I'm not fully sure, as it really needed, but
|
|
805
|
+
st.setterOpt = (value, options) => {
|
|
806
|
+
const result = {};
|
|
807
|
+
options[prop.property] = value;
|
|
808
|
+
result[expose.property] = options;
|
|
809
|
+
return result;
|
|
810
|
+
};
|
|
811
|
+
// if we have a composite expose, the value have to be an object {expose.property : {prop.property: value}}
|
|
812
|
+
if (prop.access & 2) {
|
|
813
|
+
st.setter = (value, options) => {
|
|
814
|
+
const result = {};
|
|
815
|
+
options[prop.property] = value;
|
|
816
|
+
result[expose.property] = options;
|
|
817
|
+
return result;
|
|
818
|
+
};
|
|
819
|
+
st.setattr = expose.property;
|
|
820
|
+
}
|
|
821
|
+
// if we have a composite expose, the payload will be an object {expose.property : {prop.property: value}}
|
|
822
|
+
if (prop.access & 1) {
|
|
823
|
+
st.getter = payload => {
|
|
824
|
+
if ((payload.hasOwnProperty(expose.property)) && (payload[expose.property] !== null) && payload[expose.property].hasOwnProperty(prop.property)) {
|
|
825
|
+
return !isNaN(payload[expose.property][prop.property]) ? payload[expose.property][prop.property] : undefined;
|
|
826
|
+
} else {
|
|
827
|
+
return undefined;
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
} else {
|
|
831
|
+
st.getter = _payload => { return undefined; };
|
|
832
|
+
}
|
|
833
|
+
pushToStates(st, prop.access);
|
|
834
|
+
}
|
|
835
|
+
break;
|
|
836
|
+
default:
|
|
837
|
+
console.log(`Unhandled expose type ${expose.type} for device ${deviceID}`);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// If necessary, add states defined for this device model.
|
|
842
|
+
// Unfortunately this is necessary for some device models because they do not adhere to the standard
|
|
843
|
+
for (const state of getNonGenDevStatesDefs(definitions.model)) {
|
|
844
|
+
pushToStates(state, state.write ? 2 : 1);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// Add default states
|
|
848
|
+
pushToStates(statesDefs.available, 1);
|
|
849
|
+
|
|
850
|
+
const newDevice = {
|
|
851
|
+
id: deviceID,
|
|
852
|
+
ieee_address: ieee_address,
|
|
853
|
+
power_source: power_source,
|
|
854
|
+
states: states,
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// Create buttons for scenes
|
|
858
|
+
for (const scene of scenes) {
|
|
859
|
+
const sceneSate = {
|
|
860
|
+
id: `scene_${scene.id}`,
|
|
861
|
+
prop: `scene_recall`,
|
|
862
|
+
name: scene.name,
|
|
863
|
+
icon: undefined,
|
|
864
|
+
role: 'button',
|
|
865
|
+
write: true,
|
|
866
|
+
read: true,
|
|
867
|
+
type: 'boolean',
|
|
868
|
+
setter: (value) => (value) ? scene.id : undefined
|
|
869
|
+
};
|
|
870
|
+
// @ts-ignore
|
|
871
|
+
newDevice.states.push(sceneSate);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
return newDevice;
|
|
867
875
|
}
|
|
868
876
|
|
|
869
877
|
function defineDeviceFromExposes(devices, deviceID, ieee_address, definitions, power_source, scenes, config) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
878
|
+
if (definitions.hasOwnProperty('exposes')) {
|
|
879
|
+
const newDevice = createFromExposes(deviceID, ieee_address, definitions, power_source, scenes, config);
|
|
880
|
+
devices.push(newDevice);
|
|
881
|
+
}
|
|
874
882
|
}
|
|
875
883
|
|
|
876
884
|
module.exports = {
|
|
877
|
-
|
|
878
|
-
};
|
|
885
|
+
defineDeviceFromExposes: defineDeviceFromExposes,
|
|
886
|
+
};
|