xm
2020-07-20 b02e8275a21dc06bf54b66273485d44e007a2616
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.UserCenter.Device;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
using static ZigBee.Device.Panel;
 
namespace Shared.Phone.UserCenter.DeviceBind
{
    public class BindInfo
    {
        #region 绑定设计的变量定义
        /// <summary>
        /// 当前设备绑定类型
        /// </summary>
        public enum BindType
        {
            /// <summary>
            /// 新风
            /// </summary>
            FreshAir = 1,
            /// <summary>
            /// 温度传感器
            /// </summary>
            Temperature = 2,
            /// <summary>
            /// 湿度传感器
            /// </summary>
            Humidity = 3,
            /// <summary>
            /// PM2.5传感器
            /// </summary>
            PM = 4,
            /// <summary>
            /// 空调目标
            /// </summary>
            AC = 5,
        }
 
        #endregion
 
        #region 绑定涉及的数据处理
        /// <summary>
        /// 获取当前楼层名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentKeyAllRoomList()
        {
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return dicFloor[floorId];
                break;
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentSelectFloorId()
        {
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();//
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return floorId;
                break;
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentSelectFloorIdName()
        {
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return dicFloor[floorId];
                break;
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层名称
        /// fllodID:楼层ID
        /// </summary>
        /// <returns></returns>
        public static string GetBindTargetsFloorIdName(string curFllodID)
        {
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            foreach (var floorId in dicFloor.Keys)
            {
                //当前楼层
                if (curFllodID == floorId)
                {
                    return dicFloor[floorId];
                    break;
                }
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前房间中匹配的支持绑定的设备列表
        /// currentRoomSupportBindDeviceList 当前房间中支持被绑定的设备列表
        /// curRoom 当前房间
        /// curDeviceBindType 当前设备绑定类型
        /// </summary>
        /// <returns></returns>
        public static List<CommonDevice> GetCurRoomSupportDeviceList(List<CommonDevice> currentRoomSupportBindDeviceList, Room curRoom, BindInfo.BindType curDeviceBindType)
        {
            currentRoomSupportBindDeviceList.Clear();
            List<CommonDevice> curRoomDeviceListTemp = new List<CommonDevice>();
            switch (curDeviceBindType)
            {
                case BindType.FreshAir:
                    foreach (var deviceKeys in curRoom.ListDevice)
                    {
                        var device = LocalDevice.Current.GetDevice(deviceKeys);
                        if (device != null)
                        {
                            if (BindInfo.checkRealFreshAirDevice(device) == false)
                            {
                                continue;
                            }
                            if (device.Type == DeviceType.FreshAir)
                            {
                                curRoomDeviceListTemp.Add(device);
                            }
                        }
                    }
                    break;
                case BindType.Temperature:
                    curRoomDeviceListTemp = GetMatchTemperatureSensorDevice(curRoom);
                    break;
                case BindType.Humidity:
                    curRoomDeviceListTemp = GetMatchHumiditySensorDevice(curRoom);
                    foreach (var deviceKeys in curRoom.ListDevice)
                    {
                        var device = LocalDevice.Current.GetDevice(deviceKeys);
                        if (device != null)
                        {
                            if (device.Type == DeviceType.FreshAirHumiditySensor)
                            {
                                curRoomDeviceListTemp.Add(device);
                            }
                        }
                    }
                    break;
                case BindType.PM:
                    foreach (var deviceKeys in curRoom.ListDevice)
                    {
                        var device = LocalDevice.Current.GetDevice(deviceKeys);
                        if (device != null)
                        {
                            if (device.Type == DeviceType.PMSensor)
                            {
                                curRoomDeviceListTemp.Add(device);
                            }
                        }
                    }
                    break;
                case BindType.AC:
                    foreach (var deviceKeys in curRoom.ListDevice)
                    {
                        var device = LocalDevice.Current.GetDevice(deviceKeys);
                        if (device != null)
                        {
                            if (device.Type == DeviceType.Thermostat)
                            {
                                if (BindInfo.checkRealAcDevice(device) == false)
                                {
                                    continue;
                                }
                                curRoomDeviceListTemp.Add(device);
                            }
                        }
                    }
                    break;
            }
            return curRoomDeviceListTemp;
        }
 
        /// <summary>
        /// 匹配温度传感器
        /// </summary>
        /// <param name="room"></param>
        public static List<CommonDevice> GetMatchTemperatureSensorDevice(Room room)
        {
            List<CommonDevice> roomIncludeMatchTempDevice = new List<CommonDevice>();
            foreach (var de in room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(de);
                if (device != null)
                {
                    //电池设备不支持绑定
                    if (device.ZigbeeType != 1)
                    {
                        continue;
                    }
                    if (device.Type == DeviceType.TemperatureSensor)
                    {
                        var dev = device as TemperatureSensor;
                        if (dev.SensorDiv == 1)
                        {
                            roomIncludeMatchTempDevice.Add(device);
                        }
                    }
                    else if (device.Type == DeviceType.PMSensor)
                    {
                        var dev = device as PMSensor;
                        foreach (var clu in dev.InClusterList)
                        {
                            if (clu.InCluster == 1026)
                            {
                                roomIncludeMatchTempDevice.Add(device);
                            }
                        }
                    }
                }
            }
            return roomIncludeMatchTempDevice;
        }
 
        /// <summary>
        /// 匹配湿度传感器
        /// </summary>
        /// <param name="room"></param>
        public static List<CommonDevice> GetMatchHumiditySensorDevice(Room room)
        {
            List<CommonDevice> roomIncludeMatchHumpDevice = new List<CommonDevice>();
            foreach (var de in room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(de);
                if (device != null)
                {
                    //电池设备不支持绑定
                    if (device.ZigbeeType != 1)
                    {
                        continue;
                    }
                    if (device.Type == DeviceType.TemperatureSensor)
                    {
                        var dev = device as TemperatureSensor;
                        if (dev.SensorDiv == 2)
                        {
                            roomIncludeMatchHumpDevice.Add(device);
                        }
                    }
                    else if (device.Type == DeviceType.PMSensor)
                    {
                        var dev = device as PMSensor;
                        foreach (var clu in dev.InClusterList)
                        {
                            if (clu.InCluster == 1029)
                            {
                                roomIncludeMatchHumpDevice.Add(device);
                            }
                        }
                    }
                }
            }
            return roomIncludeMatchHumpDevice;
        }
 
        /// <summary>
        /// 获取支持的房间列表
        /// </summary>
        /// <returns></returns>
        public static List<Room> GetSupportRoomList()
        {
            var supportRoomListTemp = new List<Room>();
            var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
            if (Common.Config.Instance.Home.FloorDics.Count == 0)
            {
                // 获取没有楼层房间
                foreach (var room in listAllRoom)
                {
                    if (string.IsNullOrEmpty(room.FloorId))
                    {
                        if (room.IsLove)
                        {
                            continue;
                        }
                        supportRoomListTemp.Add(room);
                    }
                }
            }
            else
            {
                // 获取支持的房间
                foreach (var room in listAllRoom)
                {
                    if (room.IsLove)
                    {
                        continue;
                    }
                    supportRoomListTemp.Add(room);
                }
            }
            return supportRoomListTemp;
        }
 
        /// <summary>
        /// 能显示的房间列表
        /// curControlDev 控制设备
        /// supportRoomList 本地房间列表
        /// curDeviceBindType 当前设备绑定类型
        /// </summary>
        public static List<Room> GetSupportRoomList(Panel curControlDev, List<Room> supportRoomList, BindInfo.BindType curDeviceBindType)
        {
            var roomTempList = new List<Room>();
            for (int i = 0; i < supportRoomList.Count; i++)
            {
                var room = supportRoomList[i];
                //如果房间为喜爱[后来改名为常用房间],则不显示
                if (room.IsLove == true)
                {
                    continue;
                }
 
                //如果房间中没有设备,则不显示
                if (room.ListDevice.Count == 0)
                {
                    continue;
                }
                else
                {
                    List<CommonDevice> roomIncludeMatchDevice = new List<CommonDevice>();
 
                    //房间中没有对应的支持绑定的目标
                    switch (curDeviceBindType)
                    {
                        case BindInfo.BindType.FreshAir:
                            foreach (var de in room.ListDevice)
                            {
                                var device = LocalDevice.Current.GetDevice(de);
                                if (device != null)
                                {
                                    if (BindInfo.checkRealFreshAirDevice(device) == false)
                                    {
                                        continue;
                                    }
                                    if (device.Type == DeviceType.FreshAir)
                                    {
                                        roomIncludeMatchDevice.Add(device);
                                    }
                                }
                            }
                            break;
                        case BindInfo.BindType.Temperature:
                            roomIncludeMatchDevice = BindInfo.GetMatchTemperatureSensorDevice(room);
                            break;
                        case BindInfo.BindType.Humidity:
                            roomIncludeMatchDevice = GetMatchHumiditySensorDevice(room);
                            foreach (var de in room.ListDevice)
                            {
                                var device = LocalDevice.Current.GetDevice(de);
                                if (device != null)
                                {
                                    if (device.Type == DeviceType.FreshAirHumiditySensor)
                                    {
                                        roomIncludeMatchDevice.Add(device);
                                    }
                                }
                            }
                            break;
                        case BindInfo.BindType.PM:
                            foreach (var de in room.ListDevice)
                            {
                                var device = LocalDevice.Current.GetDevice(de);
                                if (device != null)
                                {
                                    if (device.Type == DeviceType.PMSensor)
                                    {
                                        roomIncludeMatchDevice.Add(device);
                                    }
                                }
                            }
                            break;
                        case BindInfo.BindType.AC:
                            foreach (var de in room.ListDevice)
                            {
                                var device = LocalDevice.Current.GetDevice(de);
                                if (device != null)
                                {
                                    if (device.Type == DeviceType.Thermostat)
                                    {
                                        if (BindInfo.checkRealAcDevice(device) == false)
                                        {
                                            continue;
                                        }
                                        roomIncludeMatchDevice.Add(device);
                                    }
                                }
                            }
                            break;
                    }
 
                    if (roomIncludeMatchDevice.Count == 0)
                    {
                        continue;
                    }
 
                    if (!string.IsNullOrEmpty(room.FloorId))
                    {
                        //有楼层
                        if (room.FloorId == curControlDev.currentSelectFloorId)
                        {
                            roomTempList.Add(room);
                        }
                    }
                    else
                    {
                        //没有楼层
                        roomTempList.Add(room);
                    }
                }
            }
            return roomTempList;
        }
 
        /// <summary>
        /// 获取本地未分配的支持当前类型的绑定设备列表
        /// </summary>
        /// <returns></returns>
        public static List<CommonDevice> GetUndistributeDeviceList(List<CommonDevice> undistruibuteDevList, DeviceBind.BindInfo.BindType curDeviceBindType)
        {
            undistruibuteDevList.Clear();
            List<CommonDevice> UndistributeCommonDeviceListTemp = new List<CommonDevice>();
 
            //获取本地设备列表
            foreach (var tempDev in Shared.Common.LocalDevice.Current.listAllDevice)
            {
                //获取设备所属房间
                var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
                if (tempDevRoom == null)
                {
                    UndistributeCommonDeviceListTemp.Add(tempDev);
                }
            }
            switch (curDeviceBindType)
            {
                case BindType.FreshAir:
                    foreach (var device in UndistributeCommonDeviceListTemp)
                    {
                        if (BindInfo.checkRealFreshAirDevice(device) == false)
                        {
                            continue;
                        }
                        if (device.Type == DeviceType.FreshAir)
                        {
                            undistruibuteDevList.Add(device);
                        }
                    }
                    break;
                case BindType.Temperature:
                    foreach (var device in UndistributeCommonDeviceListTemp)
                    {
                        //电池设备不支持绑定
                        if (device.ZigbeeType != 1)
                        {
                            continue;
                        }
                        if (device.Type == DeviceType.TemperatureSensor)
                        {
                            var dev = device as TemperatureSensor;
                            if (dev.SensorDiv == 1)
                            {
                                undistruibuteDevList.Add(device);
                            }
                        }
                        else if (device.Type == DeviceType.PMSensor)
                        {
                            var dev = device as PMSensor;
                            foreach (var clu in dev.InClusterList)
                            {
                                if (clu.InCluster == 1026)
                                {
                                    undistruibuteDevList.Add(device);
                                }
                            }
                        }
                    }
                    break;
                case BindType.Humidity:
                    foreach (var device in UndistributeCommonDeviceListTemp)
                    {
                        //电池设备不支持绑定
                        if (device.ZigbeeType != 1)
                        {
                            continue;
                        }
                        if (device.Type == DeviceType.TemperatureSensor)
                        {
                            var dev = device as TemperatureSensor;
                            if (dev.SensorDiv == 2)
                            {
                                undistruibuteDevList.Add(device);
                            }
                        }
                        else if (device.Type == DeviceType.PMSensor)
                        {
                            var dev = device as PMSensor;
                            foreach (var clu in dev.InClusterList)
                            {
                                if (clu.InCluster == 1029)
                                {
                                    undistruibuteDevList.Add(device);
                                }
                            }
                        }
                        if (device.Type == DeviceType.FreshAirHumiditySensor)
                        {
                            undistruibuteDevList.Add(device);
                        }
                    }
                    break;
                case BindType.PM:
                    foreach (var device in UndistributeCommonDeviceListTemp)
                    {
                        if (device.Type == DeviceType.PMSensor)
                        {
                            undistruibuteDevList.Add(device);
                        }
                    }
                    break;
                case BindType.AC:
                    foreach (var device in UndistributeCommonDeviceListTemp)
                    {
                        if (device.Type == DeviceType.Thermostat)
                        {
                            if (BindInfo.checkRealAcDevice(device) == false)
                            {
                                continue;
                            }
                            undistruibuteDevList.Add(device);
                        }
                    }
                    break;
            }
 
            return undistruibuteDevList;
        }
 
        /// <summary>
        /// 所有房间中匹配的支持绑定的所有目标列表
        /// </summary>
        /// <returns></returns>
        public static List<CommonDevice> GetAllRoomSupportDeviceList(List<CommonDevice> currentPanelSupportBindDeviceList, List<Room> supportRoomList, DeviceBind.BindInfo.BindType curDeviceBindType)
        {
            currentPanelSupportBindDeviceList.Clear();
            List<CommonDevice> currentPanelBindSupportDeviceListTemp = new List<CommonDevice>();
            switch (curDeviceBindType)
            {
                case BindInfo.BindType.FreshAir:
                    foreach (var r in supportRoomList)
                    {
                        if (r.ListDevice.Count == 0)
                        {
                            continue;
                        }
                        foreach (var deviceKeys in r.ListDevice)
                        {
                            var device = LocalDevice.Current.GetDevice(deviceKeys);
                            if (device != null)
                            {
                                if (BindInfo.checkRealFreshAirDevice(device) == false)
                                {
                                    continue;
                                }
                                if (device.Type == DeviceType.FreshAir)
                                {
                                    currentPanelBindSupportDeviceListTemp.Add(device);
                                }
                            }
                        }
                    }
                    break;
                case BindInfo.BindType.Temperature:
                    foreach (var r in supportRoomList)
                    {
                        if (r.ListDevice.Count == 0)
                        {
                            continue;
                        }
                        var deviceListTemp = GetMatchTemperatureSensorDevice(r);
                        foreach (var dev in deviceListTemp)
                        {
                            currentPanelBindSupportDeviceListTemp.Add(dev);
                        }
                    }
                    break;
                case BindInfo.BindType.Humidity:
                    foreach (var r in supportRoomList)
                    {
                        if (r.ListDevice.Count == 0)
                        {
                            continue;
                        }
                        var deviceListTemp = GetMatchHumiditySensorDevice(r);
                        foreach (var dev in deviceListTemp)
                        {
                            currentPanelBindSupportDeviceListTemp.Add(dev);
                        }
                        foreach (var deviceKeys in r.ListDevice)
                        {
                            var device = LocalDevice.Current.GetDevice(deviceKeys);
                            if (device != null)
                            {
                                if (device.Type == DeviceType.FreshAirHumiditySensor)
                                {
                                    currentPanelBindSupportDeviceListTemp.Add(device);
                                }
                            }
                        }
                    }
                    break;
                case BindInfo.BindType.PM:
                    foreach (var r in supportRoomList)
                    {
                        if (r.ListDevice.Count == 0)
                        {
                            continue;
                        }
                        foreach (var deviceKeys in r.ListDevice)
                        {
                            var device = LocalDevice.Current.GetDevice(deviceKeys);
                            if (device != null)
                            {
                                if (device.Type == DeviceType.PMSensor)
                                {
                                    currentPanelBindSupportDeviceListTemp.Add(device);
                                }
                            }
                        }
                    }
                    break;
                case BindInfo.BindType.AC:
                    foreach (var r in supportRoomList)
                    {
                        if (r.ListDevice.Count == 0)
                        {
                            continue;
                        }
                        foreach (var deviceKeys in r.ListDevice)
                        {
                            var device = LocalDevice.Current.GetDevice(deviceKeys);
                            if (device != null)
                            {
                                if (device.Type == DeviceType.Thermostat)
                                {
                                    if (BindInfo.checkRealAcDevice(device) == false)
                                    {
                                        continue;
                                    }
                                    currentPanelBindSupportDeviceListTemp.Add(device);
                                }
                            }
                        }
                    }
                    break;
            }
            return currentPanelBindSupportDeviceListTemp;
        }
 
        /// <summary>
        /// 检测目标是否被绑定过
        /// targetList 按键配置的目标列表
        /// oldTargetList 面板中已经存在的目标列表
        /// </summary>
        /// <returns></returns>
        public static bool checkExistDevice(List<CommonDevice> targetList, List<CommonDevice> oldTargetList)
        {
            bool exist = false;
            foreach (var oldDev in oldTargetList)
            {
                var key = oldDev.DeviceAddr + oldDev.DeviceEpoint;
                var result = targetList.Find(obj => (obj != null) && (obj.DeviceAddr + obj.DeviceEpoint == key));
                if (result != null)
                {
                    exist = true;
                }
                else
                {
                    exist = false;
                }
            }
            return exist;
        }
 
        /// <summary>
        /// 是否是真实的空调设备 【部分是能绑定空调的设备】 
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool checkRealAcDevice(CommonDevice device)
        {
            bool result = true;
            //获取设备类型的
            var clu = device.OutClusterList.Find((obj) => obj.OutCluster == 513 || obj.OutCluster == 514);
            if (clu != null)
            {
                result = false;
            }
            return result;
        }
 
        /// <summary>
        /// 是否是真实的新风设备 【部分是能绑定新风的设备】 
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool checkRealFreshAirDevice(CommonDevice device)
        {
            bool result = true;
            //获取设备类型的
            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir)
            {
                result = false;
            }
            if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_SimpleEnvironment)
            {
                result = false;
            }
            return result;
        }
 
        /// <summary>
        /// 检测该设备能否显示
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool CheckCanShowDevice(ZigBee.Device.CommonDevice device, string curDeviceBindType = "AddSwitch")
        {
            if (device == null)
            {
                return false;
            }
            //如果是传感器,或者是没有开关簇的话(这里判断的是输入簇)
            if ((device.Type == ZigBee.Device.DeviceType.IASZone) || InMatchDevice(device, curDeviceBindType) == false)
            {
                return false;
            }
            return true;
        }
 
        /// <summary>
        /// 检测该房间能否显示
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public static bool CheckCanShowRoom(Common.Room room, string curDeviceBindType = "AddSwitch")
        {
            if (room.ListDevice.Count == 0)
            {
                return false;
            }
            if (room.IsLove == true)
            {
                return false;
            }
            foreach (var deviceKeys in room.ListDevice)
            {
                var device = Common.LocalDevice.Current.GetDevice(deviceKeys);
                //检测该设备能否显示
                if (CheckCanShowDevice(device, curDeviceBindType) == false)
                {
                    continue;
                }
 
                //存在设备的话,此房间可以显示
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 检测设备是否拥有开关的功能(输入簇)
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool InMatchDevice(CommonDevice device, string curDeviceBindType = "AddSwitch")
        {
            foreach (var data in device.InClusterList)
            {
                switch (curDeviceBindType)
                {
                    case "AddSwitch":
                        //拥有on/off功能的,才支持测试
                        if (data.InCluster == 6)
                        {
                            return true;
                        }
                        break;
                    case "AddDimmer":
                        if (data.InCluster == 8)
                        {
                            return true;
                        }
                        break;
                    case "AddCurtain":
                        if (data.InCluster == 258)
                        {
                            return true;
                        }
                        break;
                }
            }
            return false;
        }
 
        /// <summary>
        ///  检测控制面板(按键类)所拥有的功能,现支持的有以下几种(必定存在键值,出错会返回null)
        /// </summary>
        /// <returns>The panel key function level2.</returns>
        /// <param name="key">Key.</param>
        public static async System.Threading.Tasks.Task<Dictionary<string, bool>> CheckPanelKeyFunctionLevel3(Panel key)
        {
            Dictionary<string, bool> dicCheck = new Dictionary<string, bool>();
            dicCheck["场景:触发"] = false;
            dicCheck["开关:开"] = false;
            dicCheck["开关:关"] = false;
            dicCheck["开关:切换"] = false;
            dicCheck["亮度:按等级调大"] = false;
            dicCheck["亮度:按等级调小"] = false;
            dicCheck["亮度:按等级切换"] = false;
            dicCheck["亮度:打开"] = false;
            dicCheck["亮度:关闭"] = false;
            dicCheck["亮度:切换"] = false;
            dicCheck["窗帘:开"] = false;
            dicCheck["窗帘:关"] = false;
            dicCheck["窗帘:停"] = false;
            dicCheck["窗帘:上升停"] = false;
            dicCheck["窗帘:下降停"] = false;
 
 
            List<int> result = null;
            //获取第一级功能
            if (key.privateFuncFirstLevelList.Count == 0 || key.privateFuncFirstLevelList.Contains(256) == false)
            {
                result = await key.GetPanelDeviceFunctionLevel1();
                if (result == null)
                {
                    return null;
                }
                key.privateFuncFirstLevelList = result;
                //面板没有按键类
                if (result.Contains(256) == false)
                {
                    return dicCheck;
                }
            }
            else
            {
                result = key.privateFuncFirstLevelList;
            }
 
            if (key.privateFuncSecondLevelList.Count == 0 || key.privateFuncSecondLevelList.Contains(1) == false || key.privateFuncSecondLevelList.Contains(100) == false || key.privateFuncSecondLevelList.Contains(200) == false || key.privateFuncSecondLevelList.Contains(300) == false)
            {
                //获取第二级功能
                result = await key.GetPanelDeviceFunctionLevel2(256);
                if (result == null)
                {
                    return null;
                }
                key.privateFuncSecondLevelList = result;
            }
            else
            {
                result = key.privateFuncSecondLevelList;
            }
 
            //特殊功能
            if (result.Contains(1) == true)
            {
                List<int> result3 = null;
                //获取第三级功能
                if (key.privateFuncThirdLevelList.Count == 0 || key.privateFuncThirdLevelList.Contains(1) == false)
                {
                    result3 = await key.GetPanelDeviceFunctionLevel3(256, 1);
                    foreach (var l3 in result3)
                    {
                        key.privateFuncThirdLevelList.Add(l3);
                    }
                }
                else
                {
                    result3 = key.privateFuncThirdLevelList;
                }
                if (result3 != null)
                {
                    if (result3.Contains(1) == true)
                    {
                        dicCheck["场景:触发"] = true;
                    }
                }
            }
            //按键开关类
            if (result.Contains(100) == true)
            {
 
                List<int> result3 = null;
                //获取第三级功能
                if (key.privateFuncThirdLevelList.Count == 0 || key.privateFuncThirdLevelList.Contains(100) == false || key.privateFuncThirdLevelList.Contains(101) == false || key.privateFuncThirdLevelList.Contains(102) == false)
                {
                    result3 = await key.GetPanelDeviceFunctionLevel3(256, 100);
                    foreach (var l3 in result3)
                    {
                        key.privateFuncThirdLevelList.Add(l3);
                    }
                }
                else
                {
                    result3 = key.privateFuncThirdLevelList;
                }
                if (result3 != null)
                {
                    if (result3.Contains(100) == true)
                    {
                        dicCheck["开关:开"] = true;
                    }
                    if (result3.Contains(101) == true)
                    {
                        dicCheck["开关:关"] = true;
                    }
                    if (result3.Contains(102) == true)
                    {
                        dicCheck["开关:切换"] = true;
                    }
                }
            }
            //按键调光类
            if (result.Contains(200) == true)
            {
                List<int> result3 = null;
                //获取第三级功能
                if (key.privateFuncThirdLevelList.Count == 0 || key.privateFuncThirdLevelList.Contains(200) == false || key.privateFuncThirdLevelList.Contains(201) == false || key.privateFuncThirdLevelList.Contains(202) == false)
                {
                    result3 = await key.GetPanelDeviceFunctionLevel3(256, 200);
                    foreach (var l3 in result3)
                    {
                        key.privateFuncThirdLevelList.Add(l3);
                    }
                }
                else
                {
                    result3 = key.privateFuncThirdLevelList;
                }
                if (result3 != null)
                {
                    if (result3.Contains(200) == true)
                    {
                        dicCheck["亮度:按等级调大"] = true;
                    }
                    if (result3.Contains(201) == true)
                    {
                        dicCheck["亮度:按等级调小"] = true;
                    }
                    if (result3.Contains(202) == true)
                    {
                        dicCheck["亮度:按等级切换"] = true;
                    }
                    if (result3.Contains(203) == true)
                    {
                        dicCheck["亮度:打开"] = true;
                    }
                    if (result3.Contains(204) == true)
                    {
                        dicCheck["亮度:关闭"] = true;
                    }
                    if (result3.Contains(205) == true)
                    {
                        dicCheck["亮度:切换"] = true;
                    }
                }
            }
            //窗帘类
            if (result.Contains(300) == true)
            {
                List<int> result3 = null;
                //获取第三级功能
                if (key.privateFuncThirdLevelList.Count == 0 || (key.privateFuncThirdLevelList.Contains(300) == false && key.privateFuncThirdLevelList.Contains(301) == false && key.privateFuncThirdLevelList.Contains(302) == false && key.privateFuncThirdLevelList.Contains(303) == false && key.privateFuncThirdLevelList.Contains(304) == false))
                {
                    result3 = await key.GetPanelDeviceFunctionLevel3(256, 300);
                    foreach (var l3 in result3)
                    {
                        key.privateFuncThirdLevelList.Add(l3);
                    }
                }
                else
                {
                    result3 = key.privateFuncThirdLevelList;
                }
 
                if (result3 != null)
                {
                    if (result3.Contains(300) == true)
                    {
                        dicCheck["窗帘:开"] = true;
                    }
                    if (result3.Contains(301) == true)
                    {
                        dicCheck["窗帘:关"] = true;
                    }
                    if (result3.Contains(302) == true)
                    {
                        dicCheck["窗帘:停"] = true;
                    }
                    if (result3.Contains(303) == true)
                    {
                        dicCheck["窗帘:上升停"] = true;
                    }
                    if (result3.Contains(304) == true)
                    {
                        dicCheck["窗帘:下降停"] = true;
                    }
                }
            }
            return dicCheck;
        }
 
        /// <summary>
        /// 底部完成按钮显示
        /// </summary>
        /// <returns></returns>
        public static void FinishDisplay(List<Room> roomTempList, Button btnFinish)
        {
            if (roomTempList.Count == 0)
            {
                btnFinish.Enable = false;
                btnFinish.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect;
            }
            else
            {
                btnFinish.Enable = true;
                btnFinish.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
            }
        }
        #endregion 
    }
}