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.Panel; namespace Shared.Phone.UserCenter.DeviceBind { public class BindInfo { /// /// 当前按键配置的功能 /// public static int clusterID = 0; /// /// 记录旧的目标列表 /// public static List oldTargetList = new List(); /// /// 检测该设备能否显示 /// /// /// 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; } /// /// 检测该房间能否显示 /// /// /// 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; } /// /// 检测设备是否拥有开关的功能(输入簇) /// /// /// 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; } /// /// 底部完成按钮显示 /// /// public static void FinishDisplay(List 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; } } /// /// 获取当前楼层名称 /// /// public static string GetCurrentKeyAllRoomList() { var dicFloor = HdlRoomLogic.Current.GetFloorSortList(); foreach (var floorId in dicFloor.Keys) { //第一个楼层 return dicFloor[floorId]; } return null; } /// /// 获取当前楼层 /// /// public static string GetCurrentSelectFloorId() { var dicFloor = HdlRoomLogic.Current.GetFloorSortList();// foreach (var floorId in dicFloor.Keys) { //第一个楼层 return floorId; } return null; } /// /// 获取当前楼层名称 /// /// public static string GetCurrentSelectFloorIdName() { var dicFloor = HdlRoomLogic.Current.GetFloorSortList(); foreach (var floorId in dicFloor.Keys) { //第一个楼层 return dicFloor[floorId]; } return null; } /// /// 获取当前楼层名称 /// fllodID:楼层ID /// /// public static string GetBindTargetsFloorIdName(string curFllodID) { var dicFloor = HdlRoomLogic.Current.GetFloorSortList(); foreach (var floorId in dicFloor.Keys) { //当前楼层 if (curFllodID == floorId) { return dicFloor[floorId]; } } return null; } /// /// 检测控制面板(按键类)所拥有的功能,现支持的有以下几种(必定存在键值,出错会返回null) /// /// The panel key function level2. /// Key. public static async System.Threading.Tasks.Task> CheckPanelKeyFunctionLevel3(Panel key) { Dictionary dicCheck = new Dictionary(); 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 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 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 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 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 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; } } }