From 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 19 十一月 2020 10:23:45 +0800
Subject: [PATCH] Evoyo.Home1.1.0120111601_Release

---
 ZigbeeApp/Shared/Common/Device.cs | 1023 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 619 insertions(+), 404 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index b94b3e0..ff806cc 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -81,10 +81,6 @@
         /// 璁惧鐨勬�诲洖璺�(keys:Mac鍦板潃  value:鍏ㄩ儴绔彛鍙�)
         /// </summary>
         private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
-        /// <summary>
-        /// 鐗╃悊璁惧灞炰簬鍝釜鎴块棿鐨勮褰�
-        /// </summary>
-        private Dictionary<string, string> dicDeviceRoomId = null;
 
         #endregion
 
@@ -99,7 +95,7 @@
             this.dicDeviceEpoint.Clear();
 
             //鍒濆鍖栬澶囨灇涓�
-            this.InitDeviceModelIdEnum();
+            this.InitDeviceModelIdEnum();
 
             //鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠�
             List<string> listFile = this.GetAllDeviceFile();
@@ -107,9 +103,16 @@
             {
                 CommonDevice device = null;
                 //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞�
-                try 
+                try
                 {
-                    device = CommonDevice.CommonDeviceByFilePath(file);
+                    //璇诲彇瀹冪殑鍐呭
+                    var fileData = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(Config.Instance.FullPath, file));
+                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(fileData);
+                    if (jobject.Property("DeviceID") == null)
+                    {
+                        continue;
+                    }
+                    device = CommonDevice.CommonDeviceByByteString(Convert.ToInt32(jobject["DeviceID"].ToString()), fileData);
                 }
                 catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
 
@@ -152,6 +155,15 @@
                 }
                 this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
 
+                //瀵瑰簲鏃х増鏈殑璁惧鏂囦欢 Device_OnoffOutput_abcdfrtgg_01
+                bool bolSave = file.Split(new string[] { "_" }, StringSplitOptions.None).Length == 4;
+                if (bolSave == true)
+                {
+                    //鍒犳帀杩欎釜鏂囦欢,閲嶆柊鐢熸垚
+                    HdlAutoBackupLogic.DeleteFile(file);
+                    Global.DeleteFilebyHomeId(file);
+                }
+
                 //妫�娴婾i鍥剧墖鏄惁姝g‘,杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛�
                 if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
                 {
@@ -159,12 +171,28 @@
                     device.IconPath = string.Empty;
                     device.ReSave();
                     HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+
+                    bolSave = false;
+                }
+                //閲嶆柊鐢熸垚鏂囦欢
+                if (bolSave == true)
+                {
+                    device.ReSave();
+                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                 }
             }
             //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢
             this.DeleteGatewayFileByMemberModel();
             //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
-            this.InitRealDeviceRoomId();
+            HdlRoomLogic.Current.InitRealDeviceRoomId();
+
+#if DEBUG
+            if (UserCenterResourse.HideOption.CenterHideMenu == 1)
+            {
+                //妫�娴嬩竴浜涗唬鐮侀厤缃�(debug)
+                this.CheckOhtherSettion();
+            }
+#endif
         }
 
         /// <summary>
@@ -200,6 +228,38 @@
             }
         }
 
+        /// <summary>
+        /// 妫�娴嬩竴浜涗唬鐮侀厤缃�(debug)
+        /// </summary>
+        private void CheckOhtherSettion()
+        {
+            foreach (var item in Enum.GetValues(typeof(DeviceType)))
+            {
+                string itemName = item.ToString();
+                int itemValue = (int)item;
+                if (itemName == "UnKown" || itemName == "ZbGateway")
+                {
+                    continue;
+                }
+                var device = this.NewDeviceObjectByDeviceId((DeviceType)itemValue, 1);
+                string strMsg = string.Empty;
+                if (device == null)
+                {
+                    strMsg = itemName + "娌℃湁瀹炶(1)";
+                }
+                device = CommonDevice.CommonDeviceByByteString(itemValue, "{}");
+                if (device == null)
+                {
+                    strMsg += "\r\n" + itemName + "娌℃湁瀹炶(2)";
+                }
+                if (strMsg != string.Empty)
+                {
+                    this.ShowErrorMsg(strMsg);
+                    return;
+                }
+            }
+        }
+
         #endregion
 
         #region 鈻� 娣诲姞璁惧___________________________
@@ -208,14 +268,14 @@
         /// <para>灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚)</para>
         /// <para>-1:寮傚父 1:姝e父 2:璁惧淇℃伅缂烘崯</para>
         /// </summary>
-        /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+        /// <param name="gatewayId">缃戝叧Id</param>
         /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param>
-        public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway, bool useLocalConnect)
+        public int SetDeviceToMemmoryByGateway(string gatewayId, bool useLocalConnect)
         {
             //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧
             int statu = 0;
             List<CommonDevice> listDevice = new List<CommonDevice>();
-            List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, useLocalConnect);
+            List<CommonDevice> list = this.GetDeviceListFromGateway(gatewayId, ref statu, useLocalConnect);
             if (list == null)
             {
                 return -1;
@@ -223,12 +283,11 @@
             listDevice.AddRange(list);
 
             //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶�
-            string gwID = zbGateway.GwId;
-            List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
+            List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gatewayId);
             //鑾峰彇ota璁惧
             foreach (var ota in this.dicOTADevice.Values)
             {
-                if (ota.CurrentGateWayId == gwID)
+                if (ota.CurrentGateWayId == gatewayId)
                 {
                     listLocalDevices.Add(ota);
                 }
@@ -260,29 +319,18 @@
                     dicExist.Remove(maikey);
                 }
                 //鑾峰彇璁惧鐨勫浐瀹氬睘鎬�
-                HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
+                if (HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device) == true)
+                {
+                    System.Threading.Thread.Sleep(200);
+                }
                 //瀵规湭鍛藉悕鐨勮櫄鎷熻澶囬噸鏂板懡鍚�
                 if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty)
                 {
                     listDriveDevice.Add(device);
                 }
             }
-            if (listDriveDevice.Count > 0)
-            {
-                //濡傛灉铏氭嫙璁惧杩樻病鏈夊悕瀛楃殑璇�
-                HdlThreadLogic.Current.RunThread(() =>
-                {
-                    //濡傛灉涓嶈繖鏍锋斁鍦ㄤ竴涓嚎绋嬮噷,鏈夊彲鑳藉Dictionary浜х敓褰卞搷
-                    foreach (var myDevice in listDriveDevice)
-                    {
-                        //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О
-                        var dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
-                        //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�
-                        dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
-                        this.ReName(myDevice, dName, ShowErrorMode.NO);
-                    }
-                });
-            }
+            //璁剧疆铏氭嫙璁惧鐨勯粯璁ゅ悕瀛�
+            this.SetDriveDeviceDefultName(listDriveDevice);
 
             //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂
             if (statu != 1)
@@ -311,7 +359,7 @@
             if (listDeleteMac.Count > 0)
             {
                 //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
-                this.DeleteRealDeviceFromRoom(listDeleteMac);
+                HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listDeleteMac);
             }
 
             return statu;
@@ -396,6 +444,12 @@
         public void AddVirtualDeviceToMemory(CommonDevice device)
         {
             string mainKeys = this.GetDeviceMainKeys(device);
+            if (device is OTADevice)
+            {
+                this.dicOTADevice[mainKeys] = (OTADevice)device;
+                device.ReSave();
+                return;
+            }
             this.dicAllDevice[mainKeys] = device;
 
             //璁惧鍥炶矾鏀堕泦
@@ -534,6 +588,42 @@
             return true;
         }
 
+        /// <summary>
+        /// 璁剧疆铏氭嫙璁惧鐨勯粯璁ゅ悕瀛�
+        /// </summary>
+        /// <param name="listDriveDevice">铏氭嫙璁惧鍒楄〃</param>
+        private void SetDriveDeviceDefultName(List<CommonDevice> listDriveDevice)
+        {
+            if (listDriveDevice.Count == 0)
+            {
+                return;
+            }
+            //濡傛灉铏氭嫙璁惧杩樻病鏈夊悕瀛楃殑璇�
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //濡傛灉涓嶈繖鏍锋斁鍦ㄤ竴涓嚎绋嬮噷,鏈夊彲鑳藉Dictionary浜х敓褰卞搷
+                foreach (var myDevice in listDriveDevice)
+                {
+                    string dName = string.Empty;
+                    if (this.IsMiniLight(myDevice) == true)
+                    {
+                        //Mini澶滅伅
+                        dName = Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
+                    }
+                    else
+                    {
+                        //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О
+                        dName = this.GetDeviceObjectText(new List<CommonDevice>() { myDevice }, false);
+                        //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�
+                        dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
+                    }
+                    this.ReName(myDevice, dName, ShowErrorMode.NO);
+
+                    System.Threading.Thread.Sleep(100);
+                }
+            });
+        }
+
         ///<summary >
         /// 淇敼璁惧mac鍚嶇О
         /// <para>macName:璁惧鍚嶇О</para>
@@ -543,7 +633,7 @@
             //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
-                return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
+                return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName);
             }
 
             //鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗�
@@ -554,7 +644,7 @@
                 return null;
             }
             //鍔犵紦瀛�
-            Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
+            Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName);
 
             var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RenameDeviceMacNameData>(result.ReceiptData);
             return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData };
@@ -571,7 +661,7 @@
             //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
             if (Common.Config.Instance.Home.IsVirtually == true)
             {
-                return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
+                return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName);
             }
             //鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗�
             var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
@@ -581,7 +671,7 @@
                 return null;
             }
             //鍔犵紦瀛�
-            Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
+            Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName);
 
             var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceRenameResponseData>(result.ReceiptData);
             return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData };
@@ -698,13 +788,9 @@
             {
                 this.DeleteMemmoryDevice(device);
             }
+            //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮�
+            HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listdevice[0]);
 
-            if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
-            {
-                //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮�
-                this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
-                this.SaveRealDeviceRoomId(null, null);
-            }
             return true;
         }
 
@@ -740,6 +826,8 @@
                     this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
                 }
             }
+            //鍒犻櫎妯℃澘鏁版嵁
+            Phone.TemplateData.TemplateCommonLogic.Current.DeleteDevice(device);
 
             //鍒犻櫎璁惧鏂囦欢
             string filePath = device.FilePath;
@@ -825,13 +913,25 @@
         /// <summary>
         /// 鍙戦�佸畾浣嶆寚浠ゅ埌璁惧
         /// </summary>
-        /// <param name="device"></param>
-        public void SetFixedPositionCommand(CommonDevice device)
+        /// <param name="device">璁惧鍥炶矾</param>
+        /// <param name="isRealDevice">鏄惁鏄畾浣嶇湡瀹炶澶�</param>
+        public void SetFixedPositionCommand(CommonDevice device, bool isRealDevice = false)
         {
             //濡傛灉褰撳墠浣忓畢涓嶆槸铏氭嫙浣忓畢
             if (Common.Config.Instance.Home.IsVirtually == false)
             {
-                device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
+                int epoint = device.DeviceEpoint;
+                //濡傛灉鏄畾浣嶇湡瀹炶澶囩殑璇�
+                if (isRealDevice == true)
+                {
+                    var myType = this.GetMyDeviceEnumInfo(new List<CommonDevice> { device });
+                    if (myType.ConcreteType == DeviceConcreteType.DimmableLight_OneLoad)
+                    {
+                        //涓�璺皟鍏夊櫒闇�瑕佸彂8鍥炶矾
+                        epoint = 8;
+                    }
+                }
+                device.IdentifyControl(device.DeviceAddr, epoint, 5);
             }
         }
 
@@ -847,9 +947,9 @@
                 //闂ㄩ攣娌℃湁瀹氫綅鍔熻兘
                 return false;
             }
+            var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
             if (device.Type == DeviceType.IASZone)
             {
-                var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
                 if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_Pir)
                 {
                     //浼犳劅鍣ㄩ櫎浜哖ir閮芥病鏈夊畾浣嶅姛鑳�
@@ -860,6 +960,11 @@
                     //鐞冨瀷绉诲姩浼犳劅鍣ㄨ櫧鐒舵槸鐢垫睜璁惧,浣嗘槸瀹冩湁瀹氫綅鍔熻兘
                     return true;
                 }
+                return false;
+            }
+            //娓╂箍搴︿紶鎰熷櫒娌℃湁瀹氫綅鍔熻兘
+            if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_TemperatureHumidity)
+            {
                 return false;
             }
 
@@ -1073,7 +1178,7 @@
         /// <param name="listDevice"></param>
         /// <returns></returns>
         public List<CommonDevice> GetPanelMatchEpointByMac(List<CommonDevice> listDevice, bool sort = true)
-        { 
+        {
             var list = new List<CommonDevice>();
             foreach (var dev in listDevice)
             {
@@ -1084,7 +1189,7 @@
                 else if (dev.Type == DeviceType.FreshAirHumiditySensor)
                 {
                     list.Add(dev);
-                }  
+                }
             }
             if (sort == false)
             {
@@ -1098,7 +1203,7 @@
                     return 1;
                 }
                 return -1;
-            }); 
+            });
             return list;
         }
 
@@ -1220,7 +1325,7 @@
         #region 鈻� 鑾峰彇璁惧淇℃伅_______________________
 
         /// <summary>
-        /// 璇诲彇鍗曚釜绔偣鍥炶矾璁惧淇℃伅
+        /// 浠庣綉鍏宠鍙栧崟涓鐐瑰洖璺澶囦俊鎭�
         /// </summary>
         /// <param name="device">璁惧瀵硅薄</param>
         /// <returns></returns>
@@ -1236,6 +1341,145 @@
             return info;
         }
 
+        /// <summary>
+        /// 浠庣綉鍏宠鍙栨寚瀹歁ac涓嬬殑璁惧鍒楄〃(杩斿洖鐨勬槸缃戝叧鍥炲鐨勮澶嘕son,璋冪敤ConvertJObjectToDevice鏂规硶杞负Device瀵硅薄)
+        /// </summary>
+        /// <param name="realGateway">鐪熷疄缃戝叧瀵硅薄</param>
+        /// <param name="i_deviceMac">璁惧Mac</param>
+        /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
+        /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+        /// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param>
+        /// <returns></returns>
+        public List<Newtonsoft.Json.Linq.JObject> ReadDeviceListByMacFromGateway(string gatewayId, string i_deviceMac, bool useLocalConnect, ref int statu)
+        {
+            //鏄惁杈炬垚涓柇鐨勬椂鏈�
+            bool canBreak = false;
+            //瓒呮椂鏃堕棿
+            int TimeOut = 0;
+            //璁惧鎬绘暟
+            int deviceCount = -1;
+            //鎺ユ敹鏁�
+            int receiveCount = 0;
+            //璁惧鍒楄〃
+            var listDeviceJson = new List<Newtonsoft.Json.Linq.JObject>();
+
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
+            {
+                if (topic == gatewayId + "/GetStatusRecord_Respon")
+                {
+                    lock (listDeviceJson)
+                    {
+                        //璁惧鎺ユ敹鏁�
+                        receiveCount++;
+                        TimeOut = 0;
+                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                        var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
+                        if (totalNum == 0)
+                        {
+                            //杩欎釜缃戝叧娌℃湁璁惧
+                            canBreak = true;
+                            return;
+                        }
+                        if (deviceCount == -1)
+                        {
+                            //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
+                            deviceCount = totalNum;
+                        }
+                        listDeviceJson.Add(jobject);
+                    }
+
+                    if (receiveCount == deviceCount && deviceCount != -1)
+                    {
+                        //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
+                        canBreak = true;
+                    }
+                }
+            });
+
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", i_deviceMac }, { "Epoint", 255 }, { "Cluster_ID", 0 }, { "Command", 80 } };
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetStatusRecord", jObject.ToString(), useLocalConnect);
+
+            while (canBreak == false && TimeOut <= 150)
+            {
+                System.Threading.Thread.Sleep(20);
+                TimeOut++;
+            }
+            //绉婚櫎鐩戝惉
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
+
+            if (TimeOut > 150)
+            {
+                statu = listDeviceJson.Count == 0 ? -1 : 2;
+            }
+            else
+            {
+                statu = 1;
+            }
+            return listDeviceJson;
+        }
+
+        /// <summary>
+        /// 灏嗚澶囩殑Json杞崲涓鸿澶囧璞�
+        /// </summary>
+        /// <param name="listIObjects">璁惧Json</param>
+        /// <param name="gwId">缃戝叧id</param>
+        /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+        /// <returns></returns>
+        public List<CommonDevice> ConvertJObjectToDevice(List<Newtonsoft.Json.Linq.JObject> listIObjects, string gwId, ref List<CommonDevice> listFucDevice)
+        {
+            //璁惧鍒楄〃
+            var listDevice = new List<CommonDevice>();
+            //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+            var listCheck = new HashSet<string>();
+
+            foreach (var jobject in listIObjects)
+            {
+                var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
+                //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
+                var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, gwId);
+                if (device != null)
+                {
+                    string mainkeys = this.GetDeviceMainKeys(device);
+                    //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+                    if (listCheck.Contains(mainkeys) == false)
+                    {
+                        listDevice.Add(device);
+                        listCheck.Add(mainkeys);
+                        //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
+                        var localDevice = this.GetDevice(mainkeys);
+                        var tempDevice = localDevice == null ? device : localDevice;
+
+                        //濡傛灉杩欎釜璁惧ID鍙樻洿浜嗙殑璇�
+                        bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
+                        if (typeNotEquals == true)
+                        {
+                            //閲嶆柊New杩欎釜瀵硅薄
+                            typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
+                            //閲嶆柊鍐嶆鑾峰彇瀵硅薄
+                            tempDevice = this.GetDevice(mainkeys);
+                        }
+
+                        //鍒锋柊灞炴��
+                        this.SetDeviceInfoToMain(tempDevice, device);
+                        if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
+                        {
+                            //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
+                            listFucDevice.Add(tempDevice);
+                        }
+                        if (typeNotEquals == true)
+                        {
+                            //閲嶆柊鐢熸垚缂撳瓨
+                            tempDevice.ReSave();
+                            HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
+                            //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂�
+                            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
+                        }
+                    }
+                }
+            }
+            return listDevice;
+        }
+
         #endregion
 
         #region 鈻� 璁剧疆璁惧鍔熻兘绫诲瀷___________________
@@ -1248,10 +1492,15 @@
         /// <returns></returns>
         public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType)
         {
-            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
-            var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
-            jObject.Add("Data", data);
-            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", jObject.ToString(), "Device/SetEPDeviceFunctionTypeRespon");
+            //濡傛灉鏄櫄鎷熶綇瀹�
+            if (Common.Config.Instance.Home.IsVirtually == true)
+            {
+                device.DfunctionType = functionType;
+                return true;
+            }
+            //鑾峰彇鍛戒护瀛楃
+            var sendCommond = this.GetDeviceFunctionTypeCommandText(device, functionType);
+            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", sendCommond, "Device/SetEPDeviceFunctionTypeRespon");
             if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
             {
                 return false;
@@ -1263,6 +1512,20 @@
                 return resultData["Result"].ToString() == "0";
             }
             return false;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏇存敼璁惧鍔熻兘绫诲瀷鐨勫懡浠ゆ枃鏈�
+        /// </summary>
+        /// <param name="device"></param>
+        /// <param name="functionType"></param>
+        /// <returns></returns>
+        public string GetDeviceFunctionTypeCommandText(CommonDevice device, DeviceFunctionType functionType)
+        {
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
+            var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
+            jObject.Add("Data", data);
+            return jObject.ToString();
         }
 
         #endregion
@@ -1311,7 +1574,7 @@
             }
 
             if (device.Type == DeviceType.OnOffOutput
-                || device.Type == DeviceType.DimmableLight 
+                || device.Type == DeviceType.DimmableLight
                 || device.Type == DeviceType.ColorDimmableLight
                 || device.Type == DeviceType.ColorTemperatureLight)
             {
@@ -1322,7 +1585,7 @@
             {
                 //绌鸿皟閮藉彨瀹ゅ唴鏈�
                 return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
-            }  
+            }
 
             //鑾峰彇璁惧绫诲瀷
             var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
@@ -1337,7 +1600,7 @@
                 else
                 {
                     var infoContent = this.GetDeviceModelIdNameInfo("A419");
-                    return infoContent != null ? infoContent.A瀹樻柟鍚嶅瓧 : string.Empty;
+                    return infoContent != null ? infoContent.A瀹樻柟鍚嶅瓧 + epointNo : string.Empty;
                 }
             }
             else if (device.Type == DeviceType.FreshAirHumiditySensor)
@@ -1349,15 +1612,26 @@
             {
                 if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir
                     || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment
+                    || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEnvironment
                     || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
                 {
-                    //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾︾幆澧冮潰鏉� 娓╁害浼犳劅鍣�
+                    //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾�/鏂规偊鐜闈㈡澘 娓╁害浼犳劅鍣�
                     return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
                 }
                 else if (deviceInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘)
                 {
                     //闈㈡澘鐨勬俯搴︽帰澶村彨  闈㈡澘鍚嶅瓧+娓╁害
                     return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.uTemperature);
+                }
+                else if (((TemperatureSensor)device).SensorDiv == 1)
+                {
+                    //娓╁害浼犳劅鍣�
+                    return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
+                }
+                else if (((TemperatureSensor)device).SensorDiv == 2)
+                {
+                    //婀垮害浼犳劅鍣�
+                    return Language.StringByID(R.MyInternationalizationString.HumiditySensor);
                 }
             }
             //鍏朵粬鎯呭喌,浣跨敤瀹冪殑榛樿鍚嶇О
@@ -1393,7 +1667,7 @@
         /// <param name="device">璁惧瀵硅薄</param>
         /// <param name="macName">Mac鍚嶅瓧</param>
         /// <returns></returns>
-        private void SetMacName(CommonDevice device, string macName)
+        public void SetMacName(CommonDevice device, string macName)
         {
             device.DeviceName = macName;
         }
@@ -1404,7 +1678,7 @@
         /// <param name="device">璁惧瀵硅薄</param>
         /// <param name="epointName">绔偣鍚嶅瓧</param>
         /// <returns></returns>
-        private void SetEpointName(CommonDevice device, string epointName)
+        public void SetEpointName(CommonDevice device, string epointName)
         {
             device.DeviceEpointName = epointName;
         }
@@ -1620,30 +1894,36 @@
         /// <summary>
         /// 鑾峰彇銆愯澶囧姛鑳界被鍨嬨�戠殑鑿滃崟鍥炬爣
         /// </summary>
-        /// <param name="specificType">鑷畾涔夎澶囩被鍨�</param>
+        /// <param name="deviceEnumInfo">鑷畾涔夎澶囩被鍨�</param>
         /// <param name="unSelectPath">鍥剧墖鍦板潃</param>
         /// <param name="selectPath">鍥剧墖鍦板潃</param>
         /// <returns></returns>
-        public void GetDeviceFunctionTypeMenuIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
+        public void GetDeviceFunctionTypeMenuIcon(DeviceEnumInfo deviceEnumInfo, ref string unSelectPath, ref string selectPath)
         {
             //鏂伴灏忔ā鍧�
-            if (specificType == DeviceConcreteType.Relay_FangyueFreshAirModul)
+            if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Relay_FangyueFreshAirModul)
             {
                 unSelectPath = "Device/FreshAirEpoint.png";
                 selectPath = "Device/FreshAirEpointSelected.png";
                 return;
             }
             //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣�
-            else if (specificType == DeviceConcreteType.Sensor_PMTwoPointFive)
+            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Sensor_PMTwoPointFive)
             {
                 unSelectPath = "Device/AirQualitySensorEpoint.png";
                 selectPath = "Device/AirQualitySensorEpointSelected.png";
                 return;
             }
+            else if (deviceEnumInfo.BeloneType == DeviceBeloneType.A绐楀笜)
+            {
+                unSelectPath = "ZigeeLogic/curtain.png";
+                selectPath = "ZigeeLogic/selectedcurtain.png";
+                return;
+            }
             //涓婇潰闇�瑕佺壒娈婂鐞�
 
             //鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣
-            this.GetDeviceObjectIcon(specificType, ref unSelectPath, ref selectPath);
+            this.GetDeviceObjectIcon(deviceEnumInfo.ConcreteType, ref unSelectPath, ref selectPath);
         }
 
         /// <summary>
@@ -1854,7 +2134,8 @@
                 info.ObjectTypeName = this.dicDeviceModelIdEnum["A418"].A绫诲瀷鍚嶅瓧;//璋冨厜妯″潡
             }
             else if (info.BeloneType == DeviceBeloneType.A浼犳劅鍣�
-                || device.Type == DeviceType.TemperatureSensor)
+                || device.Type == DeviceType.TemperatureSensor
+                || device.Type == DeviceType.FreshAirHumiditySensor)
             {
                 //浼犳劅鍣ㄥ悎骞�
                 info.ConcreteType = DeviceConcreteType.Sensor;
@@ -2160,183 +2441,6 @@
                 info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
                 info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorDoorWindow);
             }
-            else if (iasZone.IasDeviceType == 541)
-            {
-                //鐞冨瀷绉诲姩浼犳劅鍣�
-                info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
-                info.ConcreteText = this.dicDeviceModelIdEnum["MSPIRB-ZB.10"].A瀹樻柟鍚嶅瓧;
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鐗╃悊璁惧鎵�灞炴埧闂確__________________
-
-        /// <summary>
-        /// 鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
-        /// </summary>
-        private void InitRealDeviceRoomId()
-        {
-            this.dicDeviceRoomId = new Dictionary<string, string>();
-            string fullName = DirNameResourse.DeviceRoomIdFile;
-            var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
-            if (strData != null)
-            {
-                this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
-            }
-        }
-
-        /// <summary>
-        /// 鑾峰彇鍏ㄩ儴鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
-        /// </summary>
-        /// <returns></returns>
-        public Dictionary<string, string> GetAllRealDeviceRoomData()
-        {
-            return this.dicDeviceRoomId;
-        }
-
-        /// <summary>
-        /// 淇濆瓨鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
-        /// </summary>
-        /// <param name="listDevice">闇�瑕佷繚瀛樼殑璁惧瀵硅薄</param>
-        /// <param name="roomId">闇�瑕佷繚瀛樼殑鍝釜璁惧鐨勬埧闂碔D</param>
-        /// <param name="saveRoadDevice">濡傛灉鍙湁涓�涓洖璺�,鏄惁鎶婂洖璺殑鎴块棿涓�璧蜂慨鏀�</param>
-        public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
-        {
-            if (listDevice == null)
-            {
-                return;
-            }
-            //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜�
-            if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
-            {
-                if (listDevice[0] is OTADevice)
-                {
-                    //鍗曠函鍙槸Ota璁惧鍒欎笉澶勭悊
-                    return;
-                }
-                HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
-            }
-            bool save = false;
-            if (roomId == string.Empty)
-            {
-                //閫夋嫨鐨勬槸鏈垎閰�
-                this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
-                save = true;
-            }
-            else
-            {
-                if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false)
-                {
-                    this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
-                    save = true;
-                }
-                else
-                {
-                    //2020.05.18杩藉姞:濡傛灉璁板綍鐨勬埧闂碔D鏄笉瀛樺湪鐨勮瘽,鍒欓噸鏂拌鐩�
-                    var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
-                    if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
-                    {
-                        this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
-                        save = true;
-                    }
-                }
-            }
-
-            if (save == true)
-            {
-                //淇濆瓨璁板綍
-                HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
-
-                //娣诲姞鑷姩澶囦唤
-                HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
-            }
-        }
-
-        /// <summary>
-        /// 鑾峰彇鐪熷疄鐗╃悊璁惧鐨勬埧闂村悕瀛�
-        /// </summary>
-        /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param>
-        /// <returns></returns>
-        public string GeteRealDeviceRoomName(CommonDevice device)
-        {
-            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
-            {
-                //鏈垎閰嶅尯鍩�
-                return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
-            }
-            var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
-            return HdlRoomLogic.Current.GetRoomName(room);
-        }
-
-        /// <summary>
-        /// 鑾峰彇鐪熷疄鐗╃悊璁惧灞炰簬鍝釜鎴块棿
-        /// </summary>
-        /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param>
-        /// <returns></returns>
-        public Room GeteRealDeviceRoom(CommonDevice device)
-        {
-            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
-            {
-                return null;
-            }
-            return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
-        }
-
-        /// <summary>
-        /// 灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
-        /// </summary>
-        /// <param name="device">闅忎究涓�涓洖璺�</param>
-        public void DeleteRealDeviceFromRoom(CommonDevice device)
-        {
-            //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
-            this.DeleteRealDeviceFromRoom(new List<string>() { device.DeviceAddr });
-        }
-
-        /// <summary>
-        /// 灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
-        /// </summary>
-        /// <param name="listMac">璁惧Mac鍦板潃</param>
-        public void DeleteRealDeviceFromRoom(List<string> listMac)
-        {
-            bool save = false;
-            foreach (var deviceMacAddr in listMac)
-            {
-                if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
-                {
-                    this.dicDeviceRoomId.Remove(deviceMacAddr);
-                    save = true;
-                }
-            }
-            if (save == false)
-            {
-                //娌℃湁鏀瑰彉,涓嶉渶瑕佷繚瀛�
-                return;
-            }
-            //淇濆瓨璁板綍
-            HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
-
-            //娣诲姞鑷姩澶囦唤
-            HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
-        }
-
-        /// <summary>
-        /// 鏍规嵁鎴块棿ID,绉婚櫎鎸囧畾鐨勭湡瀹炵墿鐞嗚澶囩殑鎵�灞炴埧闂磋褰�
-        /// </summary>
-        /// <param name="i_RoomId"></param>
-        public void DeleteRealDeviceByRoomId(string i_RoomId)
-        {
-            var listDeleteKey = new List<string>();
-            foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
-            {
-                if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
-                    && listDeleteKey.Contains(deviceAddr) == false)
-                {
-                    listDeleteKey.Add(deviceAddr);
-                }
-            }
-            //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄�
-            this.DeleteRealDeviceFromRoom(listDeleteKey);
         }
 
         #endregion
@@ -2410,7 +2514,7 @@
 
             //鍏朵粬鐨勭湅鐫�鍔炲憲,閮芥槸鎺掑湪鍚庨潰鐨�,閮藉綊涓鸿繖涓睘鎬�
             list.Add(DeviceBeloneType.A鏈煡璁惧);
-            
+
             return list;
         }
 
@@ -2478,6 +2582,11 @@
             else if (i_device.Type == DeviceType.FreshAirHumiditySensor)
             {
                 //鏂伴鐨勬箍搴︿紶鎰熷櫒涓嶆樉绀�
+                return false;
+            }
+            if (((int)i_device.Type).ToString() == i_device.Type.ToString())
+            {
+                //姝よ澶噄d鍦―eviceType閲岄潰杩樻病鏈夋敞鍐�,鍒欎笉鑳芥樉绀哄嚭鏉�
                 return false;
             }
 
@@ -2601,7 +2710,7 @@
         {
             HdlThreadLogic.Current.RunMain(() =>
             {
-                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+                var contr = new ShowMsgControl(Phone.ShowMsgType.Error, msg);
                 contr.Show();
             });
         }
@@ -2614,7 +2723,7 @@
         {
             HdlThreadLogic.Current.RunMain(() =>
             {
-                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+                var contr = new ShowMsgControl(Phone.ShowMsgType.Tip, msg);
                 contr.Show();
             });
         }
@@ -2626,165 +2735,157 @@
         #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________
 
         /// <summary>
-        /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�)</para>
+        /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�),涓�娆℃�у叏閮ㄨ幏鍙�</para>
         /// <para>statu鐘舵�� -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</para>
         /// </summary>
-        /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+        /// <param name="gatewayId">缃戝叧id</param>
         /// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param>
         /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
         /// <param name="mode">鏄惁鏄剧ず閿欒</param>
         /// <returns></returns>
-        public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
+        public List<CommonDevice> GetDeviceListFromGateway(string gatewayId, ref int statu, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
         {
-            //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭�
-            string nowFormId = UserCenterResourse.NowActionFormID;
-
-            ZbGateway realWay = null;
-            if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == false)
-            {
-                if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
-                {
-                    //閿欒:缃戝叧瀵硅薄涓㈠け
-                    string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
-                    this.ShowTipMsg(msg);
-                }
-                statu = -1;
-                return null;
-            }
             //闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾
             var listFucDevice = new List<CommonDevice>();
 
             //鏄惁杈炬垚涓柇鐨勬椂鏈�
             bool canBreak = false;
-            //缃戝叧ID
-            string gatewayID = zbGateway.GwId;
             //瓒呮椂鏃堕棿
             int TimeOut = 0;
+            //褰撳墠璁惧鎺ユ敹鏁�
+            int nowReceiveCount = 0;
             //璁惧鎬绘暟
             int deviceCount = -1;
-            //鎺ユ敹鏁�
-            int receiveCount = 0;
             //璁惧鍒楄〃
             var listDevice = new List<CommonDevice>();
             //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
             var listCheck = new HashSet<string>();
-            Action<string, string> getDeviceAction = (topic, message) =>
+            ///Mac鐨勭鐐规�绘暟
+            var dicMacPointCount = new Dictionary<string, int>();
+
+            HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) =>
             {
-                if (topic == gatewayID + "/DeviceInfoRespon")
+                if (topic == gatewayId + "/DeviceInfoRespon")
                 {
-                    try
+                    lock (listDevice)
                     {
-                        lock (listDevice)
+                        TimeOut = 0;
+                        var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
+                        var totalNum = Convert.ToInt32(jobject["Data"]["TotalNum"].ToString());
+                        if (totalNum == 0)
                         {
-                            //璁惧鎺ユ敹鏁�
-                            receiveCount++;
+                            //杩欎釜缃戝叧娌℃湁璁惧
+                            canBreak = true;
+                            return;
+                        }
+                        if (deviceCount == -1)
+                        {
+                            //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
+                            deviceCount = totalNum;
+                        }
+                        nowReceiveCount++;
 
-                            TimeOut = 0;
-                            var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-                            var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
-                            if (totalNum == 0)
-                            {
-                                //杩欎釜缃戝叧娌℃湁璁惧
-                                canBreak = true;
-                                return;
-                            }
-                            if (deviceCount == -1)
-                            {
-                                //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧
-                                deviceCount = totalNum;
-                            }
+                        //璁惧鍥炶矾鏁版敹闆�
+                        string deviceMac = jobject.Value<string>("DeviceAddr");
+                        if (dicMacPointCount.ContainsKey(deviceMac) == false)
+                        {
+                            dicMacPointCount[deviceMac] = 0;
+                        }
+                        dicMacPointCount[deviceMac]++;
 
-                            var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
-                            //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
-                            var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
-                            if (device != null)
+                        var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
+                        //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
+                        var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, gatewayId);
+                        if (device != null)
+                        {
+                            string mainkeys = this.GetDeviceMainKeys(device);
+                            //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
+                            if (listCheck.Contains(mainkeys) == false)
                             {
-                                string mainkeys = this.GetDeviceMainKeys(device);
-                                //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾
-                                if (listCheck.Contains(mainkeys) == false)
+                                listDevice.Add(device);
+                                listCheck.Add(mainkeys);
+                                //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
+                                var localDevice = this.GetDevice(mainkeys);
+                                var tempDevice = localDevice == null ? device : localDevice;
+
+                                //濡傛灉杩欎釜璁惧ID鍙樻洿浜嗙殑璇�
+                                bool typeNotEquals = localDevice != null && deviceID != localDevice.Type;
+                                if (typeNotEquals == true)
                                 {
-                                    listDevice.Add(device);
-                                    listCheck.Add(mainkeys);
-                                    //鍒锋柊涓�涓嬫湰鍦扮紦瀛�
-                                    var localDevice = this.GetDevice(mainkeys);
-                                    if (localDevice != null)
-                                    {
-                                        //鍒锋柊灞炴��
-                                        this.SetDeviceInfoToMain(localDevice, device);
-                                        if (this.RefreshDeviceFunctionType(localDevice, device, false) == true)
-                                        {
-                                            //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
-                                            listFucDevice.Add(localDevice);
-                                        }
-                                    }
+                                    //閲嶆柊New杩欎釜瀵硅薄
+                                    typeNotEquals = this.ReNewDeviceOnTypeIsChanged(localDevice, deviceID);
+                                    //閲嶆柊鍐嶆鑾峰彇瀵硅薄
+                                    tempDevice = this.GetDevice(mainkeys);
+                                }
+
+                                //鍒锋柊灞炴��
+                                this.SetDeviceInfoToMain(tempDevice, device);
+                                if (this.RefreshDeviceFunctionType(tempDevice, device, false) == true)
+                                {
+                                    //闇�瑕佸彂閫佸姛鑳界被鍨嬬粰缃戝叧
+                                    listFucDevice.Add(tempDevice);
+                                }
+                                if (typeNotEquals == true)
+                                {
+                                    //閲嶆柊鐢熸垚缂撳瓨
+                                    tempDevice.ReSave();
+                                    HdlAutoBackupLogic.AddOrEditorFile(tempDevice.FilePath);
+                                    //鍏ㄩ儴涓婚〉鑿滃崟闇�瑕佸埛鏂�
+                                    Phone.UserView.UserPage.Instance.RefreshAllForm = true;
                                 }
                             }
                         }
                     }
-                    //Log鍑哄姏
-                    catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
 
-                    if (receiveCount == deviceCount && deviceCount != -1)
+                    if (nowReceiveCount >= deviceCount)
                     {
                         //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚
                         canBreak = true;
                     }
                 }
-                else if (topic == gatewayID + "/DeviceInfoResponEnd")
-                {
-                }
-            };
+            });
+            //鍙戦�佸懡浠�
+            var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
+            HdlGatewayLogic.Current.SendJobjectData(gatewayId, "GetDeviceInfo", jObject.ToString(), useLocalConnect);
 
-            realWay.Actions += getDeviceAction;
-            try
-            {
-                var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
-                if (useLocalConnect == false)
-                {
-                    realWay.Send("GetDeviceInfo", jObject.ToString());
-                }
-                else
-                {
-                    //寮哄埗浣跨敤鏈湴杩炴帴
-                    realWay.SendLocation("GetDeviceInfo", Encoding.UTF8.GetBytes(jObject.ToString()));
-                }
-            }
-            catch { canBreak = true; }
-
-            while (canBreak == false && TimeOut < 60)
+            while (canBreak == false && TimeOut <= 30)
             {
                 System.Threading.Thread.Sleep(100);
                 TimeOut++;
             }
+            //绉婚櫎缃戝叧鐩戝惉浜嬩欢
+            HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent();
 
-            realWay.Actions -= getDeviceAction;
-            getDeviceAction = null;
-
-            if (TimeOut >= 60)
+            if (TimeOut > 30)
             {
-                if (listDevice.Count == 0)
+                if (listDevice.Count > 0)
                 {
-                    if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
-                    {
-                        //鑾峰彇璁惧鍒楄〃澶辫触
-                        //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇�
-                        string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
-                        msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
-                        msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false);
-                        this.ShowTipMsg(msg);
-                    }
-                    statu = -1;
-                    return null;
-                }
-                else
-                {
-                    if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
+                    //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯,鍒欓噰鐢ㄦ寜搴忓彿鑾峰彇璁惧
+                    statu = this.GetDeviceListFromGatewayByMac(gatewayId, ref listDevice, ref listFucDevice, dicMacPointCount, useLocalConnect);
+                    if (statu == 2)
                     {
                         //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯
                         string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
                         this.ShowTipMsg(msg);
                     }
-                    statu = 2;
+                }
+                else
+                {
+                    if (mode == ShowErrorMode.YES)
+                    {
+                        //鑾峰彇璁惧鍒楄〃澶辫触
+                        //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇�
+                        string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
+                        var localGw = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
+                        if (localGw != null)
+                        {
+                            msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(localGw).ToString() + "]";
+                        }
+                        msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false);
+                        this.ShowTipMsg(msg);
+                    }
+                    statu = -1;
+                    return null;
                 }
             }
             else
@@ -2807,6 +2908,129 @@
             return listDevice;
         }
 
+        /// <summary>
+        /// 鏍规嵁搴忓彿鑾峰彇璁惧鍒楄〃淇℃伅(鍙湁鍦ㄨ澶囩己鎹熺殑鏃跺�欐墠璋冪敤杩欎釜鍑芥暟) 1:姝e父 2:璁惧缂烘崯
+        /// </summary>
+        /// <param name="gatewayId">缃戝叧id</param>
+        /// <param name="listDevice">瀛樺偍鐨勮澶囧璞¢泦鍚�</param>
+        /// <param name="listFucDevice">闇�瑕佸彉鏇村姛鑳界被鍨嬬殑鍥炶矾</param>
+        /// <param name="dicNowPointCount">褰撳墠宸茬粡鑾峰彇鐨凪ac鐨勭鐐规�绘暟</param>
+        /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param>
+        /// <returns></returns>
+        public int GetDeviceListFromGatewayByMac(string gatewayId, ref List<CommonDevice> listDevice, ref List<CommonDevice> listFucDevice, Dictionary<string, int> dicNowPointCount, bool useLocalConnect)
+        {
+            //棣栧厛鍏堣幏鍙栬澶囩殑mac鍒楄〃
+            var jObject33 = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 87 } };
+            var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(gatewayId, "GetStatusRecord", jObject33.ToString(), "DeviceMACDeviceListRespon", 3, useLocalConnect);
+            if (result.ErrorMsgDiv == -1 || result.ErrorMsgDiv == 0)
+            {
+                //濡傛灉缃戝叧娌℃湁瀵硅繖涓富棰樺仛鍑哄洖搴旂殑璇�,鍒欒鏄庡畠鏄竴涓棫缃戝叧
+                return 2;
+            }
+            var resultMac = Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiptMacResult>(result.ReceiptData);
+
+            //璁惧鍒楄〃
+            var listDeviceJson = new List<Newtonsoft.Json.Linq.JObject>();
+
+            int statu = 0;
+            foreach (var macInfo in resultMac.MACDeviceList)
+            {
+                if (dicNowPointCount.ContainsKey(macInfo.MacAddr) == true
+                    && dicNowPointCount[macInfo.MacAddr] == macInfo.EPTotalNum)
+                {
+                    //濡傛灉杩欎釜mac鐨勭鐐规暟涓�鑷�,鍒欒鏄庡凡缁忔帴鏀堕綈浜�,涓嶉渶瑕佸啀娆℃帴鏀�
+                    continue;
+                }
+                //浠庣綉鍏宠鍙栨寚瀹歁ac涓嬬殑璁惧鍒楄〃
+                var jsonData = this.ReadDeviceListByMacFromGateway(gatewayId, macInfo.MacAddr, useLocalConnect, ref statu);
+                foreach (var myData in jsonData)
+                {
+                    listDeviceJson.Add(myData);
+                }
+                if (statu != 1)
+                {
+                    //娌℃湁姝e父瀹屾垚,鍒欎腑鏂�
+                    break;
+                }
+            }
+            //杞寲涓鸿澶囧垪琛�
+            var listTempDevice = this.ConvertJObjectToDevice(listDeviceJson, gatewayId, ref listFucDevice);
+            for (int i = 0; i < listTempDevice.Count; i++)
+            {
+                listDevice.Add(listTempDevice[i]);
+            }
+            return statu == 1 ? 1 : 2;
+        }
+
+        /// <summary>
+        /// 鍦ㄨ澶嘥ype鍙樻洿鏃�,閲嶆柊New杩欎釜璁惧瀵硅薄(浠呴檺鍦ㄥ埛鏂拌澶囧垪琛ㄤ娇鐢�,骞朵笖鏈湴闇�瑕佸瓨鍦�)
+        /// </summary>
+        /// <param name="oldLocalDevice">鍘熸潵鐨勬湰鍦板璞�</param>
+        /// <param name="newDeviceType">鏂扮殑璁惧Type</param>
+        private bool ReNewDeviceOnTypeIsChanged(CommonDevice oldLocalDevice, DeviceType newDeviceType)
+        {
+            //鍏堣幏鍙栨湰鍦拌繖涓棫璁惧瀵硅薄鐨刯son
+            string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, oldLocalDevice.FilePath);
+            var deviceData = HdlFileLogic.Current.ReadFileTextContent(oldFile);
+            if (deviceData == null)
+            {
+                //搴旇涓嶄細
+                return false;
+            }
+            //鏍规嵁鏂癟ype閲嶆柊New瀵硅薄
+            var newDevice = CommonDevice.CommonDeviceByByteString((int)newDeviceType, deviceData);
+            if (newDevice == null)
+            {
+                //濂藉儚鏈夌偣鍙兘
+                return false;
+            }
+            //鍒犻櫎鏈湴鏂囦欢
+            HdlFileLogic.Current.DeleteFile(oldFile);
+            HdlAutoBackupLogic.DeleteFile(oldLocalDevice.FilePath);
+
+            //閲嶆柊鐢熸垚鏂囦欢
+            if (newDevice.IsCustomizeImage == false)
+            {
+                newDevice.IconPath = string.Empty;
+            }
+            string mainkey = this.GetDeviceMainKeys(newDevice);
+            lock (dicAllDevice)
+            {
+                this.dicAllDevice[mainkey] = newDevice;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鎺ユ敹璁惧Mac鍒楄〃鐨勭被
+        /// </summary>
+        private class ReceiptMacResult
+        {
+            /// <summary>
+            /// mac鎬绘暟
+            /// </summary>
+            public int MACDeviceTotalNum = 0;
+            /// <summary>
+            /// 璁惧mac鍒楄〃
+            /// </summary>
+            public List<MacResult> MACDeviceList = new List<MacResult>();
+        }
+
+        /// <summary>
+        /// 璁惧Mac鐨勫唴瀹�
+        /// </summary>
+        private class MacResult
+        {
+            /// <summary>
+            /// 璁惧Mac
+            /// </summary>
+            public string MacAddr = string.Empty;
+            /// <summary>
+            /// mac绔偣鐨勬�绘暟
+            /// </summary>
+            public int EPTotalNum = 0;
+        }
+
         #endregion
 
         #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________
@@ -2816,14 +3040,12 @@
         /// </summary>
         /// <param name="deviceType">璁惧绫诲瀷</param>
         /// <param name="jobject">涓婚Data</param>
-        /// <param name="zbGateway">缃戝叧瀵硅薄</param>
+        /// <param name="gwid">缃戝叧id</param>
         /// <returns></returns>
-        private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway)
+        private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, string gwid)
         {
-            string gwId = zbGateway.GwId;
-
             //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
-            CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType);
+            CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType, jobject.Value<int>("Epoint"));
             if (device == null)
             {
                 return null;
@@ -2838,7 +3060,7 @@
 
             //璁剧疆璁惧涓婚敭绫�
             this.SetNewDeviceMainKeys(device, jobject);
-            device.CurrentGateWayId = gwId;
+            device.CurrentGateWayId = gwid;
 
             return device;
         }
@@ -2850,14 +3072,8 @@
         /// <param name="device">璁剧疆婧愯澶囧璞�</param>
         public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device)
         {
-            if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false)
-            {
-                mainDevice.DeviceName = device.DeviceInfo.MacName;
-            }
-            if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false)
-            {
-                mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
-            }
+            mainDevice.DeviceName = device.DeviceInfo.MacName;
+            mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
             mainDevice.CurrentGateWayId = device.CurrentGateWayId;
             mainDevice.ZigbeeType = device.DeviceInfo.ZigbeeType;
             mainDevice.IsOnline = device.DeviceInfo.IsOnline;
@@ -2865,6 +3081,7 @@
             mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
             mainDevice.Profile = device.DeviceInfo.Profile;
             mainDevice.Type = device.Type;
+            mainDevice.DeviceID = (int)device.Type;
 
             //鍥轰欢鐗堟湰
             mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
@@ -2890,6 +3107,8 @@
             mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
             mainDevice.OutClusterList.Clear();
             mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
+            mainDevice.AttributeStatus.Clear();
+            mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
 
             //濡傛灉鏄俯搴︿紶鎰熷櫒
             if (mainDevice.Type == DeviceType.TemperatureSensor)
@@ -2913,33 +3132,16 @@
         /// 鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞�
         /// </summary>
         /// <param name="deviceType">璁惧Type</param>
+        /// <param name="DeviceEpoint">璁惧绔偣(娌℃湁浠�涔堢壒娈婇渶姹傜殑璇�,濉�0鍗冲彲)</param>
         /// <returns></returns>
-        public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
+        public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, int DeviceEpoint)
         {
-            CommonDevice device = null;
-
             //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�
-            if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
-            else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
-            else if (deviceType == DeviceType.ColorDimmerSwitch) { device = new ColorDimmerSwitch(); }
-            else if (deviceType == DeviceType.LevelControlSwitch) { device = new LevelControlSwitch(); }
-            else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); }
-            else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); }
-            else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); }
-            else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); }
-            else if (deviceType == DeviceType.WindowCoveringController) { device = new WindowCoveringController(); }
-            else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
-            else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
-            else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
-            else if (deviceType == DeviceType.FreshAir) { device = new FreshAir(); }
-            else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); }
-            else if (deviceType == DeviceType.TemperatureSensor) { device = new TemperatureSensor(); }
-            else if (deviceType == DeviceType.PMSensor) { device = new PMSensor(); }
-            else if (deviceType == DeviceType.FreshAirHumiditySensor) { device = new HumiditySensor(); }
-            else if (deviceType == DeviceType.ColorTemperatureLight) { device = new ColorTemperatureLight(); }
-            else if (deviceType == DeviceType.Buzzer) { device = new Buzzer(); }
-            else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
-            else { return null; }
+            var device = CommonDevice.CommonDeviceByByteString((int)deviceType, "{\"DeviceID\":" + (int)deviceType + ",\"DeviceEpoint\":" + DeviceEpoint + "}");
+            if (device == null)
+            {
+                return null;
+            }
 
             device.DeviceEpointName = string.Empty;
             device.DeviceName = string.Empty;
@@ -2980,7 +3182,7 @@
                     mainDevice.IconPath = "Device/Light.png";
                 }
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
-                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
                 {
                     //璋冨厜鍣ㄥ浐瀹氱伅鍏�
                     if (sendFucType == true)
@@ -2998,7 +3200,7 @@
                     mainDevice.IconPath = "Device/ColorLightTemperature.png";
                 }
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
-                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
                 {
                     //鑹叉俯鐏浐瀹氱伅鍏�
                     if (sendFucType == true)
@@ -3017,7 +3219,7 @@
                 if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�)
                 {
                     mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
-                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                    if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
                     {
                         //缁х數鍣ㄩ粯璁や负鐏厜
                         if (sendFucType == true)
@@ -3037,7 +3239,7 @@
                 if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�)
                 {
                     mainDevice.DfunctionType = DeviceFunctionType.A寮�鍏�;
-                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A寮�鍏�)
+                    if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A寮�鍏�)
                     {
                         //绌烘皵寮�鍏抽粯璁や负寮�鍏�
                         if (sendFucType == true)
@@ -3056,7 +3258,7 @@
                     mainDevice.IconPath = "Device/ColorLight.png";
                 }
                 mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
-                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
+                if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜)
                 {
                     //褰╃伅榛樿涓哄紑鍏�
                     if (sendFucType == true)
@@ -3142,7 +3344,7 @@
                 content.ConcreteTypeValue = Convert.ToInt32(strArry2[0].Trim());
                 content.A瀹樻柟鍚嶅瓧 = strArry2[1].Trim();
                 content.A澶囨敞鍚嶅瓧 = strArry2[2].Trim();
-                content.BeloneTypeValue= Convert.ToInt32(strArry2[3].Trim());
+                content.BeloneTypeValue = Convert.ToInt32(strArry2[3].Trim());
                 content.A鎵�灞炲悕瀛� = strArry2[4].Trim();
                 content.A绫诲瀷鍚嶅瓧 = strArry2[5].Trim();
                 this.dicDeviceModelIdEnum[strArry1[0].Trim()] = content;
@@ -3167,6 +3369,7 @@
             this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//绠�绾�2鎸夐敭闈㈡澘 娌跨敤 2鎸夐敭鐨勫浘鏍�
             this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one鐨勯棬閿佸浘鐗� 娌跨敤 H06C鐨勫浘鏍�
             this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//鏂规偊鏂伴灏忔ā鍧楀浘鐗� 娌跨敤 3璺户鐢靛櫒鐨勫浘鏍�
+            this.dicPictrueShard["ButtonPanel_FourButtonScene"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭鍦烘櫙闈㈡澘 娌跨敤 4鎸夐敭闈㈡澘鐨勫浘鏍�
         }
 
         /// <summary>
@@ -3371,6 +3574,10 @@
         /// PM2.5绌烘皵璐ㄩ噺浼犳劅鍣�
         /// </summary>
         Sensor_PMTwoPointFive = 1307,
+        /// <summary>
+        /// 娓╂箍搴︿紶鎰熷櫒(杩欎釜鍗曡瘝鎷奸敊浜�,浣嗘槸閿欎簡灏遍敊浜嗗憲,灏辫繖鏍蜂簡)
+        /// </summary>
+        Sensor_TemperatureHumidity = 1308,
 
         /// <summary>
         /// 杩愬姩浼犳劅鍣�
@@ -3381,11 +3588,7 @@
         /// </summary>
         Sensor_Keyfob = -1307,
         /// <summary>
-        /// 娓╂箍搴︿紶鎰熷櫒
-        /// </summary>
-        Sensor_TemperatureHumidity = -1308,
-        /// <summary>
-        /// 娓╁害浼犳劅鍣�
+        /// 娓╁害浼犳劅鍣�(杩欎釜鍗曡瘝鎷奸敊浜�,浣嗘槸閿欎簡灏遍敊浜嗗憲,灏辫繖鏍蜂簡)
         /// </summary>
         Sensor_Temperature = -1309,
         /// <summary>
@@ -3406,7 +3609,19 @@
         /// 鏂规偊鏂伴灏忔ā鍧� 闀滃儚id锛�2310
         /// </summary>
         Relay_FangyueFreshAirModul = 2310,
-		
+        /// <summary>
+        /// 鍥芥爣3璺�10A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2301
+        /// </summary>
+        Relay_NationalThreeLoadTenA = 2301,
+        /// <summary>
+        /// 娆ф爣2璺�5A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2315
+        /// </summary>
+        Relay_EuropeanTwoLoadFiveA = 2315,
+        /// <summary>
+        /// 7璺共鎺ョ偣杈撳叆杈撳嚭妯″潡 闀滃儚id锛�2320
+        /// </summary>
+        Relay_SevenLoadInOutPutDryContact = 2320,
+
         //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
         /// <summary>
         /// 璋冨厜鍣�

--
Gitblit v1.8.0