黄学彪
2019-12-20 23fb45dd846ed8b62304c408c6bbe64265d4ac8b
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.Device.Category;
using Shared.Phone.UserCenter.Device;
using ZigBee.Device;
using static ZigBee.Device.Panel;
 
namespace Shared.Phone.UserCenter.DeviceBind
{
    public class BindInfo
    {
        /// <summary>
        /// 当前按键配置的功能
        /// </summary>
        public static int clusterID = 0;
        /// <summary>
        /// 记录旧的目标列表
        /// </summary>
        public static List<CommonDevice> oldTargetList = new List<CommonDevice>();
 
        /// <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.DeviceUIList.Count == 0)
            {
                return false;
            }
            if (room.IsLove == true)
            {
                return false;
            }
            foreach (var deviceUi in room.DeviceUIList)
            {
                //检测该设备能否显示
                if (CheckCanShowDevice(deviceUi.CommonDevice, 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>
        /// 底部完成按钮显示
        /// </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;
            }
        }
 
        /// <summary>
        /// 获取当前楼层名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentKeyAllRoomList()
        {
            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return dicFloor[floorId];
                break;
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentSelectFloorId()
        {
            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();//
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return floorId;
                break;
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层名称
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentSelectFloorIdName()
        {
            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                return dicFloor[floorId];
                break;
            }
            return null;
        }
 
        /// <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;
        }
    }
}