From 7a2b08af309d3b16e380c83063da8211cc97217a Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期二, 22 九月 2020 14:18:42 +0800 Subject: [PATCH] 一个新版本 --- ZigbeeApp/Shared/Common/Device.cs | 69 +++++++++++++++++++--------------- 1 files changed, 39 insertions(+), 30 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs index ec7fb84..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); } @@ -227,7 +251,7 @@ { strMsg = itemName + "娌℃湁瀹炶(1)"; } - device = CommonDevice.CommonDeviceByByteString(itemName, "{}"); + device = CommonDevice.CommonDeviceByByteString(itemValue, "{}"); if (device == null) { strMsg += "\r\n" + itemName + "娌℃湁瀹炶(2)"; @@ -2600,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; @@ -2960,7 +2989,7 @@ return false; } //鏍规嵁鏂癟ype閲嶆柊New瀵硅薄 - var newDevice = CommonDevice.CommonDeviceByByteString(newDeviceType.ToString(), deviceData); + var newDevice = CommonDevice.CommonDeviceByByteString((int)newDeviceType, deviceData); if (newDevice == null) { //濂藉儚鏈夌偣鍙兘 @@ -3089,32 +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.Transverter) { device = new Transverter(); } - else if (deviceType == DeviceType.DimmerSwitch) { device = new DimmerSwitch(); } - 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; -- Gitblit v1.8.0