forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_web_plugin.cpp
19356 lines (17189 loc) · 754 KB
/
de_web_plugin.cpp
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
/*
* Copyright (c) 2017-2020 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#include <QCoreApplication>
#include <QDebug>
#include <QDesktopServices>
#include <QtPlugin>
#include <QtCore/qmath.h>
#include <QNetworkAccessManager>
#include <QPushButton>
#include <QTextCodec>
#include <QTime>
#include <QTimer>
#include <QTcpSocket>
#include <QHostAddress>
#include <QUrl>
#include <QCryptographicHash>
#include <QFile>
#include <QDir>
#include <QProcess>
#include <QSettings>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonParseError>
#include <queue>
#include <cmath>
#include "colorspace.h"
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
#include "de_web_widget.h"
#include "gateway_scanner.h"
#include "json.h"
#include "poll_control.h"
#include "poll_manager.h"
#include "rest_devices.h"
#include "read_files.h"
#ifdef ARCH_ARM
#include <unistd.h>
#include <sys/reboot.h>
#include <errno.h>
#endif
DeRestPluginPrivate *plugin;
const char *HttpStatusOk = "200 OK"; // OK
const char *HttpStatusAccepted = "202 Accepted"; // Accepted but not complete
const char *HttpStatusNotModified = "304 Not Modified"; // For ETag / If-None-Match
const char *HttpStatusBadRequest = "400 Bad Request"; // Malformed request
const char *HttpStatusUnauthorized = "401 Unauthorized"; // Unauthorized
const char *HttpStatusForbidden = "403 Forbidden"; // Understand request but no permission
const char *HttpStatusNotFound = "404 Not Found"; // Requested uri not found
const char *HttpStatusServiceUnavailable = "503 Service Unavailable";
const char *HttpStatusNotImplemented = "501 Not Implemented";
const char *HttpContentHtml = "text/html; charset=utf-8";
const char *HttpContentCss = "text/css";
const char *HttpContentJson = "application/json; charset=utf-8";
const char *HttpContentJS = "text/javascript";
const char *HttpContentPNG = "image/png";
const char *HttpContentJPG = "image/jpg";
const char *HttpContentSVG = "image/svg+xml";
static int checkZclAttributesDelay = 750;
static uint MaxGroupTasks = 4;
const quint64 macPrefixMask = 0xffffff0000000000ULL;
// New mac prefixes can be checked here: https://wintelguy.com/index.pl
const quint64 legrandMacPrefix = 0x0004740000000000ULL;
const quint64 dishMacPrefix = 0x0008890000000000ULL;
const quint64 ikeaMacPrefix = 0x000b570000000000ULL;
const quint64 emberMacPrefix = 0x000d6f0000000000ULL;
const quint64 instaMacPrefix = 0x000f170000000000ULL;
const quint64 tiMacPrefix = 0x00124b0000000000ULL;
const quint64 netvoxMacPrefix = 0x00137a0000000000ULL;
const quint64 boschMacPrefix = 0x00155f0000000000ULL;
const quint64 jennicMacPrefix = 0x00158d0000000000ULL;
const quint64 develcoMacPrefix = 0x0015bc0000000000ULL;
const quint64 philipsMacPrefix = 0x0017880000000000ULL;
const quint64 celMacPrefix = 0x0022a30000000000ULL; // California Eastern Laboratories
const quint64 computimeMacPrefix = 0x001e5e0000000000ULL;
const quint64 ubisysMacPrefix = 0x001fee0000000000ULL;
const quint64 deMacPrefix = 0x00212e0000000000ULL;
const quint64 keenhomeMacPrefix = 0x0022a30000000000ULL;
const quint64 zenMacPrefix = 0x0024460000000000ULL;
const quint64 heimanMacPrefix = 0x0050430000000000ULL;
const quint64 davicomMacPrefix = 0x00606e0000000000ULL;
const quint64 xiaomiMacPrefix = 0x04cf8c0000000000ULL;
const quint64 konkeMacPrefix = 0x086bd70000000000ULL;
const quint64 ikea2MacPrefix = 0x14b4570000000000ULL;
const quint64 profaluxMacPrefix = 0x20918a0000000000ULL;
const quint64 stMacPrefix = 0x24fd5b0000000000ULL;
const quint64 samjinMacPrefix = 0x286d970000000000ULL;
const quint64 sinopeMacPrefix = 0x500b910000000000ULL;
const quint64 silabs9MacPrefix = 0x5c02720000000000ULL;
const quint64 silabs6MacPrefix = 0x588e810000000000ULL;
const quint64 silabs8MacPrefix = 0x60a4230000000000ULL;
const quint64 silabs4MacPrefix = 0x680ae20000000000ULL;
const quint64 ecozyMacPrefix = 0x70b3d50000000000ULL;
const quint64 osramMacPrefix = 0x8418260000000000ULL;
const quint64 silabs5MacPrefix = 0x842e140000000000ULL;
const quint64 embertecMacPrefix = 0x848e960000000000ULL;
const quint64 silabsMacPrefix = 0x90fd9f0000000000ULL;
const quint64 zhejiangMacPrefix = 0xb0ce180000000000ULL;
const quint64 silabs7MacPrefix = 0xbc33ac0000000000ULL;
const quint64 silabs2MacPrefix = 0xcccccc0000000000ULL;
const quint64 silabs3MacPrefix = 0xec1bbd0000000000ULL;
const quint64 energyMiMacPrefix = 0xd0cf5e0000000000ULL;
const quint64 bjeMacPrefix = 0xd85def0000000000ULL;
const quint64 xalMacPrefix = 0xf8f0050000000000ULL;
const quint64 lutronMacPrefix = 0xffff000000000000ULL;
// Danalock support
const quint64 danalockMacPrefix = 0x000b570000000000ULL; // note: same as ikeaMacPrefix
const quint64 schlageMacPrefix = 0xd0cf5e0000000000ULL;
struct SupportedDevice {
quint16 vendorId;
const char *modelId;
quint64 mac;
};
static const SupportedDevice supportedDevices[] = {
{ VENDOR_3A_SMART_HOME, "FNB56-GAS", jennicMacPrefix }, // Feibit FNB56-GAS05FB1.4 gas leak detector
{ VENDOR_3A_SMART_HOME, "FNB56-COS", jennicMacPrefix }, // Feibit FNB56-COS06FB1.7 Carb. Mon. detector
{ VENDOR_3A_SMART_HOME, "FNB56-SMF", jennicMacPrefix }, // Feibit FNB56-SMF06FB1.6 smoke detector
{ VENDOR_BUSCH_JAEGER, "RB01", bjeMacPrefix },
{ VENDOR_BUSCH_JAEGER, "RM01", bjeMacPrefix },
{ VENDOR_BOSCH, "ISW-ZDL1-WP11G", boschMacPrefix },
{ VENDOR_BOSCH, "ISW-ZPR1-WP13", boschMacPrefix },
{ VENDOR_BOSCH, "RFDL-ZB-MS", emberMacPrefix }, // Bosch motion sensor
{ VENDOR_BOSCH2, "AIR", tiMacPrefix }, // Bosch Air quality sensor
{ VENDOR_CENTRALITE, "Motion Sensor-A", emberMacPrefix },
{ VENDOR_CENTRALITE, "3321-S", emberMacPrefix }, // Centralite multipurpose sensor
{ VENDOR_CENTRALITE, "3325-S", emberMacPrefix }, // Centralite motion sensor
{ VENDOR_CENTRALITE, "3305-S", emberMacPrefix }, // Centralite motion sensor
{ VENDOR_CLS, "3200-S", emberMacPrefix }, // Centralite smart plug / Samsung smart outlet
{ VENDOR_C2DF, "3300", emberMacPrefix }, // Centralite contact sensor
{ VENDOR_C2DF, "3320-L", emberMacPrefix }, // Centralite contact sensor
{ VENDOR_C2DF, "3315", emberMacPrefix }, // Centralite water sensor
{ VENDOR_CENTRALITE, "3326-L", emberMacPrefix }, // Iris motion sensor v2
{ VENDOR_C2DF, "3326-L", emberMacPrefix }, // Iris motion sensor v2
{ VENDOR_CENTRALITE, "3328-G", emberMacPrefix }, // Centralite micro motion sensor
{ VENDOR_CENTRALITE, "3323", emberMacPrefix }, // Centralite contact sensor
{ VENDOR_DDEL, "de_spect", silabs3MacPrefix }, // dresden elektronic spectral sensor
{ VENDOR_JASCO, "45856", celMacPrefix },
{ VENDOR_NONE, "LM_", tiMacPrefix },
{ VENDOR_NONE, "LMHT_", tiMacPrefix },
{ VENDOR_NONE, "IR_", tiMacPrefix },
{ VENDOR_NONE, "DC_", tiMacPrefix },
{ VENDOR_NONE, "BX_", tiMacPrefix }, // Climax siren
{ VENDOR_NONE, "PSMD_", tiMacPrefix }, // Climax smart plug
{ VENDOR_NONE, "PSMP5_", tiMacPrefix }, // Climax smart plug
{ VENDOR_NONE, "PCM_", tiMacPrefix }, // Climax power meter
{ VENDOR_NONE, "OJB-IR715-Z", tiMacPrefix },
{ VENDOR_NONE, "902010/21", tiMacPrefix }, // Bitron: door/window sensor
{ VENDOR_NONE, "902010/22", tiMacPrefix }, // Bitron: motion sensor
{ VENDOR_NONE, "902010/23", tiMacPrefix }, // Bitron: remote control
{ VENDOR_NONE, "902010/24", tiMacPrefix }, // Bitron: smoke detector
{ VENDOR_NONE, "902010/25", tiMacPrefix }, // Bitron: smart plug
{ VENDOR_NONE, "902010/29", tiMacPrefix }, // Bitron: Outdoor siren
{ VENDOR_NONE, "SPW35Z", tiMacPrefix }, // RT-RK OBLO SPW35ZD0 smart plug
{ VENDOR_BITRON, "902010/32", emberMacPrefix }, // Bitron: thermostat
{ VENDOR_DDEL, "Lighting Switch", deMacPrefix },
{ VENDOR_DDEL, "Scene Switch", deMacPrefix },
{ VENDOR_DDEL, "FLS-NB1", deMacPrefix },
{ VENDOR_DDEL, "FLS-NB2", deMacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", ikeaMacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", silabsMacPrefix },
{ VENDOR_IKEA, "TRADFRI remote control", silabs2MacPrefix },
{ VENDOR_IKEA, "TRADFRI motion sensor", ikeaMacPrefix },
{ VENDOR_IKEA, "TRADFRI wireless dimmer", ikeaMacPrefix },
{ VENDOR_IKEA, "TRADFRI on/off switch", ikeaMacPrefix },
{ VENDOR_IKEA, "TRADFRI SHORTCUT Button", silabs4MacPrefix },
{ VENDOR_IKEA, "TRADFRI open/close remote", ikeaMacPrefix },
{ VENDOR_IKEA, "FYRTUR", ikeaMacPrefix }, // smart blind
{ VENDOR_IKEA, "KADRILJ", ikeaMacPrefix }, // smart blind
{ VENDOR_IKEA, "KADRILJ", silabs4MacPrefix }, // smart blind
{ VENDOR_IKEA, "SYMFONISK", ikea2MacPrefix }, // sound controller
{ VENDOR_INSTA, "Remote", instaMacPrefix },
{ VENDOR_INSTA, "HS_4f_GJ_1", instaMacPrefix },
{ VENDOR_INSTA, "WS_4f_J_1", instaMacPrefix },
{ VENDOR_INSTA, "WS_3f_G_1", instaMacPrefix },
{ VENDOR_AXIS, "Gear", zenMacPrefix },
{ VENDOR_MMB, "Gear", zenMacPrefix },
{ VENDOR_NYCE, "3011", emberMacPrefix }, // NYCE door/window sensor
{ VENDOR_NYCE, "3014", emberMacPrefix }, // NYCE garage door/tilt sensor
{ VENDOR_NYCE, "3043", emberMacPrefix }, // NYCE ceiling motion sensor
{ VENDOR_PHILIPS, "RWL02", philipsMacPrefix }, // Hue dimmer switch
{ VENDOR_PHILIPS, "ROM00", philipsMacPrefix }, // Hue smart button
{ VENDOR_PHILIPS, "SML00", philipsMacPrefix }, // Hue motion sensor
{ VENDOR_PHYSICAL, "tagv4", stMacPrefix}, // SmartThings Arrival sensor
{ VENDOR_PHYSICAL, "motionv4", stMacPrefix}, // SmartThings motion sensor
{ VENDOR_PHYSICAL, "moisturev4", stMacPrefix}, // SmartThings water leak sensor
{ VENDOR_PHYSICAL, "multiv4", stMacPrefix}, // SmartThings multi sensor 2016
{ VENDOR_SAMJIN, "motion", samjinMacPrefix }, // Smarthings GP-U999SJVLBAA (Samjin) Motion Sensor
{ VENDOR_SAMJIN, "multi", samjinMacPrefix }, // Smarthings (Samjin) Multipurpose Sensor
{ VENDOR_SAMJIN, "water", samjinMacPrefix }, // Smarthings (Samjin) Water Sensor
{ VENDOR_SAMJIN, "button", samjinMacPrefix }, // Smarthings (Samjin) Button
{ VENDOR_SAMJIN, "outlet", samjinMacPrefix }, // Smarthings (Samjin) Outlet
{ VENDOR_JENNIC, "lumi.sensor_ht", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.weather", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_magnet", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_motion", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_switch.aq2", jennicMacPrefix }, // Xiaomi WXKG11LM 2016
{ VENDOR_JENNIC, "lumi.remote.b1acn01", jennicMacPrefix }, // Xiaomi WXKG11LM 2018
{ VENDOR_JENNIC, "lumi.sensor_switch.aq3", jennicMacPrefix }, // Xiaomi WXKG12LM
{ VENDOR_JENNIC, "lumi.sensor_cube", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_86sw1", jennicMacPrefix }, // Xiaomi single button wall switch WXKG03LM 2016
{ VENDOR_JENNIC, "lumi.remote.b186acn01", jennicMacPrefix }, // Xiaomi single button wall switch WXKG03LM 2018
{ VENDOR_JENNIC, "lumi.remote.b186acn02", jennicMacPrefix }, // Xiaomi single button wall switch WXKG02LM 2020
{ VENDOR_JENNIC, "lumi.sensor_86sw2", jennicMacPrefix }, // Xiaomi dual button wall switch WXKG02LM 2016
{ VENDOR_JENNIC, "lumi.remote.b286acn01", jennicMacPrefix }, // Xiaomi dual button wall switch WXKG02LM 2018
{ VENDOR_JENNIC, "lumi.remote.b286acn02", jennicMacPrefix }, // Xiaomi dual button wall switch WXKG02LM 2020
{ VENDOR_JENNIC, "lumi.sensor_switch", jennicMacPrefix }, // Xiaomi WXKG01LM, WXKG11LM and WXKG12LM (fallback)
{ VENDOR_JENNIC, "lumi.ctrl_neutral", jennicMacPrefix }, // Xiaomi Wall Switch (end-device)
{ VENDOR_JENNIC, "lumi.vibration", jennicMacPrefix }, // Xiaomi Aqara vibration/shock sensor
{ VENDOR_JENNIC, "lumi.sensor_wleak", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_smoke", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_natgas", jennicMacPrefix }, // Xiaomi Mija (HonneyWell) gas detector
{ VENDOR_JENNIC, "lumi.relay.c", jennicMacPrefix }, // Xiaomi Aqara LLKZMK11LM
{ VENDOR_XIAOMI, "lumi.plug", jennicMacPrefix }, // Xiaomi smart plug (router)
{ VENDOR_XIAOMI, "lumi.ctrl_ln", jennicMacPrefix}, // Xiaomi Wall Switch (router)
{ VENDOR_XIAOMI, "lumi.plug.maeu01", xiaomiMacPrefix}, // Xiaomi Aqara outlet
{ VENDOR_XIAOMI, "lumi.remote.b286opcn01", xiaomiMacPrefix }, // Xiaomi Aqara Opple WXCJKG11LM
{ VENDOR_XIAOMI, "lumi.remote.b486opcn01", xiaomiMacPrefix }, // Xiaomi Aqara Opple WXCJKG12LM
{ VENDOR_XIAOMI, "lumi.remote.b686opcn01", xiaomiMacPrefix }, // Xiaomi Aqara Opple WXCJKG13LM
{ VENDOR_XIAOMI, "lumi.sen_ill.mgl01", xiaomiMacPrefix }, // Xiaomi ZB3.0 light sensor
{ VENDOR_XIAOMI, "lumi.plug", xiaomiMacPrefix }, // Xiaomi smart plugs (router)
{ VENDOR_XIAOMI, "lumi.switch.b1naus01", xiaomiMacPrefix }, // Xiaomi Aqara ZB3.0 Smart Wall Switch Single Rocker WS-USC03
// { VENDOR_XIAOMI, "lumi.curtain", jennicMacPrefix}, // Xiaomi curtain controller (router) - exposed only as light
{ VENDOR_XIAOMI, "lumi.curtain.hagl04", xiaomiMacPrefix}, // Xiaomi B1 curtain controller
{ VENDOR_UBISYS, "C4", ubisysMacPrefix },
{ VENDOR_UBISYS, "D1", ubisysMacPrefix },
{ VENDOR_UBISYS, "J1", ubisysMacPrefix },
{ VENDOR_UBISYS, "S1", ubisysMacPrefix },
{ VENDOR_UBISYS, "S2", ubisysMacPrefix },
{ VENDOR_NONE, "Z716A", netvoxMacPrefix },
// { VENDOR_OSRAM_STACK, "Plug", osramMacPrefix }, // OSRAM plug - exposed only as light
{ VENDOR_OSRAM, "Lightify Switch Mini", emberMacPrefix }, // Osram 3 button remote
{ VENDOR_OSRAM, "Switch 4x EU-LIGHTIFY", emberMacPrefix }, // Osram 4 button remote
{ VENDOR_OSRAM, "Switch 4x-LIGHTIFY", emberMacPrefix }, // Osram 4 button remote
{ VENDOR_OSRAM, "Switch-LIGHTIFY", emberMacPrefix }, // Osram 4 button remote
{ VENDOR_OSRAM_STACK, "CO_", heimanMacPrefix }, // Heiman CO sensor
{ VENDOR_OSRAM_STACK, "DOOR_", heimanMacPrefix }, // Heiman door/window sensor - older model
{ VENDOR_OSRAM_STACK, "PIR_", heimanMacPrefix }, // Heiman motion sensor
{ VENDOR_OSRAM_STACK, "GAS_", heimanMacPrefix }, // Heiman gas sensor - older model
{ VENDOR_OSRAM_STACK, "TH-", heimanMacPrefix }, // Heiman temperature/humidity sensor
{ VENDOR_OSRAM_STACK, "SMOK_", heimanMacPrefix }, // Heiman fire sensor - older model
{ VENDOR_OSRAM_STACK, "WATER_", heimanMacPrefix }, // Heiman water sensor
{ VENDOR_OSRAM_STACK, "RC_V14", heimanMacPrefix }, // Heiman HS1RC-M remote control
{ VENDOR_LGE, "LG IP65 HMS", emberMacPrefix },
{ VENDOR_EMBER, "SmartPlug", emberMacPrefix }, // Heiman smart plug
{ VENDOR_HEIMAN, "SmartPlug", emberMacPrefix }, // Heiman smart plug
{ VENDOR_HEIMAN, "GAS", emberMacPrefix }, // Heiman gas sensor - newer model
{ VENDOR_HEIMAN, "Smoke", emberMacPrefix }, // Heiman fire sensor - newer model
{ VENDOR_HEIMAN, "COSensor", emberMacPrefix }, // Heiman CO sensor - newer model
{ VENDOR_HEIMAN, "TH-", emberMacPrefix }, // Heiman temperature/humidity sensor - newer model
{ VENDOR_HEIMAN, "HT-", emberMacPrefix }, // Heiman temperature/humidity sensor - newer model
{ VENDOR_HEIMAN, "Water", emberMacPrefix }, // Heiman water sensor - newer model
{ VENDOR_HEIMAN, "Door", emberMacPrefix }, // Heiman door/window sensor - newer model
{ VENDOR_HEIMAN, "WarningDevice", emberMacPrefix }, // Heiman siren
{ VENDOR_HEIMAN, "Smoke", jennicMacPrefix }, // Heiman fire sensor - newer model
{ VENDOR_HEIMAN, "PIRSensor-EM", jennicMacPrefix }, // Heiman motion sensor - newer model
{ VENDOR_HEIMAN, "SKHMP30", jennicMacPrefix }, // GS (Heiman) smart plug
{ VENDOR_HEIMAN, "RC-EM", emberMacPrefix }, // Heiman IAS ACE remote control
{ VENDOR_LUTRON, "LZL4BWHL01", lutronMacPrefix }, // Lutron LZL-4B-WH-L01 Connected Bulb Remote
{ VENDOR_LUTRON, "Z3-1BRL", lutronMacPrefix }, // Lutron Aurora Friends-of-Hue dimmer
{ VENDOR_KEEN_HOME , "SV01-", keenhomeMacPrefix}, // Keen Home Vent
{ VENDOR_KEEN_HOME , "SV02-", keenhomeMacPrefix}, // Keen Home Vent
{ VENDOR_INNR, "SP 120", jennicMacPrefix}, // innr smart plug
{ VENDOR_JENNIC, "VMS_ADUROLIGHT", jennicMacPrefix }, // Trust motion sensor ZPIR-8000
{ VENDOR_JENNIC, "CSW_ADUROLIGHT", jennicMacPrefix }, // Trust contact sensor ZMST-808
{ VENDOR_JENNIC, "ZYCT-202", jennicMacPrefix }, // Trust remote control ZYCT-202 (older model)
{ VENDOR_ADUROLIGHT, "ZLL-NonColorController", jennicMacPrefix }, // Trust remote control ZYCT-202 (newer model)
{ VENDOR_INNR, "RC 110", jennicMacPrefix }, // innr remote RC 110
{ VENDOR_VISONIC, "MCT-340", emberMacPrefix }, // Visonic MCT-340 E temperature/motion
{ VENDOR_SUNRICHER, "ED-1001", silabs2MacPrefix }, // EcoDim wireless switches
{ VENDOR_SUNRICHER, "ICZB-KPD1", emberMacPrefix }, // iCasa keypad
{ VENDOR_SUNRICHER, "ICZB-RM", silabs2MacPrefix }, // iCasa remote
{ VENDOR_SUNRICHER, "ZGRC-KEY", emberMacPrefix }, // Sunricher wireless CCT remote
{ VENDOR_SUNRICHER, "ZG2833K", emberMacPrefix }, // Sunricher remote controller
{ VENDOR_SUNRICHER, "RGBgenie ZB-5", emberMacPrefix }, // RGBgenie remote control
{ VENDOR_SUNRICHER, "ROB_200", silabs3MacPrefix }, // Sunricher SR-ZG9040A built-in dimmer, whitelabeled by Robbshop
{ VENDOR_SUNRICHER, "Micro Smart Dimmer", silabs3MacPrefix }, // Sunricher SR-ZG9040A built-in dimmer
{ VENDOR_SUNRICHER, "ZG2835", silabs6MacPrefix }, // SR-ZG2835 Zigbee Rotary Switch
{ VENDOR_SUNRICHER, "ZGRC-TEUR-", emberMacPrefix }, // iluminize wall switch 511.524
{ VENDOR_JENNIC, "SPZB0001", jennicMacPrefix }, // Eurotronic thermostat
{ VENDOR_NONE, "RES001", tiMacPrefix }, // Hubitat environment sensor, see #1308
{ VENDOR_SINOPE, "WL4200S", sinopeMacPrefix}, // Sinope water sensor with wired remote sensor
{ VENDOR_SINOPE, "WL4200", sinopeMacPrefix}, // Sinope water sensor
{ VENDOR_SINOPE, "TH1300ZB", sinopeMacPrefix }, // Sinope Thermostat
{ VENDOR_SINOPE, "TH112", sinopeMacPrefix }, // Sinope Thermostat TH1123ZB & TH1124ZB
{ VENDOR_ZEN, "Zen-01", zenMacPrefix }, // Zen Thermostat
{ VENDOR_C2DF, "3157100", emberMacPrefix }, // Centralite Thermostat
{ VENDOR_EMBER, "Super TR", emberMacPrefix }, // Elko Thermostat
{ VENDOR_EMBER, "ElkoDimmer", emberMacPrefix }, // Elko dimmer
{ VENDOR_ATMEL, "Thermostat", ecozyMacPrefix }, // eCozy Thermostat
{ VENDOR_OWON, "AC201", davicomMacPrefix }, // OWON AC201 Thermostat
{ VENDOR_STELPRO, "ST218", xalMacPrefix }, // Stelpro Thermostat
{ VENDOR_STELPRO, "STZB402", xalMacPrefix }, // Stelpro baseboard thermostat
{ VENDOR_STELPRO, "SORB", xalMacPrefix }, // Stelpro Orleans Fan
{ VENDOR_DEVELCO, "AQSZB-1", develcoMacPrefix }, // Develco air quality sensor
{ VENDOR_DEVELCO, "SMSZB-1", develcoMacPrefix }, // Develco smoke sensor
{ VENDOR_DEVELCO, "HESZB-1", develcoMacPrefix }, // Develco heat sensor
{ VENDOR_DEVELCO, "SPLZB-1", develcoMacPrefix }, // Develco smart plug
{ VENDOR_DEVELCO, "WISZB-1", develcoMacPrefix }, // Develco window sensor
{ VENDOR_DEVELCO, "MOSZB-1", develcoMacPrefix }, // Develco motion sensor
{ VENDOR_DEVELCO, "FLSZB-1", develcoMacPrefix }, // Develco water leak sensor
{ VENDOR_DEVELCO, "EMIZB-1", develcoMacPrefix }, // Develco EMI Norwegian HAN
{ VENDOR_DEVELCO, "SMRZB-3", develcoMacPrefix }, // Develco Smart Relay DIN
{ VENDOR_DEVELCO, "SIRZB-1", develcoMacPrefix }, // Develco siren
{ VENDOR_DEVELCO, "HMSZB-1", develcoMacPrefix }, // Develco temp/hum sensor
{ VENDOR_DEVELCO, "ZHMS101", develcoMacPrefix }, // Wattle (Develco) magnetic sensor
{ VENDOR_DEVELCO, "MotionSensor51AU", develcoMacPrefix }, // Aurora (Develco) motion sensor
{ VENDOR_EMBER, "3AFE14010402000D", konkeMacPrefix }, // Konke Kit Pro-BS Motion Sensor
{ VENDOR_KONKE, "3AFE28010402000D", ikea2MacPrefix }, // Konke Kit Pro-BS Motion Sensor ver.2
{ VENDOR_EMBER, "3AFE140103020000", konkeMacPrefix }, // Konke Kit Pro-FT Temp Humidity Sensor
{ VENDOR_KONKE, "3AFE220103020000", ikea2MacPrefix }, // Konke Kit Pro-BS Temp Humidity Sensor ver.2
{ VENDOR_KONKE, "3AFE220103020000", konkeMacPrefix }, // Konke Kit Pro-BS Temp Humidity Sensor ver ???
{ VENDOR_EMBER, "3AFE130104020015", konkeMacPrefix }, // Konke Kit Pro-Door Entry Sensor
{ VENDOR_NONE, "RICI01", tiMacPrefix}, // LifeControl smart plug
{ VENDOR_JENNIC, "VOC_Sensor", jennicMacPrefix}, // LifeControl Enviroment sensor
{ VENDOR_JENNIC, "SN10ZW", jennicMacPrefix }, // ORVIBO motion sensor
{ VENDOR_OSRAM_STACK, "SF20", heimanMacPrefix }, // ORVIBO SF20 smoke sensor
// Danalock support
{ VENDOR_DANALOCK, "V3", danalockMacPrefix}, // Danalock Smart Lock
// Schlage support
{ VENDOR_SCHLAGE, "BE468", schlageMacPrefix}, // Schlage BE468 Smart Lock
{ VENDOR_HEIMAN, "SF21", emberMacPrefix }, // ORVIBO SF21 smoke sensor
{ VENDOR_HEIMAN, "358e4e3e03c644709905034dae81433e", emberMacPrefix }, // Orvibo Combustible Gas Sensor
{ VENDOR_LEGRAND, "Dimmer switch w/o neutral", legrandMacPrefix }, // Legrand Dimmer switch wired
{ VENDOR_LEGRAND, "Connected outlet", legrandMacPrefix }, // Legrand Plug
{ VENDOR_LEGRAND, "Shutter switch with neutral", legrandMacPrefix }, // Legrand Shutter switch
{ VENDOR_LEGRAND, "Remote toggle switch", legrandMacPrefix }, // Legrand switch module
{ VENDOR_LEGRAND, "Cable outlet", legrandMacPrefix }, // Legrand Cable outlet
{ VENDOR_LEGRAND, "Remote switch", legrandMacPrefix }, // Legrand wireless switch
{ VENDOR_LEGRAND, "Double gangs remote switch", legrandMacPrefix }, // Legrand wireless double switch
{ VENDOR_LEGRAND, "Remote motion sensor", legrandMacPrefix }, // Legrand motion sensor
{ VENDOR_LEGRAND, "Shutters central remote switch", legrandMacPrefix }, // Legrand wireless shutter switch (battery)
{ VENDOR_LEGRAND, "DIN power consumption module", legrandMacPrefix }, // Legrand DIN power consumption module
{ VENDOR_LEGRAND, "Teleruptor", legrandMacPrefix }, // Legrand Teleruptor
{ VENDOR_LEGRAND, "Contactor", legrandMacPrefix }, // Legrand Contactor
{ VENDOR_NETVOX, "Z809AE3R", netvoxMacPrefix }, // Netvox smartplug
{ VENDOR_LDS, "ZB-ONOFFPlug-D0005", silabs2MacPrefix }, // Samsung SmartPlug 2019 (7A-PL-Z-J3)
{ VENDOR_LDS, "ZBT-DIMSwitch", silabs2MacPrefix }, // Linkind 1 key Remote Control / ZS23000178
{ VENDOR_LDS, "ZB-MotionSensor-D0003", silabsMacPrefix }, // Linkind motion sensor / ZS110040078
{ VENDOR_PHYSICAL, "outletv4", stMacPrefix }, // Samsung SmartThings plug (IM6001-OTP)
{ VENDOR_EMBER, "RH3040", konkeMacPrefix }, // Tuyatec motion sensor
{ VENDOR_NONE, "RH3001", ikea2MacPrefix }, // Tuyatec door/window sensor
{ VENDOR_EMBER, "RH3001", silabs3MacPrefix }, // Tuya/Blitzwolf BW-IS2 door/window sensor
{ VENDOR_NONE, "RH3052", emberMacPrefix }, // Tuyatec temperature sensor
{ VENDOR_NONE, "RH3052", konkeMacPrefix }, // Tuyatec/Lupus temperature sensor
{ VENDOR_EMBER, "TS0201", silabs3MacPrefix }, // Tuya/Blitzwolf temperature and humidity sensor
{ VENDOR_NONE, "TS0204", silabs3MacPrefix }, // Tuya gas sensor
{ VENDOR_NONE, "TS0205", silabs3MacPrefix }, // Tuya smoke sensor
{ VENDOR_NONE, "TS0121", silabs3MacPrefix }, // Tuya/Blitzwolf smart plug
{ VENDOR_EMBER, "TS0121", silabs3MacPrefix }, // Tuya/Blitzwolf smart plug
{ VENDOR_EMBER, "TS0302", silabs3MacPrefix }, // Tuya curtain switch
{ VENDOR_EMBER, "TS0041", silabs3MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0041", silabs5MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0042", silabs3MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0043", silabs3MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0043", silabs8MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0043", silabs7MacPrefix }, // Tuya wireless switch
{ VENDOR_EMBER, "TS0044", silabs9MacPrefix }, // Tuya wireless switch
{ VENDOR_NONE, "kud7u2l", silabs3MacPrefix }, // Tuya Smart TRV HY369 Thermostatic Radiator Valve
{ VENDOR_NONE, "GbxAXL2", silabs3MacPrefix }, // Another Tuya Smart TRV Thermostatic Radiator Valve
{ VENDOR_EMBER, "TS0601", silabs7MacPrefix }, // Tuya Smart TRV HY369 Thermostatic Radiator Valve
{ VENDOR_EMBER, "TS0601", silabs5MacPrefix }, // MOES Zigbee Radiator Actuator HY368 / Moes Tuya Thermostat BTH-002
{ VENDOR_EMBER, "TS0207", silabs3MacPrefix }, // Tuya water leak sensor
{ VENDOR_NONE, "TS0202", silabs4MacPrefix }, // Tuya presence sensor
{ VENDOR_NONE, "0yu2xgi", silabs5MacPrefix }, // Tuya siren
{ VENDOR_NONE, "eaxp72v", ikea2MacPrefix }, // Tuya TRV Wesmartify Thermostat Essentials Premium
{ VENDOR_NONE, "88teujp", silabs8MacPrefix }, // SEA802-Zigbee
{ VENDOR_NONE, "fvq6avy", silabs7MacPrefix }, // Revolt NX-4911-675 Thermostat
{ VENDOR_HEIMAN, "TY0203", silabs7MacPrefix }, // Lidl/Silvercrest Smart Window or Door Sensor
{ VENDOR_HEIMAN, "TY0202", silabs3MacPrefix }, // Lidl/Silvercrest Smart Motion Sensor
{ VENDOR_HEIMAN, "TY0202", silabs7MacPrefix }, // Lidl/Silvercrest Smart Motion Sensor
{ VENDOR_AURORA, "DoubleSocket50AU", jennicMacPrefix }, // Aurora AOne Double Socket UK
{ VENDOR_COMPUTIME, "SP600", computimeMacPrefix }, // Salus smart plug
{ VENDOR_HANGZHOU_IMAGIC, "1116-S", energyMiMacPrefix }, // iris contact sensor v3
{ VENDOR_HANGZHOU_IMAGIC, "1117-S", energyMiMacPrefix }, // iris motion sensor v3
{ VENDOR_JENNIC, "113D", jennicMacPrefix }, // iHorn (Huawei) temperature and humidity sensor
{ VENDOR_CHINA_FIRE_SEC, "LH05121", jennicMacPrefix }, // iHorn (Huawei) smoke detector
{ VENDOR_SERCOMM, "SZ-ESW01", emberMacPrefix }, // Sercomm / Telstra smart plug
{ VENDOR_SERCOMM, "SZ-SRN12N", emberMacPrefix }, // Sercomm siren
{ VENDOR_SERCOMM, "SZ-SRN12N", energyMiMacPrefix }, // Sercomm siren
{ VENDOR_SERCOMM, "SZ-DWS04", emberMacPrefix }, // Sercomm open/close sensor
{ VENDOR_SERCOMM, "Tripper", emberMacPrefix }, // Quirky Tripper (Sercomm) open/close sensor
{ VENDOR_ALERTME, "MOT003", tiMacPrefix }, // Hive Motion Sensor
{ VENDOR_ALERTME, "DWS003", tiMacPrefix }, // Hive Door sensor
{ VENDOR_ALERTME, "SLP2", computimeMacPrefix }, // Hive plug
{ VENDOR_ALERTME, "SLP2b", computimeMacPrefix }, // Hive plug
{ VENDOR_ALERTME, "SLR1b", computimeMacPrefix }, // Hive Heating Receiver 1 channel
{ VENDOR_ALERTME, "SLR2", computimeMacPrefix }, // Hive Heating Receiver 2 channel
{ VENDOR_ALERTME, "SLR2b", computimeMacPrefix }, // Hive Heating Receiver 2 channel second version
{ VENDOR_ALERTME, "SLT2", computimeMacPrefix }, // Hive thermostat
{ VENDOR_DANFOSS, "TRV001", silabs2MacPrefix }, // Hive thermostat (From Danfoos)
{ VENDOR_SUNRICHER, "45127", silabs2MacPrefix }, // Namron 1/2/4-ch remote controller
{ VENDOR_SENGLED_OPTOELEC, "E13-", zhejiangMacPrefix }, // Sengled PAR38 Bulbs
{ VENDOR_SENGLED_OPTOELEC, "E1D-", zhejiangMacPrefix }, // Sengled contact sensor
{ VENDOR_SENGLED_OPTOELEC, "E1E-", zhejiangMacPrefix }, // Sengled Smart Light Switch
{ VENDOR_JENNIC, "Plug-230V-ZB3.0", silabs2MacPrefix }, // Immax NEO ZB3.0 smart plug
{ VENDOR_JENNIC, "4in1-Sensor-ZB3.0", emberMacPrefix }, // Immax NEO ZB3.0 4 in 1 sensor
{ VENDOR_WAXMAN, "leakSMART Water Sensor V2", celMacPrefix }, // WAXMAN LeakSMART v2
{ VENDOR_PHILIO, "PST03A-v2.2.5", emberMacPrefix }, // Philio pst03-a
{ VENDOR_EMBERTEC, "BQZ10-AU", embertecMacPrefix }, // Embertec smart plug
{ VENDOR_MUELLER, "ZBT-Remote-ALL-RGBW", jennicMacPrefix }, // Tint remote control
{ VENDOR_PLUGWISE_BV, "160-01", emberMacPrefix }, // Plugwise smart plug
{ VENDOR_NIKO_NV, "Connected socket outlet", konkeMacPrefix }, // Niko smart socket 170-33505
{ VENDOR_ATMEL, "Bell", dishMacPrefix }, // Sage doorbell sensor
{ VENDOR_UNIVERSAL2, "4655BC0", emberMacPrefix }, // Ecolink contact sensor
{ VENDOR_NONE, "ZM-SmartPlug-1.0.0", tiMacPrefix }, // edp re:dy plug
{ VENDOR_NONE, "WB01", tiMacPrefix }, // Sonoff SNZB-01
{ VENDOR_NONE, "WB-01", tiMacPrefix }, // Sonoff SNZB-01
{ VENDOR_NONE, "MS01", tiMacPrefix }, // Sonoff SNZB-03
{ VENDOR_NONE, "MSO1", tiMacPrefix }, // Sonoff SNZB-03
{ VENDOR_NONE, "ms01", tiMacPrefix }, // Sonoff SNZB-03
{ VENDOR_NONE, "66666", tiMacPrefix }, // Sonoff SNZB-03
{ VENDOR_NONE, "TH01", tiMacPrefix }, // Sonoff SNZB-02
{ VENDOR_NONE, "DS01", tiMacPrefix }, // Sonoff SNZB-04
{ VENDOR_DANFOSS, "eTRV0100", silabs2MacPrefix }, // Danfoss Ally thermostat
{ VENDOR_LDS, "ZBT-CCTSwitch-D0001", silabs2MacPrefix }, // Leedarson remote control
{ VENDOR_KWIKSET, "SMARTCODE_CONVERT_GEN1", zenMacPrefix }, // Kwikset 914 ZigBee smart lock
{ VENDOR_EMBER, "TS1001", silabs5MacPrefix }, // LIDL Livarno Lux Remote Control HG06323
{ VENDOR_EMBER, "TS1001", silabs7MacPrefix }, // LIDL Livarno Lux Remote Control HG06323
{ 0, nullptr, 0 }
};
struct lidlDevice {
const char *zigbeeManufacturerName;
const char *zigbeeModelIdentifier;
const char *manufacturername;
const char *modelid;
};
static const lidlDevice lidlDevices[] = { // Sorted by zigbeeManufacturerName
{ "_TYZB01_bngwdjsr", "TS1001", "LIDL Livarno Lux", "HG06323" }, // Remote Control
{ "_TZ3000_1obwwnmq", "TS011F", "LIDL Silvercrest", "HG06338" }, // Smart USB Extension Lead (EU)
{ "_TZ3000_49qchf10", "TS0502A", "LIDL Livarno Lux", "HG06492C" }, // CT Light (E27)
{ "_TZ3000_dbou1ap4", "TS0505A", "LIDL Livarno Lux", "HG06106C" }, // RGB Light (E27)
{ "_TZ3000_el5kt5im", "TS0502A", "LIDL Livarno Lux", "HG06492A" }, // CT Light (GU10)
{ "_TZ3000_kdi2o9m6", "TS011F", "LIDL Silvercrest", "HG06337" }, // Smart plug (EU)
{ "_TZ3000_kdpxju99", "TS0505A", "LIDL Livarno Lux", "HG06106A" }, // RGB Light (GU10)
{ "_TZ3000_oborybow", "TS0502A", "LIDL Livarno Lux", "HG06492B" }, // CT Light (E14)
{ "_TZ3000_odygigth", "TS0505A", "LIDL Livarno Lux", "HG06106B" }, // RGB Light (E14)
{ "_TZ3000_riwp3k79", "TS0505A", "LIDL Livarno Lux", "HG06104A" }, // LED Light Strip
// { "_TZE200_s8gkrkxk", "TS0601", "LIDL Livarno Lux", "HG06467" }, // Smart LED String Lights (EU)
{ nullptr, nullptr, nullptr, nullptr }
};
static const lidlDevice *getLidlDevice(const QString &zigbeeManufacturerName)
{
const lidlDevice *device = lidlDevices;
while (device->zigbeeManufacturerName != nullptr)
{
if (zigbeeManufacturerName == QLatin1String(device->zigbeeManufacturerName))
{
return device;
}
device++;
}
return nullptr;
}
static bool isLidlDevice(const QString &zigbeeModelIdentifier, const QString &manufacturername)
{
const lidlDevice *device = lidlDevices;
while (device->zigbeeManufacturerName != nullptr)
{
if (zigbeeModelIdentifier == QLatin1String(device->zigbeeModelIdentifier) &&
manufacturername == QLatin1String(device->manufacturername))
{
return true;
}
device++;
}
return false;
}
int TaskItem::_taskCounter = 1; // static rolling taskcounter
/*! Returns the largest supported API version.
There might be one, none or multiple versions listed in \p hdrValue:
Accept: nothing, relevant, here --> ApiVersion_1
Accept: vnd.ddel.v1 --> ApiVersion_1_DDEL
Accept: vnd.ddel.v1,vnd.ddel.v1.1 --> ApiVersion_1_1_DDEL
Accept: vnd.ddel.v2 --> ApiVersion_2_DDEL
Accept: vnd.ddel.v1,vnd.ddel.v2 --> ApiVersion_2_DDEL
*/
static ApiVersion getAcceptHeaderApiVersion(const QString &hdrValue)
{
ApiVersion result = { ApiVersion_1 };
static const struct {
ApiVersion version;
const char *str;
} versions[] = {
// ordered by largest version
{ApiVersion_2_DDEL, "application/vnd.ddel.v2"},
{ApiVersion_1_1_DDEL, "application/vnd.ddel.v1.1"},
{ApiVersion_1_1_DDEL, "vnd.ddel.v1.1"}, // backward compatibility
{ApiVersion_1_DDEL, "application/vnd.ddel.v1"},
{ApiVersion_1_DDEL, "vnd.ddel.v1"}, // backward compatibility
{ApiVersion_1, nullptr}
};
const auto ls = hdrValue.split(QLatin1Char(','), QString::SkipEmptyParts);
for (int i = 0; versions[i].str != nullptr; i++)
{
if (ls.contains(QLatin1String(versions[i].str)))
{
result = versions[i].version;
break;
}
}
return result;
}
ApiRequest::ApiRequest(const QHttpRequestHeader &h, const QStringList &p, QTcpSocket *s, const QString &c) :
hdr(h), path(p), sock(s), content(c), version(ApiVersion_1), auth(ApiAuthNone), mode(ApiModeNormal)
{
if (hdr.hasKey(QLatin1String("Accept")) && hdr.value(QLatin1String("Accept")).contains(QLatin1String("vnd.ddel")))
{
version = getAcceptHeaderApiVersion(hdr.value(QLatin1String("Accept")));
}
}
/*! Returns the apikey of a request or a empty string if not available
*/
QString ApiRequest::apikey() const
{
if (path.length() > 1 && path[0] == QLatin1String("api"))
{
return path.at(1);
}
return QLatin1String("");
}
/*! Constructor for pimpl.
\param parent - the main plugin
*/
DeRestPluginPrivate::DeRestPluginPrivate(QObject *parent) :
QObject(parent)
{
plugin = this;
pollManager = new PollManager(this);
restDevices = new RestDevices(this);
databaseTimer = new QTimer(this);
databaseTimer->setSingleShot(true);
initEventQueue();
initResourceDescriptors();
connect(databaseTimer, SIGNAL(timeout()),
this, SLOT(saveDatabaseTimerFired()));
webSocketServer = 0;
gwScanner = new GatewayScanner(this);
connect(gwScanner, SIGNAL(foundGateway(QHostAddress,quint16,QString,QString)),
this, SLOT(foundGateway(QHostAddress,quint16,QString,QString)));
// gwScanner->startScan();
QString dataPath = deCONZ::getStorageLocation(deCONZ::ApplicationsDataLocation);
db = 0;
saveDatabaseItems = 0;
saveDatabaseIdleTotalCounter = 0;
dbZclValueMaxAge = 0; // default disable
sqliteDatabaseName = dataPath + QLatin1String("/zll.db");
idleLimit = 0;
idleTotalCounter = IDLE_READ_LIMIT;
idleLastActivity = 0;
idleUpdateZigBeeConf = idleTotalCounter + 15;
sensorIndIdleTotalCounter = 0;
queryTime = QTime::currentTime();
udpSock = 0;
haEndpoint = 0;
gwGroupSendDelay = deCONZ::appArgumentNumeric("--group-delay", GROUP_SEND_DELAY);
supportColorModeXyForGroups = true;
groupDeviceMembershipChecked = false;
gwLinkButton = false;
gwWebSocketNotifyAll = true;
gwdisablePermitJoinAutoOff = false;
// preallocate memory to get consistent pointers
nodes.reserve(300);
sensors.reserve(150);
fastProbeTimer = new QTimer(this);
fastProbeTimer->setInterval(500);
fastProbeTimer->setSingleShot(true);
connect(fastProbeTimer, SIGNAL(timeout()), this, SLOT(delayedFastEnddeviceProbe()));
apsCtrl = deCONZ::ApsController::instance();
DBG_Assert(apsCtrl != 0);
apsCtrl->setParameter(deCONZ::ParamOtauActive, 0);
// starttime reference counts from here
starttimeRef.start();
initConfig();
updateEtag(gwConfigEtag);
updateEtag(gwSensorsEtag);
updateEtag(gwGroupsEtag);
updateEtag(gwLightsEtag);
// set some default might be overwritten by database
gwAnnounceInterval = ANNOUNCE_INTERVAL;
gwAnnounceUrl = "https://phoscon.de/discover";
inetDiscoveryManager = nullptr;
webhookManager = new QNetworkAccessManager(this);
connect(webhookManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(webhookFinishedRequest(QNetworkReply*)));
// lights
searchLightsState = SearchLightsIdle;
searchLightsTimeout = 0;
// sensors
sensorCheckIter = 0;
searchSensorsState = SearchSensorsIdle;
searchSensorsTimeout = 0;
ttlDataBaseConnection = 0;
openDb();
initDb();
readDb();
closeDb();
initTimezone();
checkConsistency();
if (!gwUserParameter.contains("groupssequenceleft"))
{
gwUserParameter["groupssequenceleft"] = "[]";
}
if (!gwUserParameter.contains("groupssequenceright"))
{
gwUserParameter["groupssequenceright"] = "[]";
}
if (gwUuid.isEmpty())
{
generateGatewayUuid();
}
// create default group
// get new id
if (gwGroup0 == 0)
{
for (uint16_t i = 0xFFF0; i > 0; i--) // 0 and larger than 0xfff7 is not valid for Osram Lightify
{
Group* group = getGroupForId(i);
if (!group)
{
gwGroup0 = i;
break;
}
}
}
// delete old group 0
if (gwGroup0 != 0)
{
for (Group& group : groups)
{
if (group.address() == 0 && !(group.state() == Group::StateDeleted || group.state() == Group::StateDeleteFromDB))
{
group.setState(Group::StateDeleted);
queSaveDb(DB_CONFIG | DB_GROUPS, DB_LONG_SAVE_DELAY);
break;
}
}
}
// create new group 0
Group* group = getGroupForId(gwGroup0);
if (!group)
{
Group group;
group.setAddress(gwGroup0);
group.setName("All");
groups.push_back(group);
queSaveDb(DB_GROUPS, DB_LONG_SAVE_DELAY);
}
connect(apsCtrl, SIGNAL(apsdeDataConfirm(const deCONZ::ApsDataConfirm&)),
this, SLOT(apsdeDataConfirm(const deCONZ::ApsDataConfirm&)));
connect(apsCtrl, SIGNAL(apsdeDataIndication(const deCONZ::ApsDataIndication&)),
this, SLOT(apsdeDataIndication(const deCONZ::ApsDataIndication&)));
connect(apsCtrl, SIGNAL(nodeEvent(deCONZ::NodeEvent)),
this, SLOT(nodeEvent(deCONZ::NodeEvent)));
#if DECONZ_LIB_VERSION >= 0x010E00
connect(apsCtrl, &deCONZ::ApsController::sourceRouteCreated, this, &DeRestPluginPrivate::storeSourceRoute);
connect(apsCtrl, &deCONZ::ApsController::sourceRouteDeleted, this, &DeRestPluginPrivate::deleteSourceRoute);
connect(apsCtrl, &deCONZ::ApsController::nodesRestored, this, &DeRestPluginPrivate::restoreSourceRoutes, Qt::QueuedConnection);
#endif
deCONZ::GreenPowerController *gpCtrl = deCONZ::GreenPowerController::instance();
if (gpCtrl)
{
bool ok =
connect(gpCtrl, SIGNAL(gpDataIndication(deCONZ::GpDataIndication)),
this, SLOT(gpDataIndication(deCONZ::GpDataIndication)));
DBG_Assert(ok);
}
taskTimer = new QTimer(this);
taskTimer->setSingleShot(false);
connect(taskTimer, SIGNAL(timeout()),
this, SLOT(processTasks()));
taskTimer->start(100);
groupTaskTimer = new QTimer(this);
groupTaskTimer->setSingleShot(false);
connect(groupTaskTimer, SIGNAL(timeout()),
this, SLOT(processGroupTasks()));
groupTaskTimer->start(250);
verifyRulesTimer = new QTimer(this);
verifyRulesTimer->setSingleShot(false);
verifyRulesTimer->setInterval(100);
connect(verifyRulesTimer, SIGNAL(timeout()),
this, SLOT(verifyRuleBindingsTimerFired()));
verifyRulesTimer->start();
fastRuleCheckTimer = new QTimer(this);
fastRuleCheckTimer->setInterval(5);
fastRuleCheckTimer->setSingleShot(true);
connect(fastRuleCheckTimer, SIGNAL(timeout()),
this, SLOT(fastRuleCheckTimerFired()));
checkSensorsTimer = new QTimer(this);
checkSensorsTimer->setSingleShot(false);
checkSensorsTimer->setInterval(CHECK_SENSOR_INTERVAL);
connect(checkSensorsTimer, SIGNAL(timeout()),
this, SLOT(checkSensorStateTimerFired()));
checkSensorsTimer->start();
sensorCheckFast = 0;
bindingTimer = new QTimer(this);
bindingTimer->setSingleShot(true);
bindingTimer->setInterval(1000);
connect(bindingTimer, SIGNAL(timeout()),
this, SLOT(bindingTimerFired()));
bindingTableReaderTimer = new QTimer(this);
bindingTableReaderTimer->setSingleShot(true);
bindingTableReaderTimer->setInterval(1000);
connect(bindingTableReaderTimer, SIGNAL(timeout()),
this, SLOT(bindingTableReaderTimerFired()));
bindingToRuleTimer = new QTimer(this);
bindingToRuleTimer->setSingleShot(true);
bindingToRuleTimer->setInterval(50);
connect(bindingToRuleTimer, SIGNAL(timeout()),
this, SLOT(bindingToRuleTimerFired()));
lockGatewayTimer = new QTimer(this);
lockGatewayTimer->setSingleShot(true);
connect(lockGatewayTimer, SIGNAL(timeout()),
this, SLOT(lockGatewayTimerFired()));
openClientTimer = new QTimer(this);
openClientTimer->setSingleShot(false);
connect(openClientTimer, SIGNAL(timeout()),
this, SLOT(openClientTimerFired()));
openClientTimer->start(1000);
quint16 wsPort = deCONZ::appArgumentNumeric(QLatin1String("--ws-port"), gwConfig["websocketport"].toUInt());
webSocketServer = new WebSocketServer(this, wsPort);
gwConfig["websocketport"] = webSocketServer->port();
initNetworkInfo();
initUpnpDiscovery();
initAuthentication();
initInternetDicovery();
initSchedules();
initPermitJoin();
initOtau();
initTouchlinkApi();
initChangeChannelApi();
initResetDeviceApi();
initFirmwareUpdate();
//restoreWifiState();
indexRulesTriggers();
QTimer::singleShot(3000, this, SLOT(initWiFi()));
connect(pollManager, &PollManager::done, this, &DeRestPluginPrivate::pollNextDevice);
const deCONZ::Node *node;
if (apsCtrl && apsCtrl->getNode(0, &node) == 0)
{
addLightNode(node);
}
const QStringList buttonMapLocations = {
deCONZ::getStorageLocation(deCONZ::ApplicationsDataLocation) + QLatin1String("/devices/button_maps.json")
#ifdef Q_OS_LINUX
, "/usr/share/deCONZ/devices/button_maps.json"
#endif
#ifdef Q_OS_WIN
, qApp->applicationDirPath() + QLatin1String("/../devices/button_maps.json")
#endif
};
for (const auto &path : buttonMapLocations)
{
if (!QFile::exists(path))
{
continue;
}
QStringList requiredJsonObjects = {"buttons", "buttonActions", "clusters", "commands", "maps"};
QJsonDocument buttonMaps = readButtonMapJson(path);
if (checkRootLevelObjectsJson(buttonMaps, requiredJsonObjects))
{
btnMapClusters = loadButtonMapClustersJson(buttonMaps);
btnMapClusterCommands = loadButtonMapCommadsJson(buttonMaps);
buttonMapForModelId = loadButtonMapModelIdsJson(buttonMaps);
buttonMapData = loadButtonMapsJson(buttonMaps, btnMapClusters, btnMapClusterCommands);
break; // only load once
}
}
}
/*! Deconstructor for pimpl.
*/
DeRestPluginPrivate::~DeRestPluginPrivate()
{
if (inetDiscoveryManager)
{
inetDiscoveryManager->deleteLater();
inetDiscoveryManager = 0;
}
}
/*! APSDE-DATA.indication callback.
\param ind - the indication primitive
\note Will be called from the main application for each incoming indication.
Any filtering for nodes, profiles, clusters must be handled by this plugin.
*/
void DeRestPluginPrivate::apsdeDataIndication(const deCONZ::ApsDataIndication &ind)
{
Q_Q(DeRestPlugin);
if (!q->pluginActive())
{
return;
}
if ((ind.profileId() == HA_PROFILE_ID) || (ind.profileId() == ZLL_PROFILE_ID))
{
deCONZ::ZclFrame zclFrame;
{
QDataStream stream(ind.asdu());
stream.setByteOrder(QDataStream::LittleEndian);
zclFrame.readFromStream(stream);
}
switch (ind.clusterId())
{
case GROUP_CLUSTER_ID:
handleGroupClusterIndication(ind, zclFrame);
break;
case SCENE_CLUSTER_ID:
handleSceneClusterIndication(ind, zclFrame);
handleClusterIndicationGateways(ind, zclFrame);
break;
case OTAU_CLUSTER_ID:
otauDataIndication(ind, zclFrame);
break;
case COMMISSIONING_CLUSTER_ID:
handleCommissioningClusterIndication(ind, zclFrame);
break;
case LEVEL_CLUSTER_ID:
handleClusterIndicationGateways(ind, zclFrame);
break;
case ONOFF_CLUSTER_ID:
handleOnOffClusterIndication(ind, zclFrame);
handleClusterIndicationGateways(ind, zclFrame);
break;
case IAS_ZONE_CLUSTER_ID:
handleIasZoneClusterIndication(ind, zclFrame);
break;
case VENDOR_CLUSTER_ID:
// case DE_CLUSTER_ID:
if (zclFrame.manufacturerCode() == VENDOR_PHILIPS)
{
handlePhilipsClusterIndication(ind, zclFrame);
}
else // Shouldn't we check for DE manufacturer code?
{
handleDEClusterIndication(ind, zclFrame);
}
break;
case XAL_CLUSTER_ID:
handleXalClusterIndication(ind, zclFrame);
break;
case TIME_CLUSTER_ID:
handleTimeClusterIndication(ind, zclFrame);
break;
case WINDOW_COVERING_CLUSTER_ID:
handleWindowCoveringClusterIndication(ind, zclFrame);
break;
case TUYA_CLUSTER_ID:
// Tuya manfacture cluster:
handleTuyaClusterIndication(ind, zclFrame);
break;
case THERMOSTAT_CLUSTER_ID:
handleThermostatClusterIndication(ind, zclFrame);
break;
case BASIC_CLUSTER_ID:
handleBasicClusterIndication(ind, zclFrame);
break;
case APPLIANCE_EVENTS_AND_ALERTS_CLUSTER_ID:
handleApplianceAlertClusterIndication(ind, zclFrame);
break;
case THERMOSTAT_UI_CONFIGURATION_CLUSTER_ID:
handleThermostatUiConfigurationClusterIndication(ind, zclFrame);
break;
case DIAGNOSTICS_CLUSTER_ID:
handleDiagnosticsClusterIndication(ind, zclFrame);
break;
case IDENTIFY_CLUSTER_ID:
handleIdentifyClusterIndication(ind, zclFrame);
break;
case 0xFC03: // Develco specific -> VOC Management
case BOSCH_AIR_QUALITY_CLUSTER_ID: // Bosch Air quality sensor
handleAirQualityClusterIndication(ind, zclFrame);
break;
case POLL_CONTROL_CLUSTER_ID:
handlePollControlIndication(ind, zclFrame);
break;
case FAN_CONTROL_CLUSTER_ID:
handleFanControlClusterIndication(ind, zclFrame);
default:
{
}
break;
}
handleIndicationSearchSensors(ind, zclFrame);
if (ind.dstAddressMode() == deCONZ::ApsGroupAddress || ind.clusterId() == VENDOR_CLUSTER_ID || ind.clusterId() == IAS_ZONE_CLUSTER_ID ||
!(zclFrame.frameControl() & deCONZ::ZclFCDirectionServerToClient) ||
(zclFrame.isProfileWideCommand() && zclFrame.commandId() == deCONZ::ZclReportAttributesId))
{