forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_web_plugin_private.h
1889 lines (1718 loc) · 68.9 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-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.
*
*/
#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>
#if QT_VERSION < 0x050000
#include <QHttpRequestHeader>
#endif
#include <sqlite3.h>
#include <deconz.h>
#include "resource.h"
#include "daylight.h"
#include "event.h"
#include "resource.h"
#include "rest_node_base.h"
#include "light_node.h"
#include "group.h"
#include "group_info.h"
#include "scene.h"
#include "sensor.h"
#include "resourcelinks.h"
#include "rule.h"
#include "bindings.h"
#include <math.h>
#include "websocket_server.h"
/*! 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_MODIFIEABLE 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_BRIDGE_GROUP_TABLE_FULL 301
#define ERR_DEVICE_GROUP_TABLE_FULL 302
#define ERR_DEVICE_SCENES_TABLE_FULL 402 // de extension
#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 MAX_UNLOCK_GATEWAY_TIME 600
#define MAX_RECOVER_ENTRY_AGE 600
#define PERMIT_JOIN_SEND_INTERVAL (1000 * 1800)
#define EXT_PROCESS_TIMEOUT 10000
#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
//
#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 OTAU_CLUSTER_ID 0x0019
#define POLL_CONTROL_CLUSTER_ID 0x0020
#define GREEN_POWER_CLUSTER_ID 0x0021
#define DOOR_LOCK_CLUSTER_ID 0x0101
#define WINDOW_COVERING_CLUSTER_ID 0x0102
#define THERMOSTAT_CLUSTER_ID 0x0201
#define FAN_CONTROL_CLUSTER_ID 0x0202
#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 IAS_ZONE_CLUSTER_ID 0x0500
#define IAS_WD_CLUSTER_ID 0x0502
#define METERING_CLUSTER_ID 0x0702
#define ELECTRICAL_MEASUREMENT_CLUSTER_ID 0x0B04
#define COMMISSIONING_CLUSTER_ID 0x1000
#define DE_CLUSTER_ID 0xFC00
#define VENDOR_CLUSTER_ID 0xFC00
#define UBISYS_DEVICE_SETUP_CLUSTER_ID 0xFC00
#define SAMJIN_CLUSTER_ID 0xFC02
#define LEGRAND_CONTROL_CLUSTER_ID 0xFC40
#define XAL_CLUSTER_ID 0xFCCE
#define IAS_ZONE_CLUSTER_ATTR_ZONE_STATUS_ID 0x0002
#define GREEN_POWER_ENDPOINT 0xf2
#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
// 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
// read 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 READ_GROUP_IDENTIFIERS (1 << 12)
#define READ_MODE_CONFIG (1 << 13)
#define READ_THERMOSTAT_STATE (1 << 17)
#define READ_BATTERY (1 << 18)
#define READ_MODEL_ID_INTERVAL (60 * 60) // s
#define READ_SWBUILD_ID_INTERVAL (60 * 60) // s
// write flags
#define WRITE_OCCUPANCY_CONFIG (1 << 11)
#define WRITE_DELAY (1 << 13)
#define WRITE_LEDINDICATION (1 << 14)
#define WRITE_SENSITIVITY (1 << 15)
#define WRITE_USERTEST (1 << 16)
// 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_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_4_NOKS 0x1071
#define VENDOR_BITRON 0x1071 // branded
#define VENDOR_COMPUTIME 0x1078
#define VENDOR_NETVOX 0x109F
#define VENDOR_NYCE 0x10B9
#define VENDOR_UBISYS 0x10F2
#define VENDOR_BEGA 0x1105
#define VENDOR_PHYSICAL 0x110A // Used by SmartThings
#define VENDOR_OSRAM 0x110C
#define VENDOR_PROFALUX 0x1110
#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_LUTRON 0x1144
#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_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_HEIMAN 0x120B
#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 ...
#define VENDOR_XAL 0x122A
#define VENDOR_THIRD_REALITY 0x1233
#define VENDOR_DSR 0x1234
#define VENDOR_HANGZHOU_IMAGIC 0x123B
#define VENDOR_SAMJIN 0x1241
#define VENDOR_KONKE 0x1268
#define VENDOR_OSRAM_STACK 0xBBAA
#define VENDOR_C2DF 0xC2DF
#define ANNOUNCE_INTERVAL 10 // 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 32
#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 (5 * 1 * 1000) // 5 seconds
#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
extern const quint64 macPrefixMask;
extern const quint64 celMacPrefix;
extern const quint64 bjeMacPrefix;
extern const quint64 deMacPrefix;
extern const quint64 emberMacPrefix;
extern const quint64 energyMiMacPrefix;
extern const quint64 heimanMacPrefix;
extern const quint64 ikeaMacPrefix;
extern const quint64 ikea2MacPrefix;
extern const quint64 silabsMacPrefix;
extern const quint64 silabs2MacPrefix;
extern const quint64 silabs3MacPrefix;
extern const quint64 silabs4MacPrefix;
extern const quint64 instaMacPrefix;
extern const quint64 boschMacPrefix;
extern const quint64 jennicMacPrefix;
extern const quint64 keenhomeMacPrefix;
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 develcoMacPrefix;
extern const quint64 legrandMacPrefix;
extern const quint64 profaluxMacPrefix;
extern const quint64 xiaomiMacPrefix;
extern const quint64 computimeMacPrefix;
extern const quint64 konkeMacPrefix;
extern const quint64 ecozyMacPrefix;
extern const quint64 zhejiangMacPrefix;
inline bool checkMacVendor(quint64 addr, quint16 vendor)
{
const quint64 prefix = addr & macPrefixMask;
switch (vendor) {
case VENDOR_XIAOMI:
return prefix == jennicMacPrefix ||
prefix == xiaomiMacPrefix;
case VENDOR_SINOPE:
return prefix == sinopeMacPrefix;
case VENDOR_HEIMAN:
return prefix == emberMacPrefix ||
prefix == jennicMacPrefix;
case VENDOR_SUNRICHER:
return prefix == emberMacPrefix ||
prefix == silabs2MacPrefix;
case VENDOR_ALERTME:
return prefix == tiMacPrefix;
case VENDOR_BITRON:
return prefix == tiMacPrefix;
case VENDOR_BOSCH:
return prefix == boschMacPrefix ||
prefix == emberMacPrefix;
case VENDOR_BUSCH_JAEGER:
return prefix == bjeMacPrefix;
case VENDOR_CENTRALITE:
return prefix == emberMacPrefix;
case VENDOR_EMBER:
return prefix == emberMacPrefix ||
prefix == konkeMacPrefix ||
prefix == silabs3MacPrefix;
case VENDOR_DDEL:
return prefix == deMacPrefix ||
prefix == silabs3MacPrefix;
case VENDOR_IKEA:
return prefix == ikeaMacPrefix ||
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 == silabs2MacPrefix;
case VENDOR_INSTA:
return prefix == instaMacPrefix;
case VENDOR_JENNIC:
return prefix == jennicMacPrefix ||
prefix == silabs2MacPrefix;
case VENDOR_KEEN_HOME:
return prefix == keenhomeMacPrefix;
case VENDOR_LGE:
return prefix == emberMacPrefix;
case VENDOR_LUTRON:
return prefix == lutronMacPrefix;
case VENDOR_NYCE:
return prefix == emberMacPrefix;
case VENDOR_OSRAM:
case VENDOR_OSRAM_STACK:
return prefix == osramMacPrefix ||
prefix == heimanMacPrefix;
case VENDOR_PHILIPS:
return prefix == philipsMacPrefix;
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 == ikeaMacPrefix; // belongs to SiLabs
case VENDOR_STELPRO:
return prefix == xalMacPrefix;
case VENDOR_UBISYS:
return prefix == ubisysMacPrefix;
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;
default:
return false;
}
}
inline bool checkMacVendor(const deCONZ::Address &addr, quint16 vendor)
{
return checkMacVendor(addr.ext(), vendor);
}
// 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 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
};
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"
};
enum ApiAuthorisation
{
ApiAuthNone,
ApiAuthLocal,
ApiAuthInternal,
ApiAuthFull
};
enum ApiMode
{
ApiModeNormal,
ApiModeStrict,
ApiModeEcho,
ApiModeHue
};
/*! \class ApiRequest
Helper to simplify HTTP REST request handling.
*/
class ApiRequest
{
public:
ApiRequest(const QHttpRequestHeader &h, const QStringList &p, QTcpSocket *s, const QString &c);
QString apikey() const;
ApiVersion apiVersion() const { return version; }
const QHttpRequestHeader &hdr;
const QStringList &path;
QTcpSocket *sock;
QString content;
ApiVersion version;
ApiAuthorisation auth;
ApiMode mode;
};
/*! \class ApiResponse
Helper to simplify HTTP REST request handling.
*/
struct ApiResponse
{
QString etag;
const char *httpStatus;
const char *contentType;
QList<QPair<QString, QString> > hdrFields; // extra header fields
QVariantMap map; // json content
QVariantList list; // json content
QString str; // json string
};
/*! \class ApiConfig
Provide config to the resource system.
*/
class ApiConfig : public Resource
{
public:
ApiConfig();
};
class TcpClient
{
public:
QHttpRequestHeader hdr;
QDateTime created;
int closeTimeout; // close socket in n seconds
QTcpSocket *sock;
};
/*! \class DeWebPluginPrivate
Pimpl of DeWebPlugin.
*/
class DeRestPluginPrivate : public QObject
{
Q_OBJECT
public:
struct nodeVisited {
const deCONZ::Node* node;
bool visited;
};
DeRestPluginPrivate(QObject *parent = 0);
~DeRestPluginPrivate();
// REST API authorisation
void initAuthentication();
bool allowedToCreateApikey(const ApiRequest &req, ApiResponse &rsp, QVariantMap &map);
void authorise(ApiRequest &req, ApiResponse &rsp);
QString encryptString(const QString &str);
// REST API gateways
int handleGatewaysApi(const ApiRequest &req, ApiResponse &rsp);
int getAllGateways(const ApiRequest &req, ApiResponse &rsp);
int getGatewayState(const ApiRequest &req, ApiResponse &rsp);
int setGatewayState(const ApiRequest &req, ApiResponse &rsp);
int addCascadeGroup(const ApiRequest &req, ApiResponse &rsp);
int deleteCascadeGroup(const ApiRequest &req, ApiResponse &rsp);
void gatewayToMap(const ApiRequest &req, const Gateway *gw, QVariantMap &map);
// REST API configuration
void initConfig();
int handleConfigBasicApi(const ApiRequest &req, ApiResponse &rsp);
int handleConfigLocalApi(const ApiRequest &req, ApiResponse &rsp);
int handleConfigFullApi(const ApiRequest &req, ApiResponse &rsp);
int createUser(const ApiRequest &req, ApiResponse &rsp);
int getFullState(const ApiRequest &req, ApiResponse &rsp);
int getConfig(const ApiRequest &req, ApiResponse &rsp);
int getBasicConfig(const ApiRequest &req, ApiResponse &rsp);
int getZigbeeConfig(const ApiRequest &req, ApiResponse &rsp);
int putZigbeeConfig(const ApiRequest &req, ApiResponse &rsp);
int getChallenge(const ApiRequest &req, ApiResponse &rsp);
int modifyConfig(const ApiRequest &req, ApiResponse &rsp);
int deleteUser(const ApiRequest &req, ApiResponse &rsp);
int updateSoftware(const ApiRequest &req, ApiResponse &rsp);
int restartGateway(const ApiRequest &req, ApiResponse &rsp);
int restartApp(const ApiRequest &req, ApiResponse &rsp);
int shutDownGateway(const ApiRequest &req, ApiResponse &rsp);
int updateFirmware(const ApiRequest &req, ApiResponse &rsp);
int exportConfig(const ApiRequest &req, ApiResponse &rsp);
int importConfig(const ApiRequest &req, ApiResponse &rsp);
int resetConfig(const ApiRequest &req, ApiResponse &rsp);
int changePassword(const ApiRequest &req, ApiResponse &rsp);
int deletePassword(const ApiRequest &req, ApiResponse &rsp);
int getWifiState(const ApiRequest &req, ApiResponse &rsp);
int configureWifi(const ApiRequest &req, ApiResponse &rsp);
int restoreWifiConfig(const ApiRequest &req, ApiResponse &rsp);
int putWifiScanResult(const ApiRequest &req, ApiResponse &rsp);
int putWifiUpdated(const ApiRequest &req, ApiResponse &rsp);
int putHomebridgeUpdated(const ApiRequest &req, ApiResponse &rsp);
void configToMap(const ApiRequest &req, QVariantMap &map);
void basicConfigToMap(QVariantMap &map);
// REST API userparameter
int handleUserparameterApi(const ApiRequest &req, ApiResponse &rsp);
int createUserParameter(const ApiRequest &req, ApiResponse &rsp);
int addUserParameter(const ApiRequest &req, ApiResponse &rsp);
int modifyUserParameter(const ApiRequest &req, ApiResponse &rsp);
int getUserParameter(const ApiRequest &req, ApiResponse &rsp);
int getAllUserParameter(const ApiRequest &req, ApiResponse &rsp);
int deleteUserParameter(const ApiRequest &req, ApiResponse &rsp);
// REST API lights
int handleLightsApi(const ApiRequest &req, ApiResponse &rsp);
int getAllLights(const ApiRequest &req, ApiResponse &rsp);
int searchNewLights(const ApiRequest &req, ApiResponse &rsp);
int getNewLights(const ApiRequest &req, ApiResponse &rsp);
int getLightData(const ApiRequest &req, ApiResponse &rsp);
int getLightState(const ApiRequest &req, ApiResponse &rsp);
int setLightState(const ApiRequest &req, ApiResponse &rsp);
int setWindowCoveringState(const ApiRequest &req, ApiResponse &rsp, TaskItem &taskRef, QVariantMap &map);
int setWarningDeviceState(const ApiRequest &req, ApiResponse &rsp, TaskItem &taskRef, QVariantMap &map);
int setLightAttributes(const ApiRequest &req, ApiResponse &rsp);
int deleteLight(const ApiRequest &req, ApiResponse &rsp);
int removeAllScenes(const ApiRequest &req, ApiResponse &rsp);
int removeAllGroups(const ApiRequest &req, ApiResponse &rsp);
int getConnectivity(const ApiRequest &req, ApiResponse &rsp, bool alt);
void handleLightEvent(const Event &e);
bool lightToMap(const ApiRequest &req, const LightNode *webNode, QVariantMap &map);
// REST API groups
int handleGroupsApi(const ApiRequest &req, ApiResponse &rsp);
int getAllGroups(const ApiRequest &req, ApiResponse &rsp);
int createGroup(const ApiRequest &req, ApiResponse &rsp);
int getGroupAttributes(const ApiRequest &req, ApiResponse &rsp);
int setGroupAttributes(const ApiRequest &req, ApiResponse &rsp);
int setGroupState(const ApiRequest &req, ApiResponse &rsp);
int deleteGroup(const ApiRequest &req, ApiResponse &rsp);
void handleGroupEvent(const Event &e);
Group *addGroup();
// REST API groups > scenes
int createScene(const ApiRequest &req, ApiResponse &rsp);
int getAllScenes(const ApiRequest &req, ApiResponse &rsp);
int getSceneAttributes(const ApiRequest &req, ApiResponse &rsp);
int setSceneAttributes(const ApiRequest &req, ApiResponse &rsp);
int storeScene(const ApiRequest &req, ApiResponse &rsp);
int recallScene(const ApiRequest &req, ApiResponse &rsp);
int modifyScene(const ApiRequest &req, ApiResponse &rsp);
int deleteScene(const ApiRequest &req, ApiResponse &rsp);
bool groupToMap(const ApiRequest &req, const Group *group, QVariantMap &map);
// REST API schedules
void initSchedules();
int handleSchedulesApi(const ApiRequest &req, ApiResponse &rsp);
int getAllSchedules(const ApiRequest &req, ApiResponse &rsp);
int createSchedule(const ApiRequest &req, ApiResponse &rsp);
int getScheduleAttributes(const ApiRequest &req, ApiResponse &rsp);
int setScheduleAttributes(const ApiRequest &req, ApiResponse &rsp);
int deleteSchedule(const ApiRequest &req, ApiResponse &rsp);
bool jsonToSchedule(const QString &jsonString, Schedule &schedule, ApiResponse *rsp);
// REST API touchlink
void initTouchlinkApi();
int handleTouchlinkApi(const ApiRequest &req, ApiResponse &rsp);
int touchlinkScan(const ApiRequest &req, ApiResponse &rsp);