From 304dca51c28183a9dfc192c6b93ea1c00bdd5d97 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 01 七月 2020 15:00:40 +0800 Subject: [PATCH] 添加了写入功能类型 --- ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs | 830 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 744 insertions(+), 86 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs index 9524092..12546e0 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs @@ -4,20 +4,741 @@ 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 static int clusterID = 0; + 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> - public static List<CommonDevice> oldTargetList = new List<CommonDevice>(); + /// <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> GetFloorRoomList() + { + 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) + { + //鑾峰彇璁惧绫诲瀷鐨� + var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + //鏂伴闈㈡澘鐨勬柊椋庤澶囷紝鍒欎笉鏄剧ず + if (deviceEnumInfo.ConcreteType == Common.DeviceConcreteType.ButtonPanel_FangyueFreshAir) + { + 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); + 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> /// 妫�娴嬭璁惧鑳藉惁鏄剧ず @@ -101,88 +822,6 @@ } } 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 = HdlRoomLogic.Current.GetFloorSortList(); - foreach (var floorId in dicFloor.Keys) - { - //绗竴涓ゼ灞� - return dicFloor[floorId]; - } - return null; - } - - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰 - /// </summary> - /// <returns></returns> - public static string GetCurrentSelectFloorId() - { - var dicFloor = HdlRoomLogic.Current.GetFloorSortList();// - foreach (var floorId in dicFloor.Keys) - { - //绗竴涓ゼ灞� - return floorId; - } - return null; - } - - /// <summary> - /// 鑾峰彇褰撳墠妤煎眰鍚嶇О - /// </summary> - /// <returns></returns> - public static string GetCurrentSelectFloorIdName() - { - var dicFloor = HdlRoomLogic.Current.GetFloorSortList(); - foreach (var floorId in dicFloor.Keys) - { - //绗竴涓ゼ灞� - return dicFloor[floorId]; - } - 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]; - } - } - return null; } /// <summary> @@ -394,5 +1033,24 @@ } 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 } } -- Gitblit v1.8.0