From 10b78a1626106f18a6b2f68bd2b8cafd2a99683c Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 12 八月 2020 11:31:59 +0800
Subject: [PATCH] 2020-08-12 4.喜爱页面,增加房间场景添加支持。 5.Alexa,添加设备页面增加修改备注功能,点击OK后,增加设备备注名字不匹配然后自动更新操作。

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs |   99 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 90 insertions(+), 9 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
index 13c4fea..0ea98e1 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaDeviceListPage.cs
@@ -119,21 +119,66 @@
                                 //    DeviceName = common.Name, DeviceID = common.DeviceID, Id = 1, DeviceType = common.Type.ToString (), LoopID = common.LoopID,
                                 //    MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.RegionID, SubnetID = common.SubnetID
                                 //});
+                              
+
                                 if (common != null) {
-                                    var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == common.Type.ToString ());
+                                    var commonType = common.Type.ToString ();
+                                    if (commonType == "CurtainModel") {
+                                        commonType = "CurtainModule";
+                                    } else if (commonType == "LightEnergySwitch" || commonType == "LightSwitchSocket" || commonType == "LightEnergySocket") {
+                                        commonType = "LightSwitch";
+                                    } else if (commonType == "ACInfrared") {
+                                        commonType = "HVAC";
+                                    }
+                                    var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == commonType);
                                     if (oldDevice == null) {
                                         var isSuccess = AddDevice (common);
                                         if (!isSuccess) {
                                             //璺冲嚭寰幆
                                             break;
                                         }
+                                    } else {
+                                        //2020-07-21 濡傛灉宸茬粡瀛樺湪 鍖归厤璁惧澶囨敞鏄惁闇�瑕佹洿鏂�
+                                        if (oldDevice.DeviceName != common.Name) {
+                                            //Utlis.WriteLine ("鍚嶅瓧涓嶅尮閰嶏紝鎻愪氦鏇存柊锛�" + common.Name);
+                                            var oldName = oldDevice.DeviceName;
+                                            oldDevice.DeviceName = common.Name;
+                                            var isSuccess = UpdateDevice (oldDevice);
+                                            if (!isSuccess) {
+                                                //杩樺師
+                                                oldDevice.DeviceName = oldName;
+                                                //Utlis.WriteLine ("鏇存柊澶辫触锛侊紒锛侊紒");
+                                            } else {
+                                                //Utlis.WriteLine ("鏇存柊鎴愬姛锛�");
+                                            }
+                                        } else {
+                                            //Utlis.WriteLine ("鍚嶅瓧涓�鏍蜂笉鐢ㄦ洿鏂帮細"+ common.Name);
+                                        }
+
                                     }
                                 }
                             }
-                            foreach (var oldDevice in alexaDeviceLista) {
-                                var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ());
 
-                                if (!roomDeviceFilePathList.Contains (oldDevicePath)) {
+                            var roomDeviceFilePathListNew = new List<string> ();
+                            foreach (var path in roomDeviceFilePathList) {
+                                var deviceFilePath = path;
+                                if (deviceFilePath.Contains ("LightEnergySocket")) {
+                                    deviceFilePath = deviceFilePath.Replace ("LightEnergySocket", "LightSwitch");
+                                } else if (deviceFilePath.Contains ("LightEnergySwitch")) {
+                                    deviceFilePath = deviceFilePath.Replace ("LightEnergySwitch", "LightSwitch");
+                                } else if (deviceFilePath.Contains ("LightSwitchSocket")) {
+                                    deviceFilePath = deviceFilePath.Replace ("LightSwitchSocket", "LightSwitch");
+                                } else if (deviceFilePath.Contains ("ACInfrared")) {
+                                    deviceFilePath = deviceFilePath.Replace ("ACInfrared", "HVAC");
+                                } else if (deviceFilePath.Contains ("CurtainModel")) {
+                                    deviceFilePath = deviceFilePath.Replace ("CurtainModel", "CurtainModule");
+                                }
+                                roomDeviceFilePathListNew.Add (deviceFilePath);
+                            }
+
+                           foreach (var oldDevice in alexaDeviceLista) {
+                                var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ());
+                                if (!roomDeviceFilePathListNew.Contains (oldDevicePath)) {
                                     DelDevice (oldDevice.Id);
                                     Utlis.WriteLine ("delDevice " + oldDevice.DeviceName);
                                 }
@@ -397,8 +442,8 @@
                         var tempRoom = new Room ();
                         foreach (var device in alexaDeviceLista) {//鐗规畩澶勭悊鏈嶅姟鍣ㄤ笌鏈湴璁惧绫诲瀷涓嶄竴鏍风殑璁惧
                             var deviceTypeSaveString = device.DeviceType;
-                            if (deviceTypeSaveString == "CurtainModule") {
-                                deviceTypeSaveString = "CurtainModel";
+                            if (deviceTypeSaveString == "CurtainModel") {
+                                deviceTypeSaveString = "CurtainModule";
                             } else if (deviceTypeSaveString == "LightEnergySwitch") {
                                 deviceTypeSaveString = "LightSwitch";
                             } else if (deviceTypeSaveString == "LightEnergySocket") {
@@ -490,7 +535,7 @@
         /// 涓婁紶璁惧 閿欒鎻愮ず
         /// </summary>
         /// <param name="stateCodeStr"></param>
-        void ShowUploadDevicesInfo (string stateCodeStr)
+        void ShowUploadDevicesInfo (string stateCodeStr,bool bUpload = true)
         {
             string mes = "";
             if (stateCodeStr == "NoRecord") {
@@ -510,7 +555,11 @@
             }
             if (!string.IsNullOrEmpty (mes)) {
                 Application.RunOnMainThread (() => {
-                    MainPage.AddTip (ErrorCode.AddFailed + " " + mes);
+                    if (bUpload) {
+                        MainPage.AddTip (ErrorCode.AddFailed + " " + mes);
+                    } else {
+                        MainPage.AddTip ("Update failed! " + mes);
+                    }
 
                     //new Alert ("", ErrorCode.AddFailed + " " + mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                 });
@@ -533,13 +582,45 @@
             }
             if (!string.IsNullOrEmpty (mes)) {
                 Application.RunOnMainThread (() => {
-                    MainPage.AddTip (ErrorCode.AddFailed + " " + mes);
+                    MainPage.AddTip (ErrorCode.OperationFailed + " " + mes);
                 });
             }
 
         }
 
         /// <summary>
+        /// 鍒锋柊璁惧鍚嶅瓧
+        /// </summary>
+        public bool UpdateDevice (UpdateDeviceObj mUpdateDeviceObj)
+        {
+            var mUpdateAlexaDeviceObj = new UpdateAlexaDeviceObj () {
+                Id = mUpdateDeviceObj.Id,
+                DeviceType = mUpdateDeviceObj.DeviceType,
+                SubnetID = mUpdateDeviceObj.SubnetID,
+                DeviceID = mUpdateDeviceObj.DeviceID,
+                LoopID = mUpdateDeviceObj.LoopID,
+                DeviceName = mUpdateDeviceObj.DeviceName,
+                MAC = mUpdateDeviceObj.MAC,
+                RegionID = UserConfig.Instance.CurrentRegion.Id,
+            };
+
+            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mUpdateAlexaDeviceObj);
+            var revertObj = MainPage.RequestHttps (API.UpdateDevice, requestJson);
+            if (revertObj.StateCode.ToUpper () == "SUCCESS") {
+                return true;
+            } else if (revertObj.StateCode == "Exist") {
+                Application.RunOnMainThread (() => {
+                    MainPage.AddTip ("Update failed!" + " " + ErrorCode.NameExist + " ( " + mUpdateDeviceObj.DeviceName + " )");
+                });
+                return true;
+            } else {
+                //2020-06-29 寮瑰嚭鎻愮ず閿欒
+                ShowUploadDevicesInfo (revertObj.StateCode, false);
+            }
+            return false;
+        }
+
+        /// <summary>
         /// 鍒犻櫎璁惧
         /// </summary>
         public bool DelDevice(string commonId)

--
Gitblit v1.8.0