黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
using System;
using System.Collections.Generic;
using System.Text;
using Shared.Common;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// App体验账号的逻辑
    /// </summary>
    public class HdlExperienceAccountLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// App体验账号的逻辑
        /// </summary>
        private static HdlExperienceAccountLogic m_Current = null;
        /// <summary>
        /// App体验账号的逻辑
        /// </summary>
        public static HdlExperienceAccountLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlExperienceAccountLogic();
                }
                return m_Current;
            }
        }
 
        /// <summary>
        /// 用来递增生成Mac用的
        /// </summary>
        private int DeviceNumber = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化全部体验数据
        /// </summary>
        public void InitAllExperienceData()
        {
            //初始化用户
            this.InitUserInfoData();
            //初始化住宅
            this.InitHomeData();
            //初始化楼层
            this.InitFloorData();
            //初始化房间
            this.InitRoomData();
            //初始化设备
            this.InitDeviceData();
            //初始化场景
            this.InitSceneData();
            //刷新左边刷新房间视图列表
            HdlRoomLogic.Current.RefreshRoomListView();
        }
 
        #endregion
 
        #region ■ 初始化用户_________________________
 
        /// <summary>
        /// 初始化用户
        /// </summary>
        private void InitUserInfoData()
        {
            UserCenterResourse.UserInfo = new UserInformation();
            UserCenterResourse.UserInfo.AuthorityNo = 1;//给他管理员称号
            UserCenterResourse.UserInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.Administrator);
            //虚拟账号
            UserCenterResourse.UserInfo.UserName = Language.StringByID(R.MyInternationalizationString.uVirtualAccount);
        }
 
        #endregion
 
        #region ■ 初始化住宅_________________________
 
        /// <summary>
        /// 初始化住宅
        /// </summary>
        private void InitHomeData()
        {
            //初始化住宅ID
            string homeId = "abcdefghijklmn";
            //初始Guid
            Config.Instance.Guid = "chushiGuid";
            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, homeId);
            if (System.IO.Directory.Exists(path) == true)
            {
                //再次启动的时候,重新开始
                System.IO.Directory.Delete(path, true);
            }
            System.IO.Directory.CreateDirectory(path);
 
            //注意,这里不清空当前住宅列表,保留它之前的住宅列表
 
            //创建临时住宅
            var house = new House() { Id = homeId, Name = Language.StringByID(R.MyInternationalizationString.uMyHome) };
            house.IsVirtually = true;
            house.Save(false);
            Config.Instance.HomeId = house.Id;
            Config.Instance.Home = HdlResidenceLogic.Current.GetHouseByHouseId(house.Id);
 
            //预创建个人中心全部的文件夹
            UserCenterLogic.CreatAllUserCenterDirectory();
        }
 
        #endregion
 
        #region ■ 初始化楼层_________________________
 
        /// <summary>
        /// 初始化楼层
        /// </summary>
        private void InitFloorData()
        {
            Config.Instance.Home.FloorDics = new Dictionary<string, string>();
            //Config.Instance.Home.FloorDics["floorKey1"] = "1F";
            //Config.Instance.Home.FloorDics["floorKey2"] = "2F";
            //Config.Instance.Home.FloorDics["floorKey3"] = "3F";
            //Config.Instance.Home.FloorDics["floorKey4"] = "4F";
            //Config.Instance.Home.FloorDics["floorKey5"] = "5F";
        }
 
        #endregion
 
        #region ■ 初始化房间_________________________
 
        /// <summary>
        /// 获取房间样板列表
        /// </summary>
        /// <returns></returns>
        private Dictionary<string, string> GetRoomSampleList()
        {
            var dicRoomName = new Dictionary<string, string>();
            //客厅
            dicRoomName["KeTing"] = Language.StringByID(R.MyInternationalizationString.uLivingRoom);
            //阳台
            dicRoomName["YangTai"] = Language.StringByID(R.MyInternationalizationString.uBalcony);
            //卧室
            dicRoomName["WoShi"] = Language.StringByID(R.MyInternationalizationString.uBedroom);
            //玄关
            dicRoomName["XuanGuan"] = Language.StringByID(R.MyInternationalizationString.uVestibule);
            //厨房
            dicRoomName["ChuFang"] = Language.StringByID(R.MyInternationalizationString.uKitchen);
            //走廊
            dicRoomName["ZouLang"] = Language.StringByID(R.MyInternationalizationString.uCorridor);
 
            return dicRoomName;
        }
 
        /// <summary>
        /// 初始化房间
        /// </summary>
        private void InitRoomData()
        {
            //先刷新容器
            HdlRoomLogic.Current.InitAllRoom();
 
            //获取全部的楼层主键
            var listFloorKey = this.GetAllFloorKeys();
            var dicRoomName = this.GetRoomSampleList();
 
            //设置初始楼层
            Config.Instance.Home.CurrentFloorId = listFloorKey[0];
            foreach (string floorKey in listFloorKey)
            {
                foreach (string roomId in dicRoomName.Keys)
                {
                    //创建新房间
                    var newRoom = new Room();
                    newRoom.Id = floorKey + "_" + roomId;
                    newRoom.Name = dicRoomName[roomId];
                    newRoom.BackgroundImage = "RoomIcon/0.jpg";
                    newRoom.FloorId = floorKey;
                    HdlRoomLogic.Current.AddRoom(newRoom, false);
                }
            }
        }
 
        /// <summary>
        /// 获取全部的楼层主键
        /// </summary>
        /// <returns></returns>
        private List<string> GetAllFloorKeys()
        {
            var listKey = new List<string>();
            foreach (var strKey in Config.Instance.Home.FloorDics.Keys)
            {
                listKey.Add(strKey);
            }
            if (listKey.Count == 0)
            {
                listKey.Add("");
            }
            return listKey;
        }
 
        #endregion
 
        #region ■ 初始化设备_________________________
 
        /// <summary>
        /// 设置需要创建的虚拟设备列表
        /// </summary>
        /// <returns></returns>
        private List<AddDevicePra> GetVirtualDeviceList()
        {
            //floorKey1   _   KeTing  YangTai  WoShi  XuanGuan  ChuFang  ZouLang
            var list = new List<AddDevicePra>();
            //获取全部的楼层主键
            var listFloorKey = this.GetAllFloorKeys();
            foreach (var floorKey in listFloorKey)
            {
                //客厅
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A2按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A3按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 2 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A空调网关, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
 
                //阳台
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A220pir传感器, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A卷帘电机, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A开合帘电机, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A2按键面板, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
 
                //卧室
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A1路调光器, RoomId = floorKey + "_WoShi", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A3路继电器, RoomId = floorKey + "_WoShi", DeviceCount = 1 });
 
                //玄关
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A空气开关, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A1路调光器, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A门窗磁传感器, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
 
                //厨房
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A水浸传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A烟雾传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A燃气传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A吸顶燃气传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
 
                //走廊
                list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_ZouLang", DeviceCount = 1 });
            }
            return list;
        }
 
        /// <summary>
        /// 初始化设备
        /// </summary>
        private void InitDeviceData()
        {
            //先刷新容器
            LocalDevice.Current.ReFreshByLocal();
            //顺便也整一下网关(有可能它是从实体账号转为虚拟时,没有清空)
            HdlGatewayLogic.Current.ReFreshByLocal();
            HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
 
            Type thisType = m_Current.GetType();
            //获取需要创建的虚拟设备列表
            var list = this.GetVirtualDeviceList();
            foreach (var data in list)
            {
                string methordName = "Zigbee" + data.DeviceType.ToString().Substring(1);
                //反射指定的函数
                var myMethod = thisType.GetMethod(methordName);
                myMethod.Invoke(this, new object[] { data.DeviceCount, data.RoomId });
            }
        }
 
        #endregion
 
        #region ■ 初始化场景_________________________
 
        /// <summary>
        /// 初始化场景
        /// </summary>
        private void InitSceneData()
        {
            //刷新容器
            HdlSceneLogic.Current.ReFreshByLocal();
 
            //获取全部的楼层主键
            var listFloorKey = this.GetAllFloorKeys();
            //获取全部的房间模板列表
            var dicRoom = this.GetRoomSampleList();
 
            //floorKey1   _   KeTing  YangTai  WoShi  XuanGuan  ChuFang  ZouLang
            int sceneIdNo = 1;
            //对每一个楼层
            foreach (var floorKey in listFloorKey)
            {
                //对每一个房间
                foreach (var strKey in dicRoom.Keys)
                {
                    var room = HdlRoomLogic.Current.GetRoomById(floorKey + "_" + strKey);
                    if (room == null)
                    {
                        continue;
                    }
                    //灯全开
                    var listAdjust1 = this.InitVirtualSceneAdjustList(room, 1);
                    var sceneName = Language.StringByID(R.MyInternationalizationString.uAllLightOpen);
                    var scene = HdlSceneLogic.Current.AddVirtualScene(sceneIdNo, sceneName, listAdjust1);
                    sceneIdNo++;
                    HdlSceneLogic.Current.AddSceneToRoom(room, scene);
 
                    //灯全关
                    var listAdjust2 = this.InitVirtualSceneAdjustList(room, 0);
                    var sceneName2 = Language.StringByID(R.MyInternationalizationString.uAllLightClose);
                    var scene2 = HdlSceneLogic.Current.AddVirtualScene(sceneIdNo, sceneName2, listAdjust2);
                    sceneIdNo++;
                    HdlSceneLogic.Current.AddSceneToRoom(room, scene2);
                }
            }
        }
 
        /// <summary>
        /// 初始化虚拟场景的执行目标(statu 0:关 1:开)
        /// </summary>
        /// <param name="i_room"></param>
        /// <param name="statu"></param>
        /// <returns></returns>
        private List<Scene.DeviceListData> InitVirtualSceneAdjustList(Room i_room, int statu)
        {
            var listBind = new List<Scene.DeviceListData>();
            foreach (var mainKey in i_room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(mainKey);
                if (device == null) { continue; }
                //只要继电器和灯
                if (device.Type == DeviceType.OnOffOutput
                    || device.Type == DeviceType.DimmableLight)
                {
                    var data = new Scene.DeviceListData();
                    data.Type = 0;
                    data.DeviceAddr = device.DeviceAddr;
                    data.Epoint = device.DeviceEpoint;
                    data.TaskList.Add(new Safeguard.TaskListInfo() { TaskType = 1, Data1 = statu });
                    listBind.Add(data);
                }
            }
            return listBind;
        }
 
        #endregion
 
        #region ■ 创建虚拟设备列表___________________
 
        public void Zigbee开合帘电机(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new Rollershade() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.WcdType = 4;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 100, 100, "MWM65B-ZB.20", i_RoomId);
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee卷帘电机(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new Rollershade() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.WcdType = 0;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 101, 101, "MVSM35B-ZB.20", i_RoomId);
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee4按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //4个干接点
                for (int j = 1; j <= 4; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
                }
                //4个继电器
                for (int j = 5; j <= 8; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 9 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee3按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //3个干接点
                for (int j = 1; j <= 3; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
                }
                //3个继电器
                for (int j = 4; j <= 6; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 3);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee2按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //2个干接点
                for (int j = 1; j <= 2; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
                }
                //2个继电器
                for (int j = 3; j <= 4; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 5 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee简约4按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //4个干接点
                for (int j = 1; j <= 4; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
                }
                //4个继电器
                for (int j = 5; j <= 8; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 9 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee简约3按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //3个干接点
                for (int j = 1; j <= 3; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
                }
                //3个继电器
                for (int j = 4; j <= 6; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 3);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee简约2按键面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //2个干接点
                for (int j = 1; j <= 2; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
                }
                //2个继电器
                for (int j = 3; j <= 4; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 5 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee220pir传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //1个传感器
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 13;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1200, 1200, "MSPIR01-ZB.10", i_RoomId);
 
                //1个继电器
                var device2 = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 2 };
                device2.DfunctionType = DeviceFunctionType.A灯光;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 1200, 1200, "MSPIR01-ZB.10", i_RoomId);
                device2.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + 1;
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee燃气传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 43;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1300, 1300, "MSG01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee吸顶燃气传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 43;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1300, 1300, "MGCD01/ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee门窗磁传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 21;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1301, 1301, "MSDC01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee烟雾传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 40;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1301, 1301, "MSS01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee红外传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 13;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1303, 1303, "MSPIR01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee水浸传感器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 42;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1304, 1304, "MSW01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee紧急按键(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                device.IasDeviceType = 44;
                device.DeviceID = 1026;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 1305, 1305, "MBU01/M-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee3路继电器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //3个继电器
                for (int j = 1; j <= 3; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 2300, 2300, "MPR0310-ZB.10", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + j;
                }
                //7个干接点
                for (int j = 4; j <= 10; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 2300, 2300, "MPR0310-ZB.10", i_RoomId);
                }
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee1路调光器(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //7个干接点
                for (int j = 1; j <= 7; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 2300, 2300, "MPD0101-ZB.10", i_RoomId);
                }
 
                //1个调光器
                var device2 = new DimmableLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 8 };
                device2.DfunctionType = DeviceFunctionType.A灯光;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 2300, 2300, "MPD0101-ZB.10", i_RoomId);
                device2.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + 1;
 
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee空调网关(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //10个空调应该可以了
                for (int j = 1; j <= 10; j++)
                {
                    var device = new AC() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //室温默认26℃
                    device.currentLocalTemperature = 26;
                    device.currentCoolingSetpoint = 26;
                    device.currentHeatingSetpoint = 26;
                    device.currentAutoSetpoint = 26;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 3600, 3600, "MAC/GW-ZB.10", i_RoomId);
                }
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee空气开关(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new AirSwitch() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 4100, 4100, "MBCI01-ZB.10", i_RoomId);
                device.DfunctionType = DeviceFunctionType.A开关;
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee智能门锁(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                var device = new ZigBee.Device.DoorLock() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 2800, 2800, "S-one", i_RoomId);
                device.DfunctionType = DeviceFunctionType.A开关;
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee方悦单开双控面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //2个干接点
                for (int j = 1; j <= 2; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
                }
                //1个继电器
                for (int j = 3; j <= 3; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 4 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee方悦双开四控面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //4个干接点
                for (int j = 1; j <= 4; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
                }
                //2个继电器
                for (int j = 5; j <= 6; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee方悦四开八控面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //8个干接点
                for (int j = 1; j <= 8; j++)
                {
                    var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
                }
                //4个继电器
                for (int j = 9; j <= 12; j++)
                {
                    var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
                    device.DfunctionType = DeviceFunctionType.A灯光;
                    //设置设备的基本信息
                    this.SetBaseDataToDevice(device, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
                    device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 8);
                }
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 13 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee方悦新风面板(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //1新风
                var device = new FreshAir() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 250, 250, "MPFA/TILE-ZB.18", i_RoomId);
 
                //1温度探头
                var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 2 };
                device2.SensorDiv = 1;
                //设置设备的基本信息
                this.SetBaseDataToDevice(device2, 250, 250, "MPFA/TILE-ZB.18", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        public void Zigbee方悦新风小模块(int i_DeviceCount, string i_RoomId)
        {
            for (int i = 0; i < i_DeviceCount; i++)
            {
                //1新风
                var device = new FreshAir() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
                //设置设备的基本信息
                this.SetBaseDataToDevice(device, 2310, 2310, "MFA01-ZB.10", i_RoomId);
 
                this.DeviceNumber++;
            }
        }
 
        /// <summary>
        /// 设置设备的基本信息
        /// </summary>
        /// <param name="device"></param>
        private void SetBaseDataToDevice(CommonDevice device, int HwVersion, int ImgTypeId,
            string ModelIdentifier, string roomId)
        {
            device.DeviceEpointName = string.Empty;
            device.HadReadDeviceStatu = true;
            device.DeviceName = string.Empty;
            device.IsOnline = 1;
            device.HwVersion = HwVersion;
            device.ImgTypeId = ImgTypeId;
            device.DriveCode = 0;
            device.ManufacturerName = "HDL";
            device.ModelIdentifier = ModelIdentifier;
            device.CurrentGateWayId = string.Empty;
 
            //默认每个设备都可以定位,拥有开关功能
            device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 3 });
            device.OutClusterList.Add(new CommonDevice.OutClusterObj { OutCluster = 3 });
            if (device.Type == DeviceType.AirSwitch || device.Type == DeviceType.OnOffOutput
                || device.Type == DeviceType.DimmableLight || device.Type == DeviceType.ColorDimmableLight)
            {
                device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 6 });
                device.OutClusterList.Add(new CommonDevice.OutClusterObj { OutCluster = 6 });
            }
            if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
                || device.Type == DeviceType.ColorDimmableLight)
            {
                device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 8 });
            }
            if (device.Type == DeviceType.WindowCoveringDevice)
            {
                device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 258 });
            }
            //添加虚拟设备
            LocalDevice.Current.AddVirtualDeviceToMemory(device);
 
            var room = HdlRoomLogic.Current.GetRoomById(roomId);
            if (room != null)
            {
                //添加房间
                HdlRoomLogic.Current.AddDevice(room, device, true);
            }
        }
 
        #endregion
 
        #region ■ 设备枚举___________________________
 
        /// <summary>
        /// 虚拟设备枚举
        /// </summary>
        private enum VirtualDeviceEnum
        {
            A开合帘电机 = 1,
            A卷帘电机 = 2,
            A4按键面板 = 3,
            A3按键面板 = 4,
            A2按键面板 = 5,
            A简约4按键面板 = 7,
            A简约3按键面板 = 8,
            A简约2按键面板 = 9,
            A220pir传感器 = 10,
            A燃气传感器 = 11,
            A门窗磁传感器 = 12,
            A烟雾传感器 = 13,
            A红外传感器 = 14,
            A水浸传感器 = 15,
            A紧急按键 = 16,
            A3路继电器 = 17,
            A1路调光器 = 18,
            A空调网关 = 19,
            A空气开关 = 20,
            A智能门锁 = 21,
            A方悦单开双控面板 = 22,
            A方悦双开四控面板 = 23,
            A方悦四开八控面板 = 24,
            A方悦新风面板 = 25,
            A方悦新风小模块 = 26,
            A吸顶燃气传感器 = 27,
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 添加设备的参数
        /// </summary>
        private class AddDevicePra
        {
            /// <summary>
            /// 设备类型
            /// </summary>
            public VirtualDeviceEnum DeviceType = VirtualDeviceEnum.A空气开关;
            /// <summary>
            /// 添加的设备个数(不是回路数)
            /// </summary>
            public int DeviceCount = 1;
            /// <summary>
            /// 将设备添加到的房间(不设置表示不添加到房间)
            /// </summary>
            public string RoomId = string.Empty;
        }
 
        #endregion
    }
}