From c0ce2f57a4f836ebeb9e7b8b4b5a4407fd78dc86 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期三, 23 九月 2020 10:06:05 +0800
Subject: [PATCH] 上传

---
 ZigbeeApp/Shared/Common/Device.cs |  174 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 125 insertions(+), 49 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
index 8031876..5628cbf 100755
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -107,9 +107,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,11 +159,28 @@
                 }
                 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)
                 {
                     //涓嶅瓨鍦ㄧ殑璇濓紝閲嶆柊鐢熸垚
                     device.IconPath = string.Empty;
+                    device.ReSave();
+                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
+
+                    bolSave = false;
+                }
+                //閲嶆柊鐢熸垚鏂囦欢
+                if (bolSave == true)
+                {
                     device.ReSave();
                     HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                 }
@@ -165,6 +189,14 @@
             this.DeleteGatewayFileByMemberModel();
             //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
             this.InitRealDeviceRoomId();
+
+#if DEBUG
+            if (UserCenterResourse.HideOption.CenterHideMenu == 1)
+            {
+                //妫�娴嬩竴浜涗唬鐮侀厤缃�(debug)
+                this.CheckOhtherSettion();
+            }
+#endif
         }
 
         /// <summary>
@@ -196,6 +228,38 @@
                 {
                     //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑
                     HdlGatewayLogic.Current.DeleteGatewayFile(gwId);
+                }
+            }
+        }
+
+        /// <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);
+                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;
                 }
             }
         }
@@ -385,6 +449,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;
 
             //璁惧鍥炶矾鏀堕泦
@@ -765,6 +835,8 @@
                     this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
                 }
             }
+            //鍒犻櫎妯℃澘鏁版嵁
+            Phone.TemplateData.TemplateCommonLogic.Current.DeleteDevice(device);
 
             //鍒犻櫎璁惧鏂囦欢
             string filePath = device.FilePath;
@@ -850,13 +922,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);
             }
         }
 
@@ -1386,7 +1470,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)
@@ -1680,30 +1764,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>
@@ -2258,19 +2348,18 @@
         /// <param name="saveRoadDevice">濡傛灉鍙湁涓�涓洖璺�,鏄惁鎶婂洖璺殑鎴块棿涓�璧蜂慨鏀�</param>
         public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
         {
-            if (listDevice == null)
+            if (listDevice == null || listDevice.Count == 0)
             {
                 return;
             }
             //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜�
-            if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
+            if (saveRoadDevice == true && listDevice.Count == 1)
             {
-                if (listDevice[0] is OTADevice)
+                if ((listDevice[0] is OTADevice) == false)
                 {
-                    //鍗曠函鍙槸Ota璁惧鍒欎笉澶勭悊
-                    return;
+                    //ota璁惧涓嶉渶瑕佸鐞�
+                    HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
                 }
-                HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
             }
             bool save = false;
             if (roomId == string.Empty)
@@ -2535,9 +2624,14 @@
                 //鏂伴鐨勬箍搴︿紶鎰熷櫒涓嶆樉绀�
                 return false;
             }
+            if (((int)i_device.Type).ToString() == i_device.Type.ToString())
+            {
+                //姝よ澶噄d鍦―eviceType閲岄潰杩樻病鏈夋敞鍐�,鍒欎笉鑳芥樉绀哄嚭鏉�
+                return false;
+            }
 
             //濡傛灉鏄柊椋庨潰鏉挎垨鐜闈㈡澘,鍒欓兘涓嶆樉绀轰换浣曞洖璺�
-            var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
+                var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
             if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
             {
                 return false;
@@ -2656,7 +2750,7 @@
         {
             HdlThreadLogic.Current.RunMain(() =>
             {
-                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
+                var contr = new ShowMsgControl(Phone.ShowMsgType.Error, msg);
                 contr.Show();
             });
         }
@@ -2669,7 +2763,7 @@
         {
             HdlThreadLogic.Current.RunMain(() =>
             {
-                var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+                var contr = new ShowMsgControl(Phone.ShowMsgType.Tip, msg);
                 contr.Show();
             });
         }
@@ -2895,7 +2989,7 @@
                 return false;
             }
             //鏍规嵁鏂癟ype閲嶆柊New瀵硅薄
-            var newDevice = CommonDevice.CommonDeviceByByteString(newDeviceType.ToString(), deviceData);
+            var newDevice = CommonDevice.CommonDeviceByByteString((int)newDeviceType, deviceData);
             if (newDevice == null)
             {
                 //濂藉儚鏈夌偣鍙兘
@@ -3024,30 +3118,12 @@
         /// <returns></returns>
         public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
         {
-            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 + "}");
+            if (device == null)
+            {
+                return null;
+            }
 
             device.DeviceEpointName = string.Empty;
             device.DeviceName = string.Empty;
@@ -3088,7 +3164,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)
@@ -3106,7 +3182,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)
@@ -3125,7 +3201,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)
@@ -3145,7 +3221,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)
@@ -3164,7 +3240,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)

--
Gitblit v1.8.0