From 5986f63b75bd81c6cef262c670e9251c038cbf5d Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 17 十二月 2019 17:21:07 +0800
Subject: [PATCH] 合并一个版本

---
 ZigbeeApp/Shared/Common/Device.cs |  164 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 112 insertions(+), 52 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 7259cdb..acbcb17 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -72,6 +72,10 @@
         /// </summary>
         private Dictionary<string, string> dicDeviceModelIdChanged = null;
         /// <summary>
+        /// 鍥剧墖鍏辨湁(keys:鎸囧畾璁惧鐨勫叿浣撶被鍨� value:鎸囧畾鍏辨湁瀵硅薄鐨勫叿浣撶被鍨�)
+        /// </summary>
+        private Dictionary<string, string> dicPictrueShard = null;
+        /// <summary>
         /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(闈炲叕寮�)
         /// </summary>
         private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>();
@@ -107,8 +111,14 @@
             List<string> listFile = this.GetAllDeviceFile();
             foreach (string file in listFile)
             {
+                CommonDevice device = null;
                 //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞�
-                var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file);
+                try 
+                {
+                    device = CommonDevice.CommonDeviceByFilePath(file);
+                }
+                catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
+
                 if (device == null || device.CurrentGateWayId == null)
                 {
 #if DEBUG
@@ -533,6 +543,12 @@
         /// <param name="deleteRoom">鏄惁浠庢埧闂村垹闄�</param>
         public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
         {
+            if (deleteRoom == true && Room.CurrentRoom != null)
+            {
+                //浠庢埧闂翠腑鍒犻櫎
+                Room.CurrentRoom.DeleteDevice(device);
+            }
+
             //鍒犻櫎缂撳瓨
             string mainKeys = this.GetDeviceMainKeys(device);
             lock (dicAllDevice)
@@ -582,12 +598,6 @@
                     }
                 }
                 this.dicOTADevice.Remove(otaKeys);
-            }
-
-            if (deleteRoom == true && Room.CurrentRoom != null)
-            {
-                //浠庢埧闂翠腑鍒犻櫎
-                Room.CurrentRoom.DeleteDevice(device);
             }
         }
 
@@ -1033,6 +1043,13 @@
             //鑾峰彇瀹冨睘浜庝粈涔堢被鍨嬬殑璁惧
             var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
             string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType);
+            
+            //鍥剧墖鍏辨湁
+            if (this.dicPictrueShard.ContainsKey(strConcrete) == true)
+            {
+                strConcrete = this.dicPictrueShard[strConcrete];
+            }
+
             string strType = strConcrete.Replace("_", string.Empty);
             //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧�
             string imageFilePath = "RealDevice/" + strType + ".png";
@@ -1105,6 +1122,12 @@
         {
             //灏嗗叿浣撶被鍨嬭浆瀛楃涓�
             string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
+            //鍥剧墖鍏辨湁
+            if (this.dicPictrueShard.ContainsKey(strSpecific) == true)
+            {
+                strSpecific = this.dicPictrueShard[strSpecific];
+            }
+
             string strType = strSpecific.Replace("_", string.Empty);
             //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧�
             string imageFilePath = "Device/" + strType + ".png";
@@ -1397,7 +1420,7 @@
                             temperatrue = true;
                         }
                         //婀垮害浼犳劅鍣�
-                        else if(((TemperatureSensor)device).SensorDiv == 2)
+                        else if (((TemperatureSensor)device).SensorDiv == 2)
                         {
                             humidity = true;
                         }
@@ -1639,16 +1662,16 @@
         /// <returns></returns>
         public string AppendVersion(int versionValue)
         {
-            //杞负16杩涘埗
-            string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0');
+            //鐩存帴鏄�10杩涘埗
+            string txt10 = Convert.ToString(versionValue).PadLeft(4, '0');
             //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫��
-            int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16);
+            int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2));
             //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫��
-            int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16);
+            int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2));
 
             //Ver.
             string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
-            return ver + value1 + "." + value2.ToString().PadLeft(3, '0');
+            return ver + value1 + "." + value2.ToString().PadLeft(2, '0');
         }
 
         /// <summary>
@@ -1745,53 +1768,61 @@
             int receiveCount = 0;
             //璁惧鍒楄〃
             var listDevice = new List<CommonDevice>();
-
+            //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+            var listCheck = new HashSet<string>();
             Action<string, string> getDeviceAction = (topic, message) =>
             {
-                try
+                if (topic == gatewayID + "/" + "DeviceInfoRespon")
                 {
-                    if (topic == gatewayID + "/" + "DeviceInfoRespon")
+                    try
                     {
-                        TimeOut = 0;
-                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                        var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
-                        if (totalNum == 0)
+                        lock (listDevice)
                         {
-                            //杩欎釜缃戝叧娌℃湁璁惧
-                            canBreak = true;
-                            return;
-                        }
-                        if (deviceCount == -1)
-                        {
-                            //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
-                            deviceCount = totalNum;
-                        }
-                        //璁惧鎺ユ敹鏁�
-                        receiveCount++;
+                            //璁惧鎺ユ敹鏁�
+                            receiveCount++;
 
-                        var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
-                        //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
-                        var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
-                        if (device != null)
-                        {
-                            try
+                            TimeOut = 0;
+                            var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                            var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
+                            if (totalNum == 0)
                             {
-                                //鍥炶皟鍑芥暟
-                                deviceComingAction?.Invoke(device);
+                                //杩欎釜缃戝叧娌℃湁璁惧
+                                canBreak = true;
+                                return;
                             }
-                            //Log鍑哄姏
-                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
+                            if (deviceCount == -1)
+                            {
+                                //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
+                                deviceCount = totalNum;
+                            }
 
-                            listDevice.Add(device);
-                        }
-                        if (deviceCount == receiveCount)
-                        {
-                            //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
-                            canBreak = true;
+                            var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
+                            //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
+                            var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
+                            if (device != null)
+                            {
+                                string mainkeys = this.GetDeviceMainKeys(device);
+                                //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+                                if (listCheck.Contains(mainkeys) == false)
+                                {
+                                    //鍥炶皟鍑芥暟
+                                    deviceComingAction?.Invoke(device);
+                                    listDevice.Add(device);
+
+                                    listCheck.Add(mainkeys);
+                                }
+                            }
                         }
                     }
+                    //Log鍑哄姏
+                    catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
+
+                    if (receiveCount == deviceCount && deviceCount != -1)
+                    {
+                        //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
+                        canBreak = true;
+                    }
                 }
-                catch { }
             };
 
             realWay.Actions += getDeviceAction;
@@ -1943,7 +1974,7 @@
                 }
             }
             //濡傛灉鏄皟鍏夊櫒
-            else if (mainDevice.Type == DeviceType.DimmableLight )
+            else if (mainDevice.Type == DeviceType.DimmableLight)
             {
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
                 if (mainDevice.IsCustomizeImage == false)
@@ -1952,7 +1983,7 @@
                 }
             }
             //濡傛灉鏄僵鐏殑璇�
-            else if ( mainDevice.Type == DeviceType.ColorDimmableLight)
+            else if (mainDevice.Type == DeviceType.ColorDimmableLight)
             {
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
                 if (mainDevice.IsCustomizeImage == false)
@@ -2027,6 +2058,14 @@
             //瀹氫箟瑙勫垯锛氭ā鍧桰D(宸茬炕璇�)=璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互)
             //绗竴涓�兼槸:DeviceConcreteType  绗簩涓�兼槸:DeviceBeloneType
 
+            //*********************************************************************
+            //鏂拌澶囨坊鍔犳柟娉曪細
+            //1銆佸湪杩欓噷濉啓涓婃ā鍧桰D锛岀劧鍚庢槸 DeviceConcreteType 锛岀劧鍚庢槸 DeviceBeloneType
+            //2銆佺劧鍚庡湪鏈�涓嬮潰娣诲姞銆愯澶囩殑鍏蜂綋绫诲瀷銆戯紝銆愯澶囩殑鎵�灞炵被鍨嬨��
+            //3銆佸凡璁惧鐨勫叿浣撶被鍨嬩负鍚嶅瓧(鍘绘帀銆�-銆�)娣诲姞璁惧鐨勩�愭墍灞炲浘鐗囥�戯紝銆愮湡瀹炵墿鐞嗗浘鐗囥�戙�傚洖璺浘鐗囬渶瑕佺壒娈婂鐞�
+            //4銆佹坊鍔燫鏂囦欢,娣诲姞Language鏂囦欢
+            //*********************************************************************
+
             //=========鈽呪槄寮�鍚堝笜绫�(100-199)鈽呪槄=========
             this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//鏅鸿兘寮�鍚堝笜鐢垫満
             this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//鏅鸿兘绠$姸鐢垫満
@@ -2037,6 +2076,9 @@
             this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2鎸夐敭瑙︽懜闈㈡澘
             this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12鎸夐敭瑙︽懜闈㈡澘
             this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4鎸夐敭瑙︽懜闈㈡澘(鍙甫鐢垫簮搴曞骇)
+            this.dicDeviceModelIdEnum["MPT4R4L/S-ZB1.8"] = "220-200";//绠�绾�4鎸夐敭闈㈡澘
+            this.dicDeviceModelIdEnum["MPT3R3L/S-ZB1.8"] = "221-200";//绠�绾�3鎸夐敭闈㈡澘
+            this.dicDeviceModelIdEnum["MPT2R2L/S-ZB1.8"] = "222-200";//绠�绾�2鎸夐敭闈㈡澘
 
             //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
             this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir浼犳劅鍣�220
@@ -2071,7 +2113,7 @@
             this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee杞琤uspro鍗忚杞崲鍣�
             this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee杞�485鍗忚杞崲鍣�
 
-            //闇�瑕佷氦鎹㈢殑妯″潡ID
+            //鉁┾湬鉁┾湬鉁╅渶瑕佷氦鎹㈢殑妯″潡ID鉁┾湬鉁┾湬鉁�
             this.dicDeviceModelIdChanged = new Dictionary<string, string>();
             //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫烩槄鈽�=========
             this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//鐕冩皵浼犳劅鍣�
@@ -2080,6 +2122,12 @@
             this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//绾㈠浼犳劅鍣�
             this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//姘存蹈浼犳劅鍣�
             this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//绱ф�ユ寜閿�
+
+            //鉁┾湬鉁┾湬鉁╅渶瑕佸叡鏈夌殑鍥剧墖瀵硅薄鉁┾湬鉁┾湬鉁�
+            this.dicPictrueShard = new Dictionary<string, string>();
+            this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭闈㈡澘 娌跨敤 4鎸夐敭鐨勫浘鏍�
+            this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//绠�绾�3鎸夐敭闈㈡澘 娌跨敤 3鎸夐敭鐨勫浘鏍�
+            this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//绠�绾�2鎸夐敭闈㈡澘 娌跨敤 2鎸夐敭鐨勫浘鏍�
         }
 
         #endregion
@@ -2139,6 +2187,18 @@
         /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉匡紙鍙甫鐢垫簮搴曞骇锛� 闀滃儚id锛�210
         /// </summary>
         ButtonPanel_FourNotPower = 210,
+        /// <summary>
+        /// 绠�绾�4鎸夐敭闈㈡澘 闀滃儚id锛�220
+        /// </summary>
+        ButtonPanel_SimpleFour = 220,
+        /// <summary>
+        /// 绠�绾�3鎸夐敭闈㈡澘 闀滃儚id锛�221
+        /// </summary>
+        ButtonPanel_SimpleThree = 221,
+        /// <summary>
+        /// 绠�绾�2鎸夐敭闈㈡澘 闀滃儚id锛�222
+        /// </summary>
+        ButtonPanel_SimpleTwo = 222,
 
         //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄=========
         /// <summary>
@@ -2258,7 +2318,7 @@
         /// </summary>
         AirSwitch = -4100,
         /// <summary>
-        /// 寰柇浜戞帶鍒跺櫒 闀滃儚id锛�4100
+        /// 鏅鸿兘绌哄紑 闀滃儚id锛�4100
         /// </summary>
         AirSwitch_CloudContr = 4100,
 

--
Gitblit v1.8.0