From 652243206427f35a256400a149a1734085824cb9 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 02 九月 2020 17:35:03 +0800
Subject: [PATCH] 2020-09-02-4

---
 ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs | 1238 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 735 insertions(+), 503 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs
index 63cb01f..f0739e7 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/BindInfo.cs
@@ -2,68 +2,739 @@
 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.BindObj;
 using static ZigBee.Device.Panel;
 
 namespace Shared.Phone.UserCenter.DeviceBind
 {
     public class BindInfo
     {
+        #region 缁戝畾璁捐鐨勫彉閲忓畾涔�
         /// <summary>
-        /// 褰撳墠鎸夐敭閰嶇疆鐨勫姛鑳�
+        /// 褰撳墠璁惧缁戝畾绫诲瀷
         /// </summary>
-        public static int clusterID = 0;
-        /// <summary>
-        /// 璁板綍鏃х殑鐩爣鍒楄〃
-        /// </summary>
-        public static List<CommonDevice> oldTargetList = new List<CommonDevice>();
-
-        public static async System.Threading.Tasks.Task<int> RemoveTargets(BindObj.BindListResponseObj bindDevice, Panel currentKey)
+        public enum BindType
         {
-            var delDevice = new BindObj.DelDeviceBindData();
-            delDevice.DeviceAddr = currentKey.DeviceAddr;
-            delDevice.Epoint = currentKey.DeviceEpoint;
+            /// <summary>
+            /// 鏂伴
+            /// </summary>
+            FreshAir = 1,
+            /// <summary>
+            /// 娓╁害浼犳劅鍣�
+            /// </summary>
+            Temperature = 2,
+            /// <summary>
+            /// 婀垮害浼犳劅鍣�
+            /// </summary>
+            Humidity = 3,
+            /// <summary>
+            /// PM2.5浼犳劅鍣�
+            /// </summary>
+            PM = 4,
+            /// <summary>
+            /// 绌鸿皟鐩爣
+            /// </summary>
+            AC = 5,
+            /// <summary>
+            /// 鍦版殩鐩爣
+            /// </summary>
+            Fh = 6,
+        }
 
-            if (bindDevice.BindType == 0 || bindDevice.BindType == 1)
+        #endregion
+
+        #region 缁戝畾娑夊強鐨勬暟鎹鐞�
+        /// <summary>
+        /// 鑾峰彇褰撳墠妤煎眰鍚嶇О
+        /// </summary>
+        /// <returns></returns>
+        public static string GetCurrentKeyAllRoomList()
+        {
+            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
+            foreach (var floorId in dicFloor.Keys)
             {
-                var removeDevice = new BindObj.RemoveBindListObj();
-                removeDevice.BindCluster = bindDevice.BindCluster;
-                removeDevice.BindType = 0;
-                removeDevice.BindMacAddr = bindDevice.BindMacAddr;
-                removeDevice.BindEpoint = bindDevice.BindEpoint;
-                delDevice.RemoveBindList.Add(removeDevice);
+                //绗竴涓ゼ灞�
+                return dicFloor[floorId];
+                break;
             }
-            else if (bindDevice.BindType == 2)
+            return null;
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠妤煎眰
+        /// </summary>
+        /// <returns></returns>
+        public static string GetCurrentSelectFloorId()
+        {
+            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();//
+            foreach (var floorId in dicFloor.Keys)
             {
-                var removeDevice = new BindObj.RemoveBindListObj();
-                removeDevice.BindCluster = bindDevice.BindCluster;
-                removeDevice.BindType = 1;
-                removeDevice.BindScenesId = bindDevice.BindScenesId;
-                delDevice.RemoveBindList.Add(removeDevice);
+                //绗竴涓ゼ灞�
+                return floorId;
+                break;
             }
-            var delResult = await currentKey.DelDeviceBindAsync(delDevice);
-            foreach (var re in delResult.delDeviceBindResponseData.RemoveBindList)
+            return null;
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠妤煎眰鍚嶇О
+        /// </summary>
+        /// <returns></returns>
+        public static string GetCurrentSelectFloorIdName()
+        {
+            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
+            foreach (var floorId in dicFloor.Keys)
             {
-                switch (re.Result)
+                //绗竴涓ゼ灞�
+                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)
                 {
-                    case 0:
-                        return 0;
-                        break;
-                    case 4:
-
-                        if (delResult.removeBindResultResponseData != null)
-                        {
-                            if (delResult.removeBindResultResponseData.Result == 0)
-                            {
-                                return 0;
-                            }
-                        }
-                        break;
+                    return dicFloor[floorId];
+                    break;
                 }
             }
-            return -1;
+            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 clu = device.OutClusterList.Find((obj) => obj.OutCluster == 514);
+            if (clu != null)
+            {
+                result = false;
+            }
+            return result;
         }
 
         /// <summary>
@@ -92,7 +763,7 @@
         /// <returns></returns>
         public static bool CheckCanShowRoom(Common.Room room, string curDeviceBindType = "AddSwitch")
         {
-            if (room.DeviceUIList.Count == 0)
+            if (room.ListDevice.Count == 0)
             {
                 return false;
             }
@@ -100,10 +771,11 @@
             {
                 return false;
             }
-            foreach (var deviceUi in room.DeviceUIList)
+            foreach (var deviceKeys in room.ListDevice)
             {
+                var device = Common.LocalDevice.Current.GetDevice(deviceKeys);
                 //妫�娴嬭璁惧鑳藉惁鏄剧ず
-                if (CheckCanShowDevice(deviceUi.CommonDevice, curDeviceBindType) == false)
+                if (CheckCanShowDevice(device, curDeviceBindType) == false)
                 {
                     continue;
                 }
@@ -147,72 +819,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 = 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>
@@ -422,400 +1028,26 @@
                     }
                 }
             }
-
             return dicCheck;
         }
 
-        #region 绉佹湁鏁版嵁澶囦唤姝ラ(鏈夌敤浠g爜锛岃繖閲屽厛娉ㄩ噴鎺夛級
-        //        title.MouseLongEventHandler += async(sender, e) =>
-        //           {
-        //               string fileName = "Panel_";
-        //        fileName += currentKey.FilePath;
-        //               var file = await System.Threading.Tasks.Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.SerializeObject(currentKey));
-        //        var data = System.Text.Encoding.UTF8.GetBytes(file);
-        //        //缃戝叧涓垱寤哄瓨鍌ㄦ暟鎹殑鏂囦欢
-        //        var saveFile = await currentKey.Gateway.CreateFileAsync(fileName);
-        //        //涓婁紶鏁版嵁鍒扮綉鍏�
-        //        var saveData = await currentKey.Gateway.SendFileAsync(data);
-        //    };
-
-        //    //瀛樺偍涓嬭浇鐨勬枃浠舵暟鎹�
-        //    var byteSource = new System.Collections.Generic.List<byte>();
-        //            if (byteSource != null)
-        //            {
-        //                //鎭㈠鏁版嵁瀵硅薄
-        //                var realDa = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(System.Text.Encoding.UTF8.GetString(byteSource.ToArray()));
-        //}
-
-        ////涓嬭浇鎭㈠绉佹湁鏁版嵁
-        //title.MouseUpEventHandler +=async(sender, e) =>
-        //            {
-        //                var key11 = currentKey;
-        //string fileName = "Panel_";
-        //fileName += currentKey.FilePath; 
-        //                //鑾峰彇褰撳墠鏂囦欢鐨勫叿浣撲俊鎭�
-        //                var getFileSize = await currentKey.Gateway.GetCurrentFileInfoAsync(fileName);
-        ////涓嬭浇鏂囦欢
-        //var saveFileName = await currentKey.Gateway.SetDownloadFileAsync(fileName);
-        ////鎺ユ敹鏁版嵁
-        //Action<string, byte[]> action = (topic, dataContent) =>
-        //{
-        //    if (topic.Split('/')[0] + "/" + topic.Split('/')[1] + "/" + topic.Split('/')[2] == topic.Split('/')[0] + "/" + "FileTransfer/DownloadFile")
-        //    {
-        //        byte[] fileBytes = dataContent;
-        //        if (fileBytes[5] != 1)
-        //        {
-        //            if (fileBytes.Length == 2056)
-        //            {
-        //                var tempBytes = new byte[2048];
-        //                System.Array.Copy(fileBytes, 8, tempBytes, 0, 2048);
-        //                byteSource.AddRange(tempBytes);
-        //            }
-        //            else
-        //            {
-        //                var tempBytes = new byte[fileBytes.Length - 8];
-        //                System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
-        //                byteSource.AddRange(tempBytes);
-        //            }
-        //        }
-        //        else
-        //        {
-        //            var tempBytes = new byte[fileBytes.Length - 8];
-        //            System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
-        //            byteSource.AddRange(tempBytes);
-        //        }
-
-        //    }
-        //};
-        //currentKey.Gateway.FileContentAction += action;
-        //};
-        #endregion
-
-        ///// <summary>
-        ///// 鍒楄〃鎺т欢
-        ///// </summary>
-        //private VerticalScrolViewLayout listView = null;
-        ///// <summary>
-        ///// 宸茬粡瀛樺湪鐨勭粦瀹氳澶�
-        ///// </summary>
-        //private Dictionary<string, CommonDevice> dicEsixtDevice = new Dictionary<string, CommonDevice>();
-
-        ///// <summary>
-        ///// 鑾峰彇璁惧鐨勫敮涓�涓婚敭
-        ///// </summary>
-        ///// <param name="device"></param>
-        ///// <returns></returns>
-        //public string GetDeviceMainKeys(CommonDevice device)
-        //{
-        //    return device.DeviceAddr + device.DeviceEpoint;
-        //}
-
-        ///// <summary>
-        ///// 鏄剧ず閿欒淇℃伅绐楀彛
-        ///// </summary>
-        ///// <param name="msg"></param>
-        //private void ShowErrorMsg(string msg)
-        //{
-        //    Application.RunOnMainThread(() =>
-        //    {
-        //        var contr = new Phone.UserCenter.ErrorMsgControl(msg);
-        //        contr.Show();
-        //    });
-        //}
-
-        ///// <summary>
-        ///// 鏄剧ずTip淇℃伅绐楀彛
-        ///// </summary>
-        ///// <param name="msg"></param>
-        //private void ShowTipMsg(string msg)
-        //{
-        //    Application.RunOnMainThread(() =>
-        //    {
-        //        var contr = new Phone.UserCenter.TipViewControl(msg);
-        //        contr.ShowView();
-        //    });
-        //}
-
-        ///// <summary>
-        ///// 鏄剧ず涓�涓渶瑕佺‘璁ょ殑淇℃伅妗�
-        ///// </summary>
-        ///// <param name="msg">淇℃伅</param>
-        ///// <param name="methodName">鏂规硶鍚�(璇风‘璁よ繖鏄竴涓叡鏈夋柟娉�)</param>
-        ///// <param name="obj">鍥炶皟鍑芥暟鐨勫惎鍔ㄥ弬鏁�</param>
-        //public void ShowConfirmMsg(string msg, string methodName = null, params object[] obj)
-        //{
-        //    Application.RunOnMainThread(() =>
-        //    {
-        //        var alert = new ConfirmMsgControl(msg);
-        //        alert.Show();
-
-        //        if (methodName != null)
-        //        {
-        //            alert.ResultEventHandler += (sender, result) =>
-        //            {
-        //                if (result == true)
-        //                {
-        //                    this.LoadFormMethodByName(this, methodName, obj);
-        //                }
-        //            };
-        //        }
-        //    });
-        //}
-
-        ///// <summary>
-        ///// 鎵ц鎸囧畾鐢婚潰鐨勬柟娉�
-        ///// </summary>
-        ///// <param name="form">鎸囧畾鐢婚潰鐨勮嫳鏂囧悕</param>
-        ///// <param name="method">鎸囧畾瑕佸姞杞界殑鏂规硶鍚�</param>
-        ///// <param name="parameter">鍚姩鍙傛暟</param>
-        //public object LoadFormMethodByName(BindInfo form, string method, params object[] parameter)
-        //{
-        //    return form.GetType().InvokeMember(method, System.Reflection.BindingFlags.InvokeMethod, null, form, parameter);
-        //}
-
-        ///// <summary>
-        ///// 娣诲姞鐢婚潰,鍚姩鍙傛暟鐢辨寚瀹氱敾闈㈢殑ShowForm鍑芥暟鎵�鎸囧畾
-        ///// </summary>
-        ///// <param name="newform">瀵硅薄鐢婚潰</param>
-        ///// <param name="parameter">鍚姩鍙傛暟锛氬弬鏁扮敱鎸囧畾鐢婚潰鐨凷howForm鍑芥暟鎵�鎸囧畾</param>
-        //public void AddForm(UserCenterCommonForm newform, params object[] parameter)
-        //{
-        //    //妫�娴嬭兘鍚﹁拷鍔犵敾闈�(闃叉鐢婚潰浜岄噸娣诲姞)锛屽綋鐐瑰嚮杩囧揩鏃讹紝浼氭湁鍑犵巼浜岄噸娣诲姞
-        //    if (UserCenterLogic.CheckCanAddForm(newform) == false)
-        //    {
-        //        return;
-        //    }
-        //    newform.FormID = UserCenterLogic.GetFormName(newform);
-
-        //    UserView.HomePage.Instance.AddChidren(newform);
-        //    UserView.HomePage.Instance.PageIndex += 1;
-        //    //鍒濆鍖栫晫闈㈡鏋�
-        //    newform.InitForm(parameter);
-        //    //鎵цShowForm()鏂规硶
-        //    newform.LoadShowFormMethod(parameter);
-        //}
-
-        ///// <summary>
-        ///// 鑳界粦瀹氬埌鎸夐敭鐨勮澶�
-        ///// </summary>
-        ///// <param name="device"></param>
-        ///// <returns></returns>
-        //public  bool SupportDevice(CommonDevice device,int currentClusterID)
-        //{
-        //    foreach (var data in device.InClusterList)
-        //    {
-        //        //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇�
-        //        if (data.InCluster == currentClusterID)
-        //        {
-        //            return true;
-        //        }
-        //    }
-        //    return false;
-        //}
-
-        ///// <summary>
-        ///// 缁戝畾PIR浼犳劅鍣ㄧ殑鐩爣(杩斿洖鎴愬姛璁剧疆鐨勮澶�,閿欒鏃讹紝杩斿洖null)
-        ///// </summary>
-        ///// <param name="i_iasZone">浼犳劅鍣�</param>
-        ///// <param name="listDevice">瑕佺粦瀹氱殑鐩爣璁惧</param>
-        ///// <returns></returns>
-        //public async Task<List<CommonDevice>> BindKeyDeviceTargets(Panel key, List<CommonDevice> listDevice,int currentClusterID)
-        //{
-        //    if (listDevice.Count == 0)
-        //    {
-        //        return new List<CommonDevice>();
-        //    }
-
-        //    var dicDevice = new Dictionary<string, CommonDevice>();
-
-        //    //缁勮鏁版嵁
-        //    var addData = new Panel.AddBindData();
-        //    addData.DeviceAddr = key.DeviceAddr;
-        //    addData.Epoint = key.DeviceEpoint;
-        //    foreach (var device in listDevice)
-        //    {
-        //        var info = new Panel.AddBindListObj();
-        //        info.BindCluster = currentClusterID;
-        //        info.BindMacAddr = device.DeviceAddr;
-        //        info.BindEpoint = device.DeviceEpoint;
-        //        info.BindType = 0;
-
-        //        addData.BindList.Add(info);
-
-        //        //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢�
-        //        string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
-        //        dicDevice[mainkeys] = device;
-        //    }
-
-        //    var result = await key.AddDeviceBindAsync(addData);
-        //    if (result.addedDeviceBindResponseData == null)
-        //    {
-        //        //濡傛灉缃戝叧宸茬粡鎺夌嚎
-        //        bool flage = Common.LocalGateway.Current.CheckGatewayOnLineOnTimeout(key.CurrentGateWayId, result.errorMessageBase);
-        //        if (flage == false)
-        //        {
-        //            return null;
-        //        }
-        //        //缁戝畾鐩爣璁剧疆澶辫触
-        //        string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail);
-        //        //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
-        //        msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg);
-
-        //        this.ShowErrorMsg(msg);
-        //        return null;
-        //    }
-
-        //    var listSuccess = new List<CommonDevice>();
-        //    foreach (var data in result.addedDeviceBindResponseData.BindList)
-        //    {
-        //        string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint);
-        //        //0:娣诲姞鎴愬姛  3:宸茬粡瀛樺湪锛屼篃鍙互浠h〃鎴愬姛
-        //        if (data.Result == 0 || data.Result == 3)
-        //        {
-        //            if (dicDevice.ContainsKey(mainkeys) == true)
-        //            {
-        //                listSuccess.Add(dicDevice[mainkeys]);
-        //            }
-        //        }
-        //        //1锛氬け璐ワ紝鑺傜偣璁惧鎴栧満鏅笉瀛樺湪
-        //        else if (data.Result == 1)
-        //        {
-        //            if (dicDevice.ContainsKey(mainkeys) == true)
-        //            {
-        //                //璁惧鍚嶇О 缁戝畾澶辫触
-        //                string msg = Shared.Common.LocalDevice .Current.GetDeviceEpointName(dicDevice[mainkeys]) + " ";
-        //                msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
-        //                this.ShowTipMsg(msg);
-        //            }
-        //        }
-        //        //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔�
-        //        else if (data.Result == 2)
-        //        {
-        //            if (result.addBindResultResponseData == null)
-        //            {
-        //                //璁惧鍚嶇О 缁戝畾澶辫触
-        //                string msg = Shared.Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + " ";
-        //                msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
-        //                this.ShowTipMsg(msg);
-        //            }
-        //            else
-        //            {
-        //                //娣诲姞鎴愬姛
-        //                if (result.addBindResultResponseData.Result == 0)
-        //                {
-        //                    if (dicDevice.ContainsKey(mainkeys) == true)
-        //                    {
-        //                        listSuccess.Add(dicDevice[mainkeys]);
-        //                    }
-        //                }
-        //                //璁惧鍚嶇О 缁戝畾鍒楄〃宸叉弧
-        //                else if (result.addBindResultResponseData.Result == 140)
-        //                {
-        //                    string msg = Shared.Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + " ";
-        //                    msg += Language.StringByID(R.MyInternationalizationString.uBindListIsFull);
-        //                    this.ShowTipMsg(msg);
-        //                }
-        //                else
-        //                {
-        //                    //璁惧鍚嶇О 缁戝畾澶辫触
-        //                    string msg = Shared.Common.LocalDevice.Current.GetDeviceEpointName(dicDevice[mainkeys]) + " ";
-        //                    msg += Language.StringByID(R.MyInternationalizationString.BindFailed);
-        //                    this.ShowTipMsg(msg);
-        //                }
-        //            }
-        //        }
-        //    }
-
-        //    return listSuccess;
-        //}
-
-        ///// <summary>
-        ///// 鏄剧ず璁惧閫夋嫨鐨勭晫闈�
-        ///// </summary>
-        //public  void ShowDeviceSelectForm(Panel key, int currentClusterID)
-        //{
-        //    var listShowDevice = new List<CommonDevice>();
-        //    foreach (var device in PanelBindPage.list)
-        //    {
-        //        if (SupportDevice(device, currentClusterID) == false)
-        //        {
-        //            continue;
-        //        }
-
-        //        string mainKeys = this.GetDeviceMainKeys(device);
-        //        if (this.dicEsixtDevice.ContainsKey(mainKeys) == true)
-        //        {
-        //            //濡傛灉宸茬粡娣诲姞浜嗭紝鍒欎笉鍐嶆樉绀�
-        //            continue;
-        //        }
-
-        //        listShowDevice.Add(device);
-        //    }
-
-        //    var listSelect = new List<string>();
-        //    foreach (string mainkeys in this.dicEsixtDevice.Keys)
-        //    {
-        //        listSelect.Add(mainkeys);
-        //    }
-
-        //    var form = new SelectDeviceForm();
-        //    this.AddForm(form, listShowDevice, listSelect, false);
-        //    //娣诲姞缁戝畾鐩爣
-        //    form.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddBindTargets));
-
-        //    //璁惧閫夋嫨纭畾
-        //    form.ActionSelectDevice += (async (listDevice) =>
-        //    {
-        //        if (listDevice.Count == 0)
-        //        {
-        //            return;
-        //        }
-
-        //        var listNewDevice = await this.BindKeyDeviceTargets(key, listDevice,currentClusterID);
-
-        //        if (listNewDevice == null || listNewDevice.Count == 0)
-        //        {
-        //            return;
-        //        }
-
-        //        foreach (CommonDevice device in listNewDevice)
-        //        {
-        //            string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
-        //            this.dicEsixtDevice[mainKeys] = device;
-
-        //            Application.RunOnMainThread(() =>
-        //            {
-        //                this.AddRowlayout(device);
-        //            });
-        //        }
-        //    });
-        //}
-
-        ///// <summary>
-        ///// 娣诲姞琛�
-        ///// </summary>
-        ///// <param name="device"></param>
-        //private void AddRowlayout(CommonDevice device)
-        //{
-        //    string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
-        //    this.dicEsixtDevice[mainKeys] = device;
-
-        //    var row = new DeviceRoomViewRow(this.listView, device);
-        //    row.ChangedChidrenBindMode(row.btnIcon, ChidrenBindMode.BindEventOnly);
-        //    row.ChangedChidrenBindMode(row.btnRoom, ChidrenBindMode.BindEventOnly);
-        //    row.ChangedChidrenBindMode(row.btnDevie, ChidrenBindMode.BindEventOnly);
-
-        //    //鍒犻櫎
-        //    var btnDelete = new RowDeleteButton();
-        //    row.AddRightView(btnDelete);
-        //    btnDelete.MouseUpEventHandler += (sender, e) =>
-        //    {
-        //        //纭瑕佸垹闄ゅ悧锛�
-        //        string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
-        //        this . ShowConfirmMsg(msg, "DeleteTargetDevice", device, row);
-        //    };
-        //}
-
-
+        /// <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