From dee21bf452a8979d0515d13e534fbb69ed9715dd Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 01 九月 2020 15:33:13 +0800
Subject: [PATCH] 上传一个版本

---
 ZigbeeApp/Shared/Common/Device.cs |  107 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 100 insertions(+), 7 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 43449e8..8031876 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -260,7 +260,10 @@
                     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)
                 {
@@ -1275,10 +1278,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;
@@ -1290,6 +1298,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
@@ -1376,9 +1398,10 @@
             {
                 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鎸夐敭闈㈡澘)
@@ -2741,12 +2764,30 @@
                                     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;
                                     }
                                 }
                             }
@@ -2838,6 +2879,45 @@
             return listDevice;
         }
 
+        /// <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(newDeviceType.ToString(), 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;
+        }
+
         #endregion
 
         #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________
@@ -2890,6 +2970,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;
@@ -3434,7 +3515,19 @@
         /// 鏂规偊鏂伴灏忔ā鍧� 闀滃儚id锛�2310
         /// </summary>
         Relay_FangyueFreshAirModul = 2310,
-		
+        /// <summary>
+        /// 鍥芥爣3璺�10A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2311(涓存椂)
+        /// </summary>
+        Relay_NationalThreeLoadTenA = 2311,
+        /// <summary>
+        /// 娆ф爣2璺�5A缁х數鍣ㄥ皬妯″潡 闀滃儚id锛�2312(涓存椂)
+        /// </summary>
+        Relay_EuropeanTwoLoadFiveA = 2312,
+        /// <summary>
+        /// 娆ф爣14璺共鎺ョ偣灏忔ā鍧� 闀滃儚id锛�2313(涓存椂)
+        /// </summary>
+        Relay_EuropeanFourteenLoadDryContact = 2313,
+
         //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄=========
         /// <summary>
         /// 璋冨厜鍣�

--
Gitblit v1.8.0