From e5f993f52e09eb46878baced83bb8492f147d41c Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期一, 04 十一月 2019 17:58:40 +0800
Subject: [PATCH] 2019-11-04-1

---
 ZigbeeApp/Shared/Common/Device.cs |  642 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 503 insertions(+), 139 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 7b123ae..a7e9d6f 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -44,9 +44,13 @@
             get
             {
                 var list = new List<CommonDevice>();
-                foreach (var device in dicAllDevice.Values)
+                foreach (var listMac in this.dicDeviceSort.Values)
                 {
-                    list.Add(device);
+                    foreach (var strMac in listMac)
+                    {
+                        var listTemp = this.GetDevicesByMac(strMac);
+                        list.AddRange(listTemp);
+                    }
                 }
                 return list;
             }
@@ -81,13 +85,13 @@
         /// </summary>
         private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
         /// <summary>
+        /// 璁惧Mac椤哄簭(閲岄潰鏄疢ac鍦板潃)
+        /// </summary>
+        private Dictionary<string, List<string>> dicDeviceSort = null;
+        /// <summary>
         /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧
         /// </summary>
         public const string deviceFirstName = "Device_";
-        /// <summary>
-        /// 閿�
-        /// </summary>
-        private object objLock = new object();
 
         #endregion
 
@@ -99,7 +103,7 @@
         public void ReFreshByLocal()
         {
             this.dicAllDevice.Clear();
-            this.dicDeviceEpoint.Clear();
+            this.dicDeviceEpoint.Clear();
 
             //鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D
             this.InitDeviceDefultNameIDList();
@@ -171,7 +175,9 @@
                 }
             }
             //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢
-            this.DeleteGatewayFileByMemberModel();
+            this.DeleteGatewayFileByMemberModel();
+            //鍒濆鍖栬澶囬『搴�
+            this.InitDeviceSort();
         }
 
         /// <summary>
@@ -184,11 +190,15 @@
                 return;
             }
             var listId = new HashSet<string>();
-            foreach (var device in this.dicAllDevice.Values)
+
+            lock (dicAllDevice)
             {
-                if (listId.Contains(device.CurrentGateWayId) == false)
+                foreach (var device in this.dicAllDevice.Values)
                 {
-                    listId.Add(device.CurrentGateWayId);
+                    if (listId.Contains(device.CurrentGateWayId) == false)
+                    {
+                        listId.Add(device.CurrentGateWayId);
+                    }
                 }
             }
             var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
@@ -213,11 +223,11 @@
         /// <param name="zbGateway">缃戝叧瀵硅薄</param>
         /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param>
         /// <returns>涓�鐩磋繑鍥瀟rue</returns>
-        public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
+        public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
         {
             //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧
             List<CommonDevice> listDevice = new List<CommonDevice>();
-            List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction);
+            List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, deviceComingAction);
 
             if (list == null)
             {
@@ -246,7 +256,7 @@
                 //娣诲姞缂撳瓨
                 this.AddDeviceToMemory(ref device);
 
-                //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� 
+                //绉婚櫎瀛樺湪鐨勮澶囧唴瀛�
                 string maikey = this.GetDeviceMainKeys(device);
                 if (dicExist.ContainsKey(maikey) == true)
                 {
@@ -302,6 +312,16 @@
         /// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param>
         public void AddDeviceToMemory(ref CommonDevice device)
         {
+            if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
+            {
+                dicDeviceSort[device.CurrentGateWayId] = new List<string>();
+            }
+            if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
+            {
+                //淇濆瓨椤哄簭
+                dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
+                UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
+            }
             string mainKeys = this.GetDeviceMainKeys(device);
             //濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠�
             if (device is OTADevice)
@@ -329,17 +349,20 @@
                 return;
             }
 
-            if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+            lock (dicAllDevice)
             {
-                //浜ゆ崲灞炴��
-                var tempDevice = this.dicAllDevice[mainKeys];
-                //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
-                this.SetDeviceInfoToMain(tempDevice, device);
-                device = tempDevice;
-            }
-            else
-            {
-                this.dicAllDevice[mainKeys] = device;
+                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+                {
+                    //浜ゆ崲灞炴��
+                    var tempDevice = this.dicAllDevice[mainKeys];
+                    //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑
+                    this.SetDeviceInfoToMain(tempDevice, device);
+                    device = tempDevice;
+                }
+                else
+                {
+                    this.dicAllDevice[mainKeys] = device;
+                }
             }
 
             //璁惧鍥炶矾鏀堕泦
@@ -456,16 +479,19 @@
         /// <param name="device"></param>
         private void BackupDeviceAfterReName(CommonDevice device)
         {
-            string mainKeys = this.GetDeviceMainKeys(device);
-            if (this.dicAllDevice.ContainsKey(mainKeys) == false)
+            lock (dicAllDevice)
             {
-                return;
-            }
-            this.dicAllDevice[mainKeys] = device;
-            device.ReSave();
+                string mainKeys = this.GetDeviceMainKeys(device);
+                if (this.dicAllDevice.ContainsKey(mainKeys) == false)
+                {
+                    return;
+                }
+                this.dicAllDevice[mainKeys] = device;
+                device.ReSave();
 
-            //娣诲姞鑷姩澶囦唤
-            HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+                //娣诲姞鑷姩澶囦唤
+                HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+            }
         }
 
         #endregion
@@ -495,6 +521,13 @@
                 this.ShowErrorMsg(msg);
                 return false;
             }
+            if (dicDeviceSort.ContainsKey(listdevice[0].CurrentGateWayId) == true &&
+                dicDeviceSort[listdevice[0].CurrentGateWayId].Contains(info.DeviceAddr) == true)
+            {
+                //淇濆瓨椤哄簭
+                dicDeviceSort[listdevice[0].CurrentGateWayId].Remove(info.DeviceAddr);
+                UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
+            }
 
             //鍒犻櫎鏂囦欢
             foreach (CommonDevice device in listdevice)
@@ -513,9 +546,12 @@
         {
             //鍒犻櫎缂撳瓨
             string mainKeys = this.GetDeviceMainKeys(device);
-            if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+            lock (dicAllDevice)
             {
-                this.dicAllDevice.Remove(mainKeys);
+                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+                {
+                    this.dicAllDevice.Remove(mainKeys);
+                }
             }
 
             //鍒犻櫎璁惧鏂囦欢
@@ -645,13 +681,34 @@
         public List<CommonDevice> GetDeviceByGatewayID(string gwId)
         {
             List<CommonDevice> list = new List<CommonDevice>();
-            //鍚勭綉鍏崇殑鎵�鏈夎澶�
-            foreach (CommonDevice device in this.dicAllDevice.Values)
+            lock (dicAllDevice)
             {
-                if (gwId == device.CurrentGateWayId)
+                List<string> listSort = null;
+                if (dicDeviceSort.ContainsKey(gwId) == false)
                 {
-                    list.Add(device);
+                    dicDeviceSort[gwId] = new List<string>();
                 }
+                listSort = dicDeviceSort[gwId];
+
+                //鍚勭綉鍏崇殑鎵�鏈夎澶�
+                foreach (CommonDevice device in this.dicAllDevice.Values)
+                {
+                    if (gwId == device.CurrentGateWayId)
+                    {
+                        if (listSort.Contains(device.DeviceAddr) == false)
+                        {
+                            listSort.Add(device.DeviceAddr);
+                        }
+                    }
+                }
+                //鎺掑簭
+                foreach (var strMac in listSort)
+                {
+                    var listTemp = this.GetDevicesByMac(strMac);
+                    list.AddRange(listTemp);
+                }
+                //淇濆瓨椤哄簭
+                UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
             }
 
             return list;
@@ -664,9 +721,12 @@
         /// <returns></returns>
         public CommonDevice GetDevice(string mainKeys)
         {
-            if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+            lock (dicAllDevice)
             {
-                return this.dicAllDevice[mainKeys];
+                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
+                {
+                    return this.dicAllDevice[mainKeys];
+                }
             }
             return null;
         }
@@ -947,6 +1007,7 @@
             this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
 
             btnIcon.UnSelectedImagePath = unSelectFilePath;
+            btnIcon.SelectedImagePath = selectFilePath;
         }
 
         /// <summary>
@@ -1102,14 +1163,14 @@
         public DeviceUI GetDeviceUI(string filePath)
         {
             string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
-            if (arry.Length != 5)
+            if (arry.Length != 4)
             {
                 return null;
             }
             //鍒涘缓涓�涓柊鐨勪笢瑗跨粰杩囧幓
             var deviceUi = new DeviceUI();
-            deviceUi.DeviceAddr = arry[3];
-            deviceUi.DeviceEpoint = Convert.ToInt32(arry[4]);
+            deviceUi.DeviceAddr = arry[2];
+            deviceUi.DeviceEpoint = Convert.ToInt32(arry[3]);
             return deviceUi;
         }
 
@@ -1293,7 +1354,7 @@
             {
                 info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9;
                 info.BeloneType = DeviceBeloneType.A褰╃伅;
-                info.ConcreteType = DeviceConcreteType.ColorDimmableLight;
+                info.ConcreteType = DeviceConcreteType.ColorLight;
             }
             //8绌鸿皟
             else if (dicType.ContainsKey(DeviceType.Thermostat) == true)
@@ -1454,94 +1515,86 @@
         #region 鈻� 璁惧鎺掑簭___________________________
 
         /// <summary>
+        /// 鍒濆鍖栬澶囬『搴�
+        /// </summary>
+        private void InitDeviceSort()
+        {
+            //璇诲彇璁惧椤哄簭
+            this.dicDeviceSort = new Dictionary<string, List<string>>();
+            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile);
+            var strData = UserCenterLogic.LoadFileContent(fullName);
+            if (strData != null)
+            {
+                this.dicDeviceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
+            }
+            foreach (var device in dicAllDevice.Values)
+            {
+                if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
+                {
+                    dicDeviceSort[device.CurrentGateWayId] = new List<string>();
+                }
+                if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
+                {
+                    //鏂版坊鍔犵殑璁惧
+                    dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
+                }
+            }
+            foreach (var keys in dicDeviceSort.Keys)
+            {
+                var list = dicDeviceSort[keys];
+                for (int i = 0; i < list.Count; i++)
+                {
+                    if (this.dicDeviceEpoint.ContainsKey(list[i]) == false)
+                    {
+                        //杩欎釜涓滆タ鑾悕鐨勪笉瑙佷簡锛熷拰璁惧鍒楄〃鍖归厤涓嶄笂?
+                        list.RemoveAt(i);
+                        i--;
+                    }
+                }
+            }
+
+            //淇濆瓨椤哄簭
+            UserCenterLogic.SaveFileContent(fullName, dicDeviceEpoint);
+        }
+
+        /// <summary>
         /// 璁惧鎺掑簭
         /// </summary>
-        /// <param name="listDevice">璁惧瀵硅薄</param>
+        /// <param name="listDevice">闇�瑕佹帓搴忕殑璁惧鍒楄〃</param>
         /// <returns></returns>
-        public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice)
-        {
-            List<CommonDevice> listSort = new List<CommonDevice>();
-            var list = this.SortDeviceListByRule(listDevice);
-            listSort.AddRange(list);
-
-            return listSort;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="listDevice">璁惧瀵硅薄</param>
-        /// <returns></returns>
-        private List<CommonDevice> SortDeviceListByRule(List<CommonDevice> listDevice)
-        {
-            //璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType)  value锛氬瓨鏀捐澶囩殑瀹瑰櫒)
-            var dic = this.GetDeviceSortRule();
-            foreach (CommonDevice device in listDevice)
-            {
-                if (device is IASZone)
-                {
-                    //浼犳劅鍣ㄦ湁寰堝绉�
-                    var strType = ((IASZone)device).DeviceInfo.DeviceType.ToString();
-                    if (dic.ContainsKey(strType) == false || dic[strType] == null)
-                    {
-                        dic[strType] = new List<CommonDevice>();
-                    }
-                    dic[strType].Add(device);
-                    continue;
-                }
-                string checkKeys = device.Type.ToString();
-                if (dic.ContainsKey(checkKeys) == false || dic[checkKeys] == null)
-                {
-                    dic[checkKeys] = new List<CommonDevice>();
-                }
-                dic[checkKeys].Add(device);
-            }
-
-            List<CommonDevice> lstSort = new List<CommonDevice>();
-            foreach (var list in dic.Values)
-            {
-                if (list != null && list.Count > 0)
-                {
-                    lstSort.AddRange(list);
-                }
-            }
-            return lstSort;
-        }
-
-        /// <summary>
-        /// 鑾峰彇璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType)  value锛氬瓨鏀捐澶囩殑瀹瑰櫒)
-        /// </summary>
-        /// <returns></returns>
-        private Dictionary<string, List<CommonDevice>> GetDeviceSortRule()
+        public List<CommonDevice> SortDevice(List<CommonDevice> listDevice)
         {
             var dic = new Dictionary<string, List<CommonDevice>>();
-            //鎺у埗闈㈡澘
-            dic[DeviceType.OnOffSwitch.ToString()] = null;
-            //鍗峰笜
-            dic[DeviceType.WindowCoveringDevice.ToString()] = null;
-            //璋冨厜鐏�
-            dic[DeviceType.ColorDimmableLight.ToString()] = null;
-            //缁х數鍣�
-            dic[DeviceType.OnOffOutput.ToString()] = null;
-            //绌烘皵寮�鍏�
-            dic[DeviceType.AirSwitch.ToString()] = null;
-            //闂ㄧ獥纾佷紶鎰熷櫒
-            dic["21"] = null;
-            dic["22"] = null;
-            //姘存蹈浼犳劅鍣�
-            dic["42"] = null;
-            //鐑熼浘浼犳劅鍣�
-            dic["40"] = null;
-            //绱ф�ユ寜閽�
-            dic["44"] = null;
-            //鐕冩皵浼犳劅鍣�
-            dic["43"] = null;
-            //杩愬姩浼犳劅鍣�
-            dic["13"] = null;
-            //閽ュ寵鎵�
-            dic["277"] = null;
-
-            return dic;
+            for (int i = 0; i < listDevice.Count; i++)
+            {
+                if (dic.ContainsKey(listDevice[i].DeviceAddr) == false)
+                {
+                    dic[listDevice[i].DeviceAddr] = new List<CommonDevice>();
+                }
+                dic[listDevice[i].DeviceAddr].Add(listDevice[i]);
+            }
+            var list = new List<CommonDevice>();
+            var listCheck = new HashSet<string>();
+            foreach (var listSort in this.dicDeviceSort.Values)
+            {
+                for (int i = 0; i < listSort.Count; i++)
+                {
+                    if (dic.ContainsKey(listSort[i]) == true && listCheck.Contains(listSort[i]) == false)
+                    {
+                        listCheck.Add(listSort[i]);
+                        dic[listSort[i]].Sort((obj1, obj2) =>
+                        {
+                            if (obj1.DeviceEpoint > obj2.DeviceEpoint)
+                            {
+                                return 1;
+                            }
+                            return -1;
+                        });
+                        list.AddRange(dic[listSort[i]]);
+                    }
+                }
+            }
+            return list;
         }
 
         #endregion
@@ -1647,14 +1700,40 @@
         #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________
 
         /// <summary>
-        /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚鈽呪槄鈽呪槄鈽呪槄鈽�)
+        /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢鈽呪槄鈽呪槄鈽呪槄鈽�)
         /// </summary>
         /// <param name="zbGateway">缃戝叧瀵硅薄</param>
-        /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param>
+        /// <param name="ignoreTime">鏄惁鏃犺鏃堕棿,true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param>
+        /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
         /// <returns></returns>
-        public async Task<List<CommonDevice>> GetDeviceListFromGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES)
+        public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES)
         {
+            if (ignoreTime == false)
+            {
+                if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000)
+                {
+                    //涓嶆棤瑙嗘椂闂�,杩斿洖鏈湴璁惧鍒楄〃
+                    var listTemp = this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
+                    if (deviceComingAction != null)
+                    {
+                        for (int i = 0; i < listTemp.Count; i++)
+                        {
+                            try
+                            {
+                                //鍥炶皟鍑芥暟
+                                deviceComingAction.Invoke(listTemp[i]);
+                            }
+                            //Log鍑哄姏
+                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
+                        }
+                    }
+                    deviceComingAction = null;
+                    return listTemp;
+                }
+            }
+            zbGateway.LastDateTime = DateTime.Now;
+
             //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭�
             string nowFormId = UserCenterResourse.NowActionFormID;
 
@@ -1711,8 +1790,13 @@
                         var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
                         if (device != null)
                         {
-                            //鍥炶皟鍑芥暟
-                            deviceComingAction?.Invoke(device);
+                            try
+                            {
+                                //鍥炶皟鍑芥暟
+                                deviceComingAction?.Invoke(device);
+                            }
+                            //Log鍑哄姏
+                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
 
                             listDevice.Add(device);
                         }
@@ -1730,13 +1814,13 @@
             try
             {
                 var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
-                await realWay.Send("GetDeviceInfo", jObject.ToString());
+                realWay.Send("GetDeviceInfo", jObject.ToString());
             }
             catch { canBreak = true; }
 
             while (canBreak == false && TimeOut < 60)
             {
-                await Task.Delay(100);
+                System.Threading.Thread.Sleep(100);
                 TimeOut++;
             }
 
@@ -1769,8 +1853,7 @@
                 }
             }
 
-            //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚)
-            deviceComingAction?.Invoke(null);
+            //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚)
             deviceComingAction = null;
 
             return listDevice;
@@ -1837,6 +1920,7 @@
             mainDevice.DriveCode = device.DeviceInfo.DriveCode;
             mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
             mainDevice.Profile = device.DeviceInfo.Profile;
+            mainDevice.Type = device.Type;
 
             //鍥轰欢鐗堟湰
             mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
@@ -1857,9 +1941,9 @@
             mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
             mainDevice.AttributeStatus.Clear();
             mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
-            
+
             //濡傛灉鏄俯搴︿紶鎰熷櫒
-            if (mainDevice is TemperatureSensor)
+            if (mainDevice.Type == DeviceType.TemperatureSensor)
             {
                 //杈撳嚭鏃� 1026:娓╁害浼犳劅鍣� 1029:婀垮害浼犳劅鍣�
                 foreach (var data in mainDevice.OutClusterList)
@@ -1872,6 +1956,24 @@
                     {
                         ((TemperatureSensor)mainDevice).SensorDiv = 1;
                     }
+                }
+            }
+            //濡傛灉鏄皟鍏夊櫒
+            else if (mainDevice.Type == DeviceType.DimmableLight )
+            {
+                mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                if (mainDevice.IsCustomizeImage == false)
+                {
+                    mainDevice.IconPath = "Device/Light.png";
+                }
+            }
+            //濡傛灉鏄僵鐏殑璇�
+            else if ( mainDevice.Type == DeviceType.ColorDimmableLight)
+            {
+                mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
+                if (mainDevice.IsCustomizeImage == false)
+                {
+                    mainDevice.IconPath = "Device/ColorLight.png";
                 }
             }
         }
@@ -1973,7 +2075,7 @@
             this.dicDeviceModelIdEnum["H06C"] = "2800-2800";//鏅鸿兘闂ㄩ攣(H06C)
 
             //=========鈽呪槄绌鸿皟绫�(3600-3899)鈽呪槄=========
-            this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡
+            this.dicDeviceModelIdEnum["MAC/GW-ZB.10"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡
 
             //=========鈽呪槄涓户鍣ㄧ被(3900-3999)鈽呪槄=========
             this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee涓户鍣�
@@ -1998,4 +2100,266 @@
 
         #endregion
     }
+
+    #region 鈻� 鑷畾涔夎澶囩被鍨媉________________________
+
+    /// <summary>
+    /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囩殑鍏蜂綋銆愯澶囩被鍨嬨��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��)</para>
+    /// <para>鍙橀噺鍚嶅彲浠ヤ綔涓恒�愯澶囩被鍨嬨�戝浘鐗�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para>
+    /// </summary>
+    public enum DeviceConcreteType
+    {
+        //瀹氫箟瑙勫垯锛氥�愯澶囩被鍨嬨�戝浘鐗囧悕瀛�=LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��
+
+        /// <summary>
+        /// 鏈煡璁惧
+        /// </summary>
+        UnKownDevice = -1,
+
+        //=========鈽呪槄绐楀笜绫�(100-199)鈽呪槄=========
+        /// <summary>
+        /// 绐楀笜
+        /// </summary>
+        Curtain = -100,
+        /// <summary>
+        /// 鏅鸿兘寮�鍚堝笜鐢垫満 闀滃儚id锛�100
+        /// </summary>
+        Curtain_AutoOpen = 100,
+        /// <summary>
+        /// 鏅鸿兘绠$姸鐢垫満 闀滃儚id锛�101
+        /// </summary>
+        Curtain_Siphonate = 101,
+
+        //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄=========
+        /// <summary>
+        /// 鎸夐敭闈㈡澘
+        /// </summary>
+        ButtonPanel = -200,
+        /// <summary>
+        /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�4璺户鐢靛櫒搴曞骇) 闀滃儚id锛�200
+        /// </summary>
+        ButtonPanel_Four = 200,
+        /// <summary>
+        /// 3鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�3璺户鐢靛櫒搴曞骇) 闀滃儚id锛�201
+        /// </summary>
+        ButtonPanel_Three = 201,
+        /// <summary>
+        /// 2鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�2璺户鐢靛櫒搴曞骇) 闀滃儚id锛�202
+        /// </summary>
+        ButtonPanel_Two = 202,
+        /// <summary>
+        /// 12鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�1璺户鐢靛櫒搴曞骇) 闀滃儚id锛�203
+        /// </summary>
+        ButtonPanel_Twelve = 203,
+        /// <summary>
+        /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉匡紙鍙甫鐢垫簮搴曞骇锛� 闀滃儚id锛�210
+        /// </summary>
+        ButtonPanel_FourNotPower = 210,
+
+        //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
+        /// <summary>
+        /// 浼犳劅鍣�
+        /// </summary>
+        Sensor = -1200,
+        /// <summary>
+        /// pir浼犳劅鍣�220 闀滃儚id锛�1200
+        /// </summary>
+        Sensor_Pir = 1200,
+
+        //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄=========
+        /// <summary>
+        /// 鐕冩皵浼犳劅鍣�
+        /// </summary>
+        Sensor_CarbonMonoxide = 1300,
+        /// <summary>
+        /// 闂ㄧ獥浼犳劅鍣�
+        /// </summary>
+        Sensor_DoorWindow = 1301,
+        /// <summary>
+        /// 鐑熼浘浼犳劅鍣�
+        /// </summary>
+        Sensor_Fire = 1302,
+        /// <summary>
+        /// 绾㈠浼犳劅鍣�
+        /// </summary>
+        Sensor_Infrared = 1303,
+        /// <summary>
+        /// 姘翠镜浼犳劅鍣�
+        /// </summary>
+        Sensor_Water = 1304,
+        /// <summary>
+        /// 绱ф�ユ寜閽�
+        /// </summary>
+        Sensor_EmergencyButton = 1305,
+        /// <summary>
+        /// 杩愬姩浼犳劅鍣�
+        /// </summary>
+        Sensor_Motion = -1306,
+        /// <summary>
+        /// 閽ュ寵鎵�
+        /// </summary>
+        Sensor_Keyfob = -1307,
+        /// <summary>
+        /// 娓╂箍搴︿紶鎰熷櫒
+        /// </summary>
+        Sensor_TemperatrueHumidity = -1308,
+        /// <summary>
+        /// 娓╁害浼犳劅鍣�
+        /// </summary>
+        Sensor_Temperatrue = -1309,
+        /// <summary>
+        /// 婀垮害浼犳劅鍣�
+        /// </summary>
+        Sensor_Humidity = -1310,
+
+        //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄=========
+        /// <summary>
+        /// 缁х數鍣�
+        /// </summary>
+        Relay = -2300,
+        /// <summary>
+        /// 涓夎矾缁х數鍣� 闀滃儚id锛�2300
+        /// </summary>
+        Relay_ThreeLoad = 2300,
+
+        //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
+        /// <summary>
+        /// 璋冨厜鍣�
+        /// </summary>
+        DimmableLight = -2500,
+        /// <summary>
+        /// 1璺皟鍏夊櫒灏忔ā鍧�
+        /// </summary>
+        DimmableLight_OneLoad = 2500,
+
+        //=========鈽呪槄鏅鸿兘闂ㄩ攣绫�(2800-????)鈽呪槄=========
+        /// <summary>
+        /// 鏅鸿兘闂ㄩ攣
+        /// </summary>
+        IntelligentLocks = -2800,
+        /// <summary>
+        /// H06C
+        /// </summary>
+        IntelligentLocks_H06C = 2800,
+
+        //=========鈽呪槄褰╃伅绫�(????-????)鈽呪槄=========
+        /// <summary>
+        /// 褰╃伅
+        /// </summary>
+        ColorLight = -10,
+
+        //=========鈽呪槄绌鸿皟(3600-3899)鈽呪槄=========
+        /// <summary>
+        /// 绌鸿皟
+        /// </summary>
+        AirConditioner = -3600,
+        /// <summary>
+        /// zigbee绌鸿皟缃戝叧妯″潡
+        /// </summary>
+        AirConditioner_ZbGateway = 3600,
+
+        //=========鈽呪槄涓户鍣�(3900-3999)鈽呪槄=========
+        /// <summary>
+        /// 涓户鍣�
+        /// </summary>
+        Repeater = -3900,
+        /// <summary>
+        /// zigbee涓户鍣� 闀滃儚id锛�3900
+        /// </summary>
+        Repeater_Zigbee = 3900,
+
+        //=========鈽呪槄绌烘皵寮�鍏崇被(4100-????)鈽呪槄=========
+        /// <summary>
+        /// 鏅鸿兘绌烘皵寮�鍏�
+        /// </summary>
+        AirSwitch = -4100,
+        /// <summary>
+        /// 寰柇浜戞帶鍒跺櫒 闀滃儚id锛�4100
+        /// </summary>
+        AirSwitch_CloudContr = 4100,
+
+        //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄=========
+        /// <summary>
+        /// 杞崲鍣�
+        /// </summary>
+        Converter = -4200,
+        /// <summary>
+        /// zigbee杞�485鍗忚杞崲鍣�
+        /// </summary>
+        Converter_Zb485 = 4200,
+        /// <summary>
+        /// zigbee杞琤uspro鍗忚杞崲鍣�
+        /// </summary>
+        Converter_ZbBuspro = 4201,
+    }
+
+    /// <summary>
+    /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囨墍灞炵殑銆愯澶囩绫汇��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨勫��)</para>
+    /// <para>杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para>
+    /// </summary>
+    public enum DeviceBeloneType
+    {
+        /// <summary>
+        /// 鏈煡璁惧
+        /// </summary>
+        A鏈煡璁惧 = 0,
+        /// <summary>
+        /// 绐楀笜(100-199)
+        /// </summary>
+        A绐楀笜 = 100,
+        /// <summary>
+        /// 鎸夐敭闈㈡澘(200-1199)
+        /// </summary>
+        A鎸夐敭闈㈡澘 = 200,
+        /// <summary>
+        /// 浼犳劅鍣�(1200-2299)
+        /// </summary>
+        A浼犳劅鍣� = 1200,
+        /// <summary>
+        /// 缁х數鍣�(2300-2499)
+        /// </summary>
+        A缁х數鍣� = 2300,
+        /// <summary>
+        /// 璋冨厜鍣�(2500-2799)
+        /// </summary>
+        A璋冨厜鍣� = 2500,
+        /// <summary>
+        /// 鏅鸿兘闂ㄩ攣(2800-????)
+        /// </summary>
+        A鏅鸿兘闂ㄩ攣 = 2800,
+        /// <summary>
+        /// 绌鸿皟(3600-3899)
+        /// </summary>
+        A绌鸿皟 = 3600,
+        /// <summary>
+        /// 涓户鍣�(3900-3999)
+        /// </summary>
+        A涓户鍣� = 3900,
+        /// <summary>
+        /// 绌烘皵寮�鍏�(4100-4199)
+        /// </summary>
+        A绌烘皵寮�鍏� = 4100,
+        /// <summary>
+        /// 杞崲鍣�(4200-4699)
+        /// </summary>
+        A杞崲鍣� = 4200,
+        /// <summary>
+        /// 褰╃伅
+        /// </summary>
+        A褰╃伅 = 9,
+        /// <summary>
+        /// 娓╂箍搴︿紶鎰熷櫒
+        /// </summary>
+        A娓╂箍搴︿紶鎰熷櫒 = 10,
+        /// <summary>
+        /// 娓╁害浼犳劅鍣�
+        /// </summary>
+        A娓╁害浼犳劅鍣� = 11,
+        /// <summary>
+        /// 婀垮害浼犳劅鍣�
+        /// </summary>
+        A婀垮害浼犳劅鍣� = 12
+    }
+
+    #endregion
 }

--
Gitblit v1.8.0