forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_web_plugin_private.h
2168 lines (1975 loc) · 82.2 KB
/
de_web_plugin_private.h
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-2021 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.
*
*/
#ifndef DE_WEB_PLUGIN_PRIVATE_H
#define DE_WEB_PLUGIN_PRIVATE_H
#include <QtGlobal>
#include <QObject>
#include <QTime>
#include <QTimer>
#include <QElapsedTimer>
#include <stdint.h>
#include <queue>
#include <memory>
#if QT_VERSION < 0x050000
#include <QHttpRequestHeader>
#endif
#include <sqlite3.h>
#include <deconz.h>
#include "device.h"
#include "aps_controller_wrapper.h"
#include "alarm_system.h"
#include "resource.h"
#include "daylight.h"
#include "event_emitter.h"
#include "green_power.h"
#include "resource.h"
#include "rest_node_base.h"
#include "light_node.h"
#include "group.h"
#include "group_info.h"
#include "ias_zone.h"
#include "scene.h"
#include "sensor.h"
#include "resourcelinks.h"
#include "rule.h"
#include "bindings.h"
#include <math.h>
#include "websocket_server.h"
#include "tuya.h"
// enable domain specific string literals
using namespace deCONZ::literals;
#if defined(Q_OS_LINUX) && !defined(Q_PROCESSOR_X86)
// Workaround to detect ARM and AARCH64 in older Qt versions.
#define ARCH_ARM
#endif
/*! JSON generic error message codes */
#define ERR_UNAUTHORIZED_USER 1
#define ERR_INVALID_JSON 2
#define ERR_RESOURCE_NOT_AVAILABLE 3
#define ERR_METHOD_NOT_AVAILABLE 4
#define ERR_MISSING_PARAMETER 5
#define ERR_PARAMETER_NOT_AVAILABLE 6
#define ERR_INVALID_VALUE 7
#define ERR_PARAMETER_NOT_MODIFIABLE 8
#define ERR_TOO_MANY_ITEMS 11
#define ERR_DUPLICATE_EXIST 100 // de extension
#define ERR_NOT_ALLOWED_SENSOR_TYPE 501
#define ERR_SENSOR_LIST_FULL 502
#define ERR_RULE_ENGINE_FULL 601
#define ERR_CONDITION_ERROR 607
#define ERR_ACTION_ERROR 608
#define ERR_INTERNAL_ERROR 901
#define ERR_NOT_CONNECTED 950 // de extension
#define ERR_BRIDGE_BUSY 951 // de extension
#define ERR_LINK_BUTTON_NOT_PRESSED 101
#define ERR_DEVICE_OFF 201
#define ERR_DEVICE_NOT_REACHABLE 202
#define ERR_BRIDGE_GROUP_TABLE_FULL 301
#define ERR_DEVICE_GROUP_TABLE_FULL 302
#define ERR_DEVICE_SCENES_TABLE_FULL 402 // de extension
#define IDLE_TIMER_INTERVAL 1000
#define IDLE_LIMIT 30
#define IDLE_READ_LIMIT 120
#define IDLE_USER_LIMIT 20
#define IDLE_ATTR_REPORT_BIND_LIMIT 1800
#define IDLE_ATTR_REPORT_BIND_LIMIT_SHORT 5
#define BUTTON_ATTR_REPORT_BIND_LIMIT 120
#define WARMUP_TIME 120
#define RULE_CHECK_DELAY 4 // seconds
#define MAX_UNLOCK_GATEWAY_TIME 600
#define MAX_RECOVER_ENTRY_AGE 600
#define PERMIT_JOIN_SEND_INTERVAL (1000 * 60)
#define SET_ENDPOINTCONFIG_DURATION (1000 * 16) // time deCONZ needs to update Endpoints
#define OTA_LOW_PRIORITY_TIME (60 * 2)
#define CHECK_SENSOR_FAST_ROUNDS 3
#define CHECK_SENSOR_FAST_INTERVAL 100
#define CHECK_SENSOR_INTERVAL 1000
#define CHECK_SENSORS_MAX 10
#define CHECK_ZB_GOOD_INTERVAL 60
// wifi managed flags
#define WIFI_MGTM_HOSTAPD 0x01 // hostapd (by deCONZ)
#define WIFI_MGTM_WPA_SUPPLICANT 0x02 // wpa_supplicant (by deCONZ)
#define WIFI_MGTM_INTERFACES 0x04 // interfaces (by deCONZ)
#define WIFI_MGMT_ACTIVE 0x08 // 1 when accesspoint or client is active
#define DE_OTAU_ENDPOINT 0x50
#define DE_PROFILE_ID 0xDE00
// Digi Drop-In-Networking (DIN) ZigBee Profile, used by the XBee.
#define DIN_PROFILE_ID 0xC105 // Digi Drop-In-Networking
#define DIN_DDO_ENDPOINT 0xE6 // Digi Device Object endpoint
#define DIN_DDM_ENDPOINT 0xE8 // Digi Data Management endpoint
#define DEV_ID_DIN_XBEE 0x0001 // Device ID used by the XBee
// Generic devices
#define DEV_ID_ONOFF_SWITCH 0x0000 // On/Off switch
#define DEV_ID_LEVEL_CONTROL_SWITCH 0x0001 // Level control switch
#define DEV_ID_ONOFF_OUTPUT 0x0002 // On/Off output
#define DEV_ID_LEVEL_CONTROLLABLE_OUTPUT 0x0003 // Level controllable output
#define DEV_ID_CONFIGURATION_TOOL 0x0005 // Configuration tool
#define DEV_ID_RANGE_EXTENDER 0x0008 // Range extender
#define DEV_ID_MAINS_POWER_OUTLET 0x0009 // Mains power outlet
#define DEV_ID_CONSUMPTION_AWARENESS_DEVICE 0x000d // Consumption awareness device
#define DEV_ID_FAN 0x000e // Fan (used by Hamption Bay fan module)
#define DEV_ID_SMART_PLUG 0x0051 // Smart plug
// HA lighting devices
#define DEV_ID_HA_ONOFF_LIGHT 0x0100 // On/Off light
#define DEV_ID_HA_DIMMABLE_LIGHT 0x0101 // Dimmable light
#define DEV_ID_HA_COLOR_DIMMABLE_LIGHT 0x0102 // Color dimmable light
#define DEV_ID_HA_ONOFF_LIGHT_SWITCH 0x0103 // On/Off light switch
#define DEV_ID_HA_DIMMER_SWITCH 0x0104 // Dimmer switch
#define DEV_ID_HA_LIGHT_SENSOR 0x0106 // Light sensor
#define DEV_ID_HA_OCCUPANCY_SENSOR 0x0107 // Occupancy sensor
// Other HA devices
#define DEV_ID_HA_WINDOW_COVERING_DEVICE 0x0202 // Window Covering Device
#define DEV_ID_HA_WINDOW_COVERING_CONTROLLER 0x0203 // Window Covering Controller
// Door lock device
#define DEV_ID_DOOR_LOCK 0x000a // Door Lock
#define DEV_ID_DOOR_LOCK_UNIT 0x000b // Door Lock controller
//
#define DEV_ID_IAS_ZONE 0x0402 // IAS Zone
#define DEV_ID_IAS_WARNING_DEVICE 0x0403 // IAS Warning Device
// Smart Energy devices
#define DEV_ID_SE_METERING_DEVICE 0x0501 // Smart Energy metering device
// ZLL lighting devices
#define DEV_ID_ZLL_ONOFF_LIGHT 0x0000 // On/Off light
#define DEV_ID_ZLL_ONOFF_PLUGIN_UNIT 0x0010 // On/Off plugin unit
#define DEV_ID_ZLL_DIMMABLE_LIGHT 0x0100 // Dimmable light
#define DEV_ID_ZLL_DIMMABLE_PLUGIN_UNIT 0x0110 // Dimmable plugin unit
#define DEV_ID_ZLL_COLOR_LIGHT 0x0200 // Color light
#define DEV_ID_ZLL_EXTENDED_COLOR_LIGHT 0x0210 // Extended color light
#define DEV_ID_ZLL_COLOR_TEMPERATURE_LIGHT 0x0220 // Color temperature light
// ZigBee 3.0 lighting devices
#define DEV_ID_Z30_ONOFF_PLUGIN_UNIT 0x010a // On/Off plugin unit
#define DEV_ID_Z30_DIMMABLE_PLUGIN_UNIT 0x010b // Dimmable plugin unit
#define DEV_ID_Z30_COLOR_TEMPERATURE_LIGHT 0x010c // Color temperature light
#define DEV_ID_Z30_EXTENDED_COLOR_LIGHT 0x010d // Extended color light
// ZLL controller devices
#define DEV_ID_ZLL_COLOR_CONTROLLER 0x0800 // Color controller
#define DEV_ID_ZLL_COLOR_SCENE_CONTROLLER 0x0810 // Color scene controller
#define DEV_ID_ZLL_NON_COLOR_CONTROLLER 0x0820 // Non color controller
#define DEV_ID_ZLL_NON_COLOR_SCENE_CONTROLLER 0x0830 // Non color scene controller
#define DEV_ID_ZLL_CONTROL_BRIDGE 0x0840 // Control bridge
#define DEV_ID_ZLL_ONOFF_SENSOR 0x0850 // On/Off sensor
#define DEV_ID_XIAOMI_SMART_PLUG 0xffff
#define DEFAULT_TRANSITION_TIME 4 // 400ms
#define MAX_ENHANCED_HUE 65535
#define MAX_ENHANCED_HUE_Z 65278 // max supportet ehue of all devices
#define MIN_UNIQUEID_LENGTH 26 // 00:21:2e:ff:ff:00:a6:fd-02
#define BASIC_CLUSTER_ID 0x0000
#define POWER_CONFIGURATION_CLUSTER_ID 0x0001
#define IDENTIFY_CLUSTER_ID 0x0003
#define GROUP_CLUSTER_ID 0x0004
#define SCENE_CLUSTER_ID 0x0005
#define ONOFF_CLUSTER_ID 0x0006
#define ONOFF_SWITCH_CONFIGURATION_CLUSTER_ID 0x0007
#define LEVEL_CLUSTER_ID 0x0008
#define TIME_CLUSTER_ID 0x000A
#define ANALOG_INPUT_CLUSTER_ID 0x000C
#define ANALOG_OUTPUT_CLUSTER_ID 0x000D
#define BINARY_INPUT_CLUSTER_ID 0x000F
#define MULTISTATE_INPUT_CLUSTER_ID 0x0012
#define MULTISTATE_OUTPUT_CLUSTER_ID 0x0013
#define OTAU_CLUSTER_ID 0x0019
#define POLL_CONTROL_CLUSTER_ID 0x0020
#define DOOR_LOCK_CLUSTER_ID 0x0101
#define WINDOW_COVERING_CLUSTER_ID 0x0102
#define THERMOSTAT_CLUSTER_ID 0x0201
#define FAN_CONTROL_CLUSTER_ID 0x0202
#define THERMOSTAT_UI_CONFIGURATION_CLUSTER_ID 0x0204
#define COLOR_CLUSTER_ID 0x0300
#define ILLUMINANCE_MEASUREMENT_CLUSTER_ID 0x0400
#define ILLUMINANCE_LEVEL_SENSING_CLUSTER_ID 0x0401
#define TEMPERATURE_MEASUREMENT_CLUSTER_ID 0x0402
#define PRESSURE_MEASUREMENT_CLUSTER_ID 0x0403
#define RELATIVE_HUMIDITY_CLUSTER_ID 0x0405
#define OCCUPANCY_SENSING_CLUSTER_ID 0x0406
#define SOIL_MOISTURE_CLUSTER_ID 0x0408
#define IAS_ZONE_CLUSTER_ID 0x0500
#define IAS_ACE_CLUSTER_ID 0x0501
#define IAS_WD_CLUSTER_ID 0x0502
#define METERING_CLUSTER_ID 0x0702
#define APPLIANCE_EVENTS_AND_ALERTS_CLUSTER_ID 0x0B02
#define ELECTRICAL_MEASUREMENT_CLUSTER_ID 0x0B04
#define DIAGNOSTICS_CLUSTER_ID 0x0B05
#define COMMISSIONING_CLUSTER_ID 0x1000
#define TUYA_CLUSTER_ID 0xEF00
#define DE_CLUSTER_ID 0xFC00
#define VENDOR_CLUSTER_ID 0xFC00
#define UBISYS_DEVICE_SETUP_CLUSTER_ID 0xFC00
#define SAMJIN_CLUSTER_ID 0xFC02
#define DEVELCO_AIR_QUALITY_CLUSTER_ID 0xFC03
#define SENGLED_CLUSTER_ID 0xFC10
#define LEGRAND_CONTROL_CLUSTER_ID 0xFC40
#define XIAOMI_CLUSTER_ID 0xFCC0
#define ADUROLIGHT_CLUSTER_ID 0xFCCC
#define XIAOYAN_CLUSTER_ID 0xFCCC
#define XAL_CLUSTER_ID 0xFCCE
#define BOSCH_AIR_QUALITY_CLUSTER_ID quint16(0xFDEF)
#define IAS_ZONE_CLUSTER_ATTR_ZONE_STATUS_ID 0x0002
#define ONOFF_COMMAND_OFF 0x00
#define ONOFF_COMMAND_ON 0x01
#define ONOFF_COMMAND_TOGGLE 0x02
#define ONOFF_COMMAND_OFF_WITH_EFFECT 0x040
#define ONOFF_COMMAND_ON_WITH_TIMED_OFF 0x42
#define LEVEL_COMMAND_MOVE_TO_LEVEL 0x00
#define LEVEL_COMMAND_MOVE 0x01
#define LEVEL_COMMAND_STEP 0x02
#define LEVEL_COMMAND_STOP 0x03
#define LEVEL_COMMAND_MOVE_TO_LEVEL_WITH_ON_OFF 0x04
#define LEVEL_COMMAND_MOVE_WITH_ON_OFF 0x05
#define LEVEL_COMMAND_STEP_WITH_ON_OFF 0x06
#define LEVEL_COMMAND_STOP_WITH_ON_OFF 0x07
#define SCENE_COMMAND_RECALL_SCENE 0x05
#define SCENE_COMMAND_IKEA_STEP_CT 0x07
#define SCENE_COMMAND_IKEA_MOVE_CT 0x08
#define SCENE_COMMAND_IKEA_STOP_CT 0x09
#define WINDOW_COVERING_COMMAND_OPEN 0x00
#define WINDOW_COVERING_COMMAND_CLOSE 0x01
#define WINDOW_COVERING_COMMAND_STOP 0x02
#define WINDOW_COVERING_COMMAND_GOTO_LIFT_PCT 0x05
#define WINDOW_COVERING_COMMAND_GOTO_TILT_PCT 0x08
#define XIAOYAN_ATTRID_ROTATION_ANGLE 0x001B
#define XIAOYAN_ATTRID_DURATION 0x001A
#define MULTI_STATE_INPUT_PRESENT_VALUE_ATTRIBUTE_ID quint16(0x0055)
// IAS Zone Types
#define IAS_ZONE_TYPE_STANDARD_CIE 0x0000
#define IAS_ZONE_TYPE_MOTION_SENSOR 0x000d
#define IAS_ZONE_TYPE_CONTACT_SWITCH 0x0015
#define IAS_ZONE_TYPE_FIRE_SENSOR 0x0028
#define IAS_ZONE_TYPE_WATER_SENSOR 0x002a
#define IAS_ZONE_TYPE_CARBON_MONOXIDE_SENSOR 0x002b
#define IAS_ZONE_TYPE_VIBRATION_SENSOR 0x002d
#define IAS_ZONE_TYPE_WARNING_DEVICE 0x0225
// IAS Setup states
#define IAS_STATE_INIT 0
#define IAS_STATE_ENROLLED 1 // finished
#define IAS_STATE_READ 2
#define IAS_STATE_WAIT_READ 3
#define IAS_STATE_WRITE_CIE_ADDR 4
#define IAS_STATE_WAIT_WRITE_CIE_ADDR 5
#define IAS_STATE_DELAY_ENROLL 6
#define IAS_STATE_ENROLL 7
#define IAS_STATE_WAIT_ENROLL 8
#define IAS_STATE_MAX 9 // invalid
#ifndef DBG_IAS
#define DBG_IAS DBG_INFO // DBG_IAS didn't exist before version v2.10.x
#endif
// read and write flags
#define READ_MODEL_ID (1 << 0)
#define READ_SWBUILD_ID (1 << 1)
#define READ_ON_OFF (1 << 2)
#define READ_LEVEL (1 << 3)
#define READ_COLOR (1 << 4)
#define READ_GROUPS (1 << 5)
#define READ_SCENES (1 << 6)
#define READ_SCENE_DETAILS (1 << 7)
#define READ_VENDOR_NAME (1 << 8)
#define READ_BINDING_TABLE (1 << 9)
#define READ_OCCUPANCY_CONFIG (1 << 10)
#define WRITE_OCCUPANCY_CONFIG (1 << 11)
#define READ_GROUP_IDENTIFIERS (1 << 12)
#define WRITE_DELAY (1 << 13)
#define WRITE_SENSITIVITY (1 << 15)
#define READ_THERMOSTAT_STATE (1 << 17)
#define READ_BATTERY (1 << 18)
#define READ_TIME (1 << 19)
#define WRITE_TIME (1 << 20)
#define READ_THERMOSTAT_SCHEDULE (1 << 21)
#define READ_MODEL_ID_INTERVAL (60 * 60) // s
#define READ_SWBUILD_ID_INTERVAL (60 * 60) // s
// manufacturer codes
// https://github.com/wireshark/wireshark/blob/master/epan/dissectors/packet-zbee.h
#define VENDOR_NONE 0x0000
#define VENDOR_EMBER 0x1002
#define VENDOR_PHILIPS 0x100B // Also used by iCasa routers
#define VENDOR_VISONIC 0x1011
#define VENDOR_ATMEL 0x1014
#define VENDOR_DEVELCO 0x1015
#define VENDOR_YALE 0x101D
#define VENDOR_MAXSTREAM 0x101E // Used by Digi
#define VENDOR_VANTAGE 0x1021
#define VENDOR_LEGRAND 0x1021 // wrong name?
#define VENDOR_LGE 0x102E
#define VENDOR_JENNIC 0x1037 // Used by Xiaomi, Trust, Eurotronic
#define VENDOR_ALERTME 0x1039
#define VENDOR_CLS 0x104E
#define VENDOR_CENTRALITE 0x104E // wrong name?
#define VENDOR_SI_LABS 0x1049
#define VENDOR_SCHNEIDER 0x105E
#define VENDOR_4_NOKS 0x1071
#define VENDOR_BITRON 0x1071 // branded
#define VENDOR_COMPUTIME 0x1078
#define VENDOR_XFINITY 0x10EF // Xfinity
#define VENDOR_AXIS 0x1262 // Axis
#define VENDOR_KWIKSET 0x1092
#define VENDOR_MMB 0x109a
#define VENDOR_NETVOX 0x109F
#define VENDOR_NYCE 0x10B9
#define VENDOR_UNIVERSAL2 0x10EF
#define VENDOR_UBISYS 0x10F2
#define VENDOR_DATEK_WIRLESS 0x1337
#define VENDOR_DANALOCK 0x115C
#define VENDOR_SCHLAGE 0x1236 // Used by Schlage Locks
#define VENDOR_BEGA 0x1105
#define VENDOR_PHYSICAL 0x110A // Used by SmartThings
#define VENDOR_OSRAM 0x110C
#define VENDOR_PROFALUX 0x1110
#define VENDOR_EMBERTEC 0x1112
#define VENDOR_JASCO 0x1124 // Used by GE
#define VENDOR_BUSCH_JAEGER 0x112E
#define VENDOR_SERCOMM 0x1131
#define VENDOR_BOSCH 0x1133
#define VENDOR_DDEL 0x1135
#define VENDOR_WAXMAN 0x113B
#define VENDOR_OWON 0x113C
#define VENDOR_TUYA 0x1141
#define VENDOR_LUTRON 0x1144
#define VENDOR_BOSCH2 0x1155
#define VENDOR_ZEN 0x1158
#define VENDOR_KEEN_HOME 0x115B
#define VENDOR_XIAOMI 0x115F
#define VENDOR_SENGLED_OPTOELEC 0x1160
#define VENDOR_INNR 0x1166
#define VENDOR_LDS 0x1168 // Used by Samsung SmartPlug 2019
#define VENDOR_PLUGWISE_BV 0x1172
#define VENDOR_D_LINK 0x1175
#define VENDOR_INSTA 0x117A
#define VENDOR_IKEA 0x117C
#define VENDOR_3A_SMART_HOME 0x117E
#define VENDOR_STELPRO 0x1185
#define VENDOR_LEDVANCE 0x1189
#define VENDOR_SINOPE 0x119C
#define VENDOR_JIUZHOU 0x119D
#define VENDOR_PAULMANN 0x119D // branded
#define VENDOR_BOSCH3 0x1209
#define VENDOR_HEIMAN 0x120B
#define VENDOR_CHINA_FIRE_SEC 0x1214
#define VENDOR_MUELLER 0x121B // Used by Mueller Licht
#define VENDOR_AURORA 0x121C // Used by Aurora Aone
#define VENDOR_SUNRICHER 0x1224 // white label used by iCasa, Illuminize, Namron, SLC ...
#define VENDOR_XIAOYAN 0x1228
#define VENDOR_XAL 0x122A
#define VENDOR_ADUROLIGHT 0x122D
#define VENDOR_THIRD_REALITY 0x1233
#define VENDOR_DSR 0x1234
#define VENDOR_HANGZHOU_IMAGIC 0x123B
#define VENDOR_SAMJIN 0x1241
#define VENDOR_DANFOSS 0x1246
#define VENDOR_NIKO_NV 0x125F
#define VENDOR_KONKE 0x1268
#define VENDOR_SHYUGJ_TECHNOLOGY 0x126A
#define VENDOR_ADEO 0x1277
#define VENDOR_XIAOMI2 0x126E
#define VENDOR_DATEK 0x1337
#define VENDOR_OSRAM_STACK 0xBBAA
#define VENDOR_C2DF 0xC2DF
#define VENDOR_PHILIO 0xFFA0
#define ANNOUNCE_INTERVAL 45 // minutes default announce interval
#define MAX_NODES 200
#define MAX_SENSORS 1000
#define MAX_GROUPS 100
#define MAX_SCENES 100
#define MAX_LIGHTSTATES 1000
#define MAX_SCHEDULES 500
#define MAX_RULES 500
#define MAX_CONDITIONS 1000
#define MAX_ACTIONS 1000
#define MAX_RESOURCELINKS 100
#define MAX_STREAMING 0
#define MAX_CHANNELS 50
#define MAX_GROUP_SEND_DELAY 5000 // ms between to requests to the same group
#define GROUP_SEND_DELAY 50 // default ms between to requests to the same group
#define MAX_TASKS_PER_NODE 2
#define MAX_BACKGROUND_TASKS 5
#define MAX_RULE_ILLUMINANCE_VALUE_AGE_MS (1000 * 60 * 20) // 20 minutes
// string lengths
#define MAX_GROUP_NAME_LENGTH 32
#define MAX_SCENE_NAME_LENGTH 32
#define MAX_RULE_NAME_LENGTH 64
#define MAX_SENSOR_NAME_LENGTH 32
// REST API return codes
#define REQ_READY_SEND 0
#define REQ_NOT_HANDLED -1
// Special application return codes
#define APP_RET_UPDATE 40
#define APP_RET_RESTART_APP 41
#define APP_RET_UPDATE_BETA 42
#define APP_RET_RESTART_SYS 43
#define APP_RET_SHUTDOWN_SYS 44
#define APP_RET_UPDATE_ALPHA 45
#define APP_RET_UPDATE_FW 46
// Firmware version related (32-bit field)
#define FW_PLATFORM_MASK 0x0000FF00UL
#define FW_PLATFORM_DERFUSB23E0X 0x00000300UL
#define FW_PLATFORM_AVR 0x00000500UL
#define FW_PLATFORM_R21 0x00000700UL
// schedules
#define SCHEDULE_CHECK_PERIOD 1000
// save database items
#define DB_LIGHTS 0x00000001
#define DB_GROUPS 0x00000002
#define DB_AUTH 0x00000004
#define DB_CONFIG 0x00000008
#define DB_SCENES 0x00000010
#define DB_SCHEDULES 0x00000020
#define DB_RULES 0x00000040
#define DB_SENSORS 0x00000080
#define DB_USERPARAM 0x00000100
#define DB_GATEWAYS 0x00000200
#define DB_RESOURCELINKS 0x00000400
#define DB_QUERY_QUEUE 0x00000800
#define DB_SYNC 0x00001000
#define DB_NOSAVE 0x00002000
#define DB_HUGE_SAVE_DELAY (60 * 60 * 1000) // 60 minutes
#define DB_LONG_SAVE_DELAY (15 * 60 * 1000) // 15 minutes
#define DB_SHORT_SAVE_DELAY (1 * 60 * 1000) // 1 minute
#define DB_FAST_SAVE_DELAY (1 * 1000) // 1 second
#define DB_CONNECTION_TTL (60 * 15) // 15 minutes
// internet discovery
// network reconnect
#define DISCONNECT_CHECK_DELAY 100
#define NETWORK_ATTEMPS 10
#define RECONNECT_CHECK_DELAY 5000
#define RECONNECT_NOW 100
//Epoch mode
#define UNIX_EPOCH 0
#define J2000_EPOCH 1
void getTime(quint32 *time, qint32 *tz, quint32 *dstStart, quint32 *dstEnd, qint32 *dstShift, quint32 *standardTime, quint32 *localTime, quint8 mode);
int getFreeSensorId(); // TODO needs to be part of a Database class
int getFreeLightId(); // TODO needs to be part of a Database class
// REST API common
QVariantMap errorToMap(int id, const QString &ressource, const QString &description);
extern const quint64 macPrefixMask;
extern const quint64 celMacPrefix;
extern const quint64 bjeMacPrefix;
extern const quint64 davicomMacPrefix;
extern const quint64 dlinkMacPrefix;
extern const quint64 deMacPrefix;
extern const quint64 emberMacPrefix;
extern const quint64 embertecMacPrefix;
extern const quint64 energyMiMacPrefix;
extern const quint64 heimanMacPrefix;
extern const quint64 zenMacPrefix;
extern const quint64 silabs1MacPrefix;
extern const quint64 ikea2MacPrefix;
extern const quint64 silabsMacPrefix;
extern const quint64 silabs2MacPrefix;
extern const quint64 silabs3MacPrefix;
extern const quint64 silabs4MacPrefix;
extern const quint64 silabs5MacPrefix;
extern const quint64 silabs6MacPrefix;
extern const quint64 silabs7MacPrefix;
extern const quint64 silabs8MacPrefix;
extern const quint64 silabs9MacPrefix;
extern const quint64 silabs10MacPrefix;
extern const quint64 silabs11MacPrefix;
extern const quint64 silabs12MacPrefix;
extern const quint64 silabs13MacPrefix;
extern const quint64 instaMacPrefix;
extern const quint64 casaiaPrefix;
extern const quint64 boschMacPrefix;
extern const quint64 jennicMacPrefix;
extern const quint64 lutronMacPrefix;
extern const quint64 netvoxMacPrefix;
extern const quint64 osramMacPrefix;
extern const quint64 philipsMacPrefix;
extern const quint64 sinopeMacPrefix;
extern const quint64 stMacPrefix;
extern const quint64 samjinMacPrefix;
extern const quint64 tiMacPrefix;
extern const quint64 ubisysMacPrefix;
extern const quint64 xalMacPrefix;
extern const quint64 onestiPrefix;
extern const quint64 develcoMacPrefix;
extern const quint64 legrandMacPrefix;
extern const quint64 YooksmartMacPrefix;
extern const quint64 profaluxMacPrefix;
extern const quint64 xiaomiMacPrefix;
extern const quint64 computimeMacPrefix;
extern const quint64 konkeMacPrefix;
extern const quint64 ecozyMacPrefix;
extern const quint64 zhejiangMacPrefix;
extern const quint64 schlageMacPrefix;
extern const quint64 lumiMacPrefix;
inline bool existDevicesWithVendorCodeForMacPrefix(quint64 addr, quint16 vendor)
{
const quint64 prefix = addr & macPrefixMask;
switch (vendor) {
case VENDOR_XIAOMI:
return prefix == jennicMacPrefix ||
prefix == xiaomiMacPrefix ||
prefix == lumiMacPrefix;
case VENDOR_SINOPE:
return prefix == sinopeMacPrefix;
case VENDOR_HEIMAN:
return prefix == emberMacPrefix ||
prefix == jennicMacPrefix;
case VENDOR_SUNRICHER:
return prefix == emberMacPrefix ||
prefix == silabs3MacPrefix ||
prefix == silabs6MacPrefix;
case VENDOR_3A_SMART_HOME:
return prefix == jennicMacPrefix;
case VENDOR_ADEO:
return prefix == emberMacPrefix ||
prefix == silabs9MacPrefix ||
prefix == konkeMacPrefix;
case VENDOR_ALERTME:
return prefix == tiMacPrefix ||
prefix == computimeMacPrefix;
case VENDOR_BITRON:
return prefix == tiMacPrefix;
case VENDOR_BOSCH:
return prefix == boschMacPrefix ||
prefix == emberMacPrefix;
case VENDOR_BUSCH_JAEGER:
return prefix == bjeMacPrefix;
case VENDOR_C2DF:
return prefix == emberMacPrefix;
case VENDOR_CENTRALITE:
return prefix == emberMacPrefix;
case VENDOR_CHINA_FIRE_SEC:
return prefix == jennicMacPrefix;
case VENDOR_DANFOSS:
return prefix == silabs2MacPrefix;
case VENDOR_EMBER:
return prefix == emberMacPrefix ||
prefix == konkeMacPrefix ||
prefix == silabs3MacPrefix ||
prefix == silabs5MacPrefix ||
prefix == silabs10MacPrefix ||
prefix == silabs13MacPrefix ||
prefix == silabs7MacPrefix;
case VENDOR_EMBERTEC:
return prefix == embertecMacPrefix;
case VENDOR_DDEL:
return prefix == deMacPrefix ||
prefix == silabs3MacPrefix;
case VENDOR_IKEA:
return prefix == silabs1MacPrefix ||
prefix == silabsMacPrefix ||
prefix == silabs2MacPrefix ||
prefix == silabs4MacPrefix ||
prefix == energyMiMacPrefix ||
prefix == emberMacPrefix;
case VENDOR_JASCO:
return prefix == celMacPrefix;
case VENDOR_INNR:
return prefix == jennicMacPrefix ||
prefix == silabs4MacPrefix;
case VENDOR_LDS:
return prefix == jennicMacPrefix ||
prefix == silabsMacPrefix ||
prefix == silabs2MacPrefix;
case VENDOR_INSTA:
return prefix == instaMacPrefix;
case VENDOR_JENNIC:
return prefix == jennicMacPrefix;
case VENDOR_KEEN_HOME:
return prefix == celMacPrefix;
case VENDOR_LGE:
return prefix == emberMacPrefix;
case VENDOR_LUTRON:
return prefix == lutronMacPrefix;
case VENDOR_NIKO_NV:
return prefix == konkeMacPrefix;
case VENDOR_NYCE:
return prefix == emberMacPrefix;
case VENDOR_OSRAM:
case VENDOR_OSRAM_STACK:
return prefix == osramMacPrefix ||
prefix == heimanMacPrefix;
case VENDOR_OWON:
return prefix == davicomMacPrefix;
case VENDOR_PHILIPS:
return prefix == philipsMacPrefix;
case VENDOR_PLUGWISE_BV:
return prefix == emberMacPrefix;
case VENDOR_PHYSICAL:
return prefix == stMacPrefix;
case VENDOR_SENGLED_OPTOELEC:
return prefix == zhejiangMacPrefix;
case VENDOR_SERCOMM:
return prefix == emberMacPrefix ||
prefix == energyMiMacPrefix;
case VENDOR_SI_LABS:
return prefix == silabsMacPrefix ||
prefix == energyMiMacPrefix ||
prefix == silabs1MacPrefix;
case VENDOR_STELPRO:
return prefix == xalMacPrefix;
case VENDOR_UBISYS:
return prefix == ubisysMacPrefix;
case VENDOR_UNIVERSAL2:
return prefix == emberMacPrefix;
case VENDOR_VISONIC:
return prefix == emberMacPrefix;
case VENDOR_XAL:
return prefix == xalMacPrefix;
case VENDOR_SAMJIN:
return prefix == samjinMacPrefix;
case VENDOR_DEVELCO:
return prefix == develcoMacPrefix;
case VENDOR_LEGRAND:
return prefix == legrandMacPrefix;
case VENDOR_PROFALUX:
return prefix == profaluxMacPrefix;
case VENDOR_NETVOX:
return prefix == netvoxMacPrefix;
case VENDOR_AURORA:
return prefix == jennicMacPrefix;
case VENDOR_COMPUTIME:
return prefix == computimeMacPrefix;
case VENDOR_DANALOCK:
return prefix == silabs1MacPrefix;
case VENDOR_AXIS:
case VENDOR_MMB:
return prefix == zenMacPrefix;
case VENDOR_SCHLAGE:
return prefix == schlageMacPrefix;
case VENDOR_ADUROLIGHT:
return prefix == jennicMacPrefix;
case VENDOR_D_LINK:
return prefix == dlinkMacPrefix;
default:
return false;
}
}
inline bool existDevicesWithVendorCodeForMacPrefix(const deCONZ::Address &addr, quint16 vendor)
{
return existDevicesWithVendorCodeForMacPrefix(addr.ext(), vendor);
}
inline bool checkMacAndVendor(const deCONZ::Node *node, quint16 vendor)
{
return node->nodeDescriptor().manufacturerCode() == vendor && existDevicesWithVendorCodeForMacPrefix(node->address(), vendor);
}
quint8 zclNextSequenceNumber();
const deCONZ::Node *getCoreNode(uint64_t extAddress);
// HTTP status codes
extern const char *HttpStatusOk;
extern const char *HttpStatusAccepted;
extern const char *HttpStatusNotModified;
extern const char *HttpStatusUnauthorized;
extern const char *HttpStatusBadRequest;
extern const char *HttpStatusForbidden;
extern const char *HttpStatusNotFound;
extern const char *HttpStatusNotImplemented;
extern const char *HttpStatusServiceUnavailable;
extern const char *HttpContentHtml;
extern const char *HttpContentCss;
extern const char *HttpContentJson;
extern const char *HttpContentJS;
extern const char *HttpContentPNG;
extern const char *HttpContentJPG;
extern const char *HttpContentSVG;
// Forward declarations
class DeviceDescriptions;
class DeviceWidget;
class DeviceJs;
class Gateway;
class GatewayScanner;
class QUdpSocket;
class QTcpSocket;
class DeRestPlugin;
class QHostInfo;
class QNetworkReply;
class QNetworkAccessManager;
class QProcess;
class PollManager;
class RestDevices;
struct Schedule
{
enum Week
{
Monday = 0x01,
Tuesday = 0x02,
Wednesday = 0x04,
Thursday = 0x08,
Friday = 0x10,
Saturday = 0x20,
Sunday = 0x40,
};
enum Type
{
TypeInvalid,
TypeAbsoluteTime,
TypeRecurringTime,
TypeTimer
};
enum State
{
StateNormal,
StateDeleted
};
Schedule() :
type(TypeInvalid),
state(StateNormal),
status(QLatin1String("enabled")),
activation(QLatin1String("start")),
autodelete(true),
weekBitmap(0),
recurring(0),
timeout(0),
currentTimeout(0)
{
}
Type type;
State state;
/*! Numeric identifier as string. */
QString id;
/*! etag of Schedule. */
QString etag;
/*! Name length 0..32, if 0 default name "schedule" will be used. (Optional) */
QString name;
/*! Description length 0..64, default is empty string. (Optional) */
QString description;
/*! Command a JSON object with length 0..90. (Required) */
QString command;
/*! Time is given in ISO 8601:2004 format: YYYY-MM-DDTHH:mm:ss. (Required) */
QString time;
/*! Localtime is given in ISO 8601:2004 format: YYYY-MM-DDTHH:mm:ss. (Optional) */
QString localtime;
/*! UTC time that the timer was started. Only provided for timers. */
QString starttime;
/*! status of schedule (enabled or disabled). */
QString status;
/*! should activation of schedule start or end at given time (if a fading time is given) (start or end). */
QString activation;
/*! If set to true, the schedule will be removed automatically if expired, if set to false it will be disabled. */
bool autodelete;
/*! Same as time but as qt object. */
QDateTime datetime;
/*! Date time of last schedule activation. */
QDateTime lastTriggerDatetime;
/*! Whole JSON schedule as received from API as string. */
QString jsonString;
/*! Whole JSON schedule as received from API as map. */
QVariantMap jsonMap;
/*! Bitmap for recurring schedule. */
quint8 weekBitmap;
/*! R[nn], the recurring part, 0 means forever. */
uint recurring;
QDateTime endtime; /*! Localtime of timeout: for timers only. */
/*! Timeout in seconds. */
int timeout;
/*! Current timeout counting down to ::timeout. */
int currentTimeout;
};
enum TaskType
{
TaskIdentify = 0,
TaskGetHue = 1,
TaskSetHue = 2,
TaskSetEnhancedHue = 3,
TaskSetHueAndSaturation = 4,
TaskSetXyColor = 5,
TaskSetColorTemperature = 6,
TaskGetColor = 7,
TaskGetSat = 8,
TaskSetSat = 9,
TaskGetLevel = 10,
TaskSetLevel = 11,
TaskIncColorTemperature = 12,
TaskStopLevel = 13,
TaskSendOnOffToggle = 14,
TaskMoveLevel = 15,
TaskGetOnOff = 16,
TaskSetColorLoop = 17,
TaskGetColorLoop = 18,
TaskReadAttributes = 19,
TaskWriteAttribute = 20,
TaskGetGroupMembership = 21,
TaskGetGroupIdentifiers = 22,
TaskGetSceneMembership = 23,
TaskStoreScene = 24,
TaskCallScene = 25,
TaskViewScene = 26,
TaskAddScene = 27,
TaskRemoveScene = 28,
TaskRemoveAllScenes = 29,
TaskAddToGroup = 30,
TaskRemoveFromGroup = 31,
TaskViewGroup = 32,
TaskTriggerEffect = 33,
TaskWarning = 34,
TaskIncBrightness = 35,
TaskWindowCovering = 36,
TaskThermostat = 37,
TaskDoorLock = 38, // Danalock support
TaskHueGradient = 45,
TaskSyncTime = 40,
TaskTuyaRequest = 41,
TaskXmasLightStrip = 42,
TaskSimpleMetering = 43,
TaskHueEffect = 44
};
enum XmasLightStripMode
{
ModeWhite = 0,
ModeColour = 1,
ModeEffect = 2
};
enum XmasLightStripEffect
{
EffectSteady = 0x00,
EffectSnow = 0x01,
EffectRainbow = 0x02,
EffectSnake = 0x03,
EffectTwinkle = 0x04,
EffectFireworks = 0x05,
EffectFlag = 0x06,
EffectWaves = 0x07,
EffectUpdown = 0x08,
EffectVintage = 0x09,
EffectFading = 0x0a,
EffectCollide = 0x0b,
EffectStrobe = 0x0c,
EffectSparkles = 0x0d,
EffectCarnaval = 0x0e,
EffectGlow = 0x0f
};
struct TaskItem
{
TaskItem()
{
taskId = _taskCounter++;
autoMode = false;
onOff = false;
client = 0;
node = 0;
lightNode = 0;
cluster = 0;
colorX = 0;
colorY = 0;
colorTemperature = 0;
transitionTime = DEFAULT_TRANSITION_TIME;
onTime = 0;
sendTime = 0;
ordered = false;
}
TaskType taskType;
int taskId;
deCONZ::ApsDataRequest req;
deCONZ::ZclFrame zclFrame;
uint8_t zclSeq;
bool ordered; // won't be send until al prior taskIds are send
int sendTime; // copy of idleTotalCounter
bool confirmed;
bool onOff;
bool colorLoop;
qreal hueReal;
uint16_t identifyTime;
uint8_t effectIdentifier;
uint8_t options;
uint16_t duration;
uint8_t hue;
uint8_t sat;
uint8_t level;
uint16_t enhancedHue;
uint16_t colorX;
uint16_t colorY;
uint16_t colorTemperature;
uint16_t groupId;
uint8_t sceneId;
qint32 inc; // bri_inc, hue_inc, sat_inc, ct_inc
QString etag;
uint16_t transitionTime;
uint16_t onTime;
QTcpSocket *client;
bool autoMode; // true then this is a automode task
deCONZ::Node *node;
LightNode *lightNode;
deCONZ::ZclCluster *cluster;
private:
static int _taskCounter;
};
/*! \class ApiAuth
Helper to combine serval authorisation parameters.
*/
class ApiAuth
{
public:
enum State
{
StateNormal,
StateDeleted
};
ApiAuth();
void setDeviceType(const QString &devtype);
bool needSaveDatabase;
State state;
QString apikey; // also called username (10..32 chars)
QString devicetype;
QDateTime createDate;
QDateTime lastUseDate;
QString useragent;
};
enum ApiVersion
{
ApiVersion_1, //!< common version 1.0
ApiVersion_1_DDEL, //!< version 1.0, "Accept: application/vnd.ddel.v1"
ApiVersion_1_1_DDEL, //!< version 1.1, "Accept: application/vnd.ddel.v1.1"
ApiVersion_2_DDEL, //!< version 2.0, "Accept: application/vnd.ddel.v2"
ApiVersion_3_DDEL //!< version 3.0, "Accept: application/vnd.ddel.v3"
};
enum ApiAuthorisation
{
ApiAuthNone,
ApiAuthLocal,
ApiAuthInternal,
ApiAuthFull
};