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 | 2063 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 1,340 insertions(+), 723 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs index 75fe150..ff806cc 100755 --- a/ZigbeeApp/Shared/Common/Device.cs +++ b/ZigbeeApp/Shared/Common/Device.cs @@ -58,17 +58,9 @@ } /// <summary> - /// R鏂囦欢閲岄潰璁惧妯″潡ID鐨勭炕璇戝悕瀛楃殑鍓嶇紑 + /// 璁惧鐨勬ā鍧桰D鐨勬灇涓� keys:妯″潡ID (Axxx浠h〃鏄涓夋柟璁惧) /// </summary> - public const string deviceModelIdName = "uDeviceModelId"; - /// <summary> - /// R鏂囦欢閲岄潰鎵�鏈夎澶囧悕瀛楃殑ID - /// </summary> - public Dictionary<string, int> dicDeviceAllNameID = null; - /// <summary> - /// 璁惧鐨勬ā鍧桰D鐨勬灇涓�(keys:妯″潡ID value:璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) - /// </summary> - private Dictionary<string, string> dicDeviceModelIdEnum = null; + private Dictionary<string, DeviceNameContent> dicDeviceModelIdEnum = null; /// <summary> /// 闇�瑕佽浆鎹㈢殑璁惧鐨勬ā鍧桰D(keys:鏃фā鍧桰D,value:鏂版ā鍧桰D) /// </summary> @@ -89,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 @@ -105,9 +93,9 @@ { this.dicAllDevice.Clear(); this.dicDeviceEpoint.Clear(); - - //鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D - this.InitDeviceDefultNameIDList(); + + //鍒濆鍖栬澶囨灇涓� + this.InitDeviceModelIdEnum(); //鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� List<string> listFile = this.GetAllDeviceFile(); @@ -115,20 +103,21 @@ { 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); } if (device == null || device.CurrentGateWayId == null) { -#if DEBUG - //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛� - string file1 = UserCenterLogic.CombinePath(file); - string file2 = UserCenterLogic.CombinePath("Back_" + file); - System.IO.File.Copy(file1, file2, true); -#endif //澶辨晥鐨勬枃浠讹紝娌℃湁缃戝叧id鐨勯兘鍒犻櫎鎺� Global.DeleteFilebyHomeId(file); continue; @@ -143,12 +132,6 @@ } else { -#if DEBUG - //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛� - string file1 = UserCenterLogic.CombinePath(file); - string file2 = UserCenterLogic.CombinePath("Back_" + file); - System.IO.File.Copy(file1, file2, true); -#endif //濡傛灉鏄富浜�,鎴栬�呯鐞嗗憳,閭d箞杩欎釜鏂囦欢鏄潪娉曠殑,鐩存帴鍒犻櫎 Global.DeleteFilebyHomeId(file); continue; @@ -172,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) { @@ -179,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> @@ -211,11 +219,43 @@ var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway(); foreach (var gateway in listGateway) { - string gwId = HdlGatewayLogic.Current.GetGatewayId(gateway); + string gwId = gateway.GwId; if (listId.Contains(gwId) == false) { //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑 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, 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; } } } @@ -228,13 +268,14 @@ /// <para>灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚)</para> /// <para>-1:寮傚父 1:姝e父 2:璁惧淇℃伅缂烘崯</para> /// </summary> - /// <param name="zbGateway">缃戝叧瀵硅薄</param> - public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway) + /// <param name="gatewayId">缃戝叧Id</param> + /// <param name="useLocalConnect">鏄惁寮哄埗浣跨敤鏈湴杩炴帴鍙戦��</param> + public int SetDeviceToMemmoryByGateway(string gatewayId, bool useLocalConnect) { //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧 int statu = 0; List<CommonDevice> listDevice = new List<CommonDevice>(); - List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, true); + List<CommonDevice> list = this.GetDeviceListFromGateway(gatewayId, ref statu, useLocalConnect); if (list == null) { return -1; @@ -242,12 +283,11 @@ listDevice.AddRange(list); //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶� - string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); - 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); } @@ -261,6 +301,7 @@ } //娣诲姞璁惧鐨勭紦瀛� + var listDriveDevice = new List<CommonDevice>(); for (int i = 0; i < listDevice.Count; i++) { var device = listDevice[i]; @@ -278,26 +319,18 @@ dicExist.Remove(maikey); } //鑾峰彇璁惧鐨勫浐瀹氬睘鎬� - HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device); - } - - for (int i = 0; i < listDevice.Count; i++) - { - var device = listDevice[i]; + if (HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device) == true) + { + System.Threading.Thread.Sleep(200); + } //瀵规湭鍛藉悕鐨勮櫄鎷熻澶囬噸鏂板懡鍚� if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty) { - //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О - var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); - //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� - dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; - - HdlThreadLogic.Current.RunThread(async () => - { - await this.ReName(device, dName, ShowErrorMode.NO); - }); + listDriveDevice.Add(device); } } + //璁剧疆铏氭嫙璁惧鐨勯粯璁ゅ悕瀛� + this.SetDriveDeviceDefultName(listDriveDevice); //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂 if (statu != 1) @@ -326,7 +359,7 @@ if (listDeleteMac.Count > 0) { //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄� - this.DeleteRealDeviceFromRoom(listDeleteMac); + HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listDeleteMac); } return statu; @@ -352,6 +385,8 @@ var tempDevice = this.dicOTADevice[mainKeys]; //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 this.SetDeviceInfoToMain(tempDevice, device); + //鍒锋柊璁惧鍔熻兘绫诲瀷(杩欎釜涓滆タ闇�瑕佺嫭绔嬪嚭鏉�) + this.RefreshDeviceFunctionType(tempDevice, device, false); device = tempDevice; } @@ -373,6 +408,8 @@ var tempDevice = this.dicAllDevice[mainKeys]; //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 this.SetDeviceInfoToMain(tempDevice, device); + //鍒锋柊璁惧鍔熻兘绫诲瀷(杩欎釜涓滆タ闇�瑕佺嫭绔嬪嚭鏉�) + this.RefreshDeviceFunctionType(tempDevice, device, false); device = tempDevice; } else @@ -407,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; //璁惧鍥炶矾鏀堕泦 @@ -431,7 +474,7 @@ /// <param name="device">璁惧瀵硅薄</param> /// <param name="newName">鏂板悕瀛�</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> - public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES) + public bool ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES) { //鍏堝埆绠¢偅涔堝锛屾洿鏀瑰悕瀛楀悗锛屽埛鏂拌澶囩紦瀛� this.SetEpointName(device, newName); @@ -442,7 +485,7 @@ if (Common.Config.Instance.Home.IsVirtually == true) { //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� - Phone.UserView.UserPage.Instance.RefreshForm = true; + Phone.UserView.UserPage.Instance.RefreshAllForm = true; return true; } @@ -450,7 +493,7 @@ //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� if (UserCenterResourse.UserInfo.AuthorityNo != 3) { - var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName); + var result = this.RenameDeviceNameAsync(device, newName); if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) { //璁惧鍚嶇О淇敼澶辫触 @@ -464,11 +507,9 @@ } return false; } - //澶囦唤鏁版嵁 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绔偣鍚嶇О, newName); } //淇敼璁惧鍚嶅瓧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� - Phone.UserView.UserPage.Instance.RefreshForm = true; + Phone.UserView.UserPage.Instance.RefreshAllForm = true; return true; } @@ -478,7 +519,7 @@ /// <param name="listDevice">璁惧瀵硅薄</param> /// <param name="newMacName">鏂板悕瀛�</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> - public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES) + public bool ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES) { if (listDevice.Count == 0) { @@ -506,7 +547,7 @@ if (UserCenterResourse.UserInfo.AuthorityNo != 3) { //淇敼鐗╃悊鍚嶅瓧 - var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName); + var result = this.RenameDeviceMacNameAsync(device, newMacName); if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0) { //璁惧鍚嶇О淇敼澶辫触 @@ -519,15 +560,13 @@ } return false; } - //澶囦唤鏁版嵁 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName); //濡傛灉瀹冨彧鏈変竴涓洖璺�,鍒欐洿鏀圭鐐瑰悕瀛� if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true) { //鍙湁涓�涓鐐� if (this.dicDeviceEpoint[device.DeviceAddr].Count == 1) { - return await this.ReName(device, newMacName); + return this.ReName(device, newMacName); } //濡傛灉瀹冩湁涓や釜绔偣鏃�,pir浼犳劅鍣ㄧ壒娈婂鐞� else if (this.dicDeviceEpoint[device.DeviceAddr].Count == 2) @@ -539,7 +578,7 @@ { if (myDevice.Type == DeviceType.IASZone) { - return await this.ReName(myDevice, newMacName); + return this.ReName(myDevice, newMacName); } } } @@ -547,6 +586,136 @@ } } 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> + /// </summary> + private CommonDevice.RenameDeviceMacNameAllData RenameDeviceMacNameAsync(CommonDevice device, string macName) + { + //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); + } + + //鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗� + var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName); + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon", 8); + if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) + { + return null; + } + //鍔犵紦瀛� + Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceMacName(device, macName); + + var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RenameDeviceMacNameData>(result.ReceiptData); + return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData }; + } + + /// <summary> + /// 淇敼璁惧绔彛锛堟寜閿級鍚嶇О + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="deviceName">璁惧绔偣鍚嶅瓧</param> + /// <returns></returns> + private CommonDevice.DeviceRenameAllData RenameDeviceNameAsync(CommonDevice device, string deviceName) + { + //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + return Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); + } + //鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗� + var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName); + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon", 8); + if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) + { + return null; + } + //鍔犵紦瀛� + Phone.TemplateData.TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, deviceName); + + var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceRenameResponseData>(result.ReceiptData); + return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData }; + } + + /// <summary> + /// 鑾峰彇缂栬緫璁惧Mac鍚嶅瓧鐨勫懡浠ゅ瓧绗� + /// </summary> + /// <param name="deviceAddr"></param> + /// <param name="deviceEpoint"></param> + /// <param name="deviceName"></param> + /// <returns></returns> + public string GetReDeviceMacNameCommandText(string deviceAddr, int deviceEpoint, string deviceName) + { + var bytes = new byte[64]; + var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName); + System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length); + deviceName = Encoding.UTF8.GetString(bytes); + + var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "MacName", deviceName } }; + jObject.Add("Data", data); + return jObject.ToString(); + } + + /// <summary> + /// 鑾峰彇缂栬緫璁惧绔偣鍚嶅瓧鐨勫懡浠ゅ瓧绗� + /// </summary> + /// <param name="deviceAddr"></param> + /// <param name="deviceEpoint"></param> + /// <param name="deviceName"></param> + /// <returns></returns> + public string GetReDeviceEpointNameCommandText(string deviceAddr, int deviceEpoint, string deviceName) + { + var bytes = new byte[64]; + var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName); + System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length); + deviceName = Encoding.UTF8.GetString(bytes); + + var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } }; + var data = new Newtonsoft.Json.Linq.JObject { { "DeviceName", deviceName } }; + jObject.Add("Data", data); + + return jObject.ToString(); } /// <summary> @@ -590,22 +759,26 @@ /// <param name="listdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param> public async Task<bool> DeleteDevice(List<CommonDevice> listdevice) { - var data = new CommonDevice.RemoveDeviceData(); - var info = new CommonDevice.RemoveDeviceListInfo(); - info.DeviceAddr = listdevice[0].DeviceAddr; - data.DeviceAddrList.Add(info); - - //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎 - var result = await listdevice[0].DeleteDeviceAsync(data); - if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0) + //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧 + if (Config.Instance.Home.IsVirtually == false) { - //璁惧鍒犻櫎澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + var data = new CommonDevice.RemoveDeviceData(); + var info = new CommonDevice.RemoveDeviceListInfo(); + info.DeviceAddr = listdevice[0].DeviceAddr; + data.DeviceAddrList.Add(info); - this.ShowErrorMsg(msg); - return false; + //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎 + var result = await listdevice[0].DeleteDeviceAsync(data); + if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0) + { + //璁惧鍒犻櫎澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + this.ShowErrorMsg(msg); + return false; + } } //鍒犻櫎缂撳瓨鐨凮ta璁惧 @@ -615,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; } @@ -633,7 +802,7 @@ public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) { //鍒犻櫎缂撳瓨璁惧鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂� - Phone.UserView.UserPage.Instance.RefreshForm = true; + Phone.UserView.UserPage.Instance.RefreshAllForm = true; if (deleteRoom == true) { @@ -657,6 +826,8 @@ this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint); } } + //鍒犻櫎妯℃澘鏁版嵁 + Phone.TemplateData.TemplateCommonLogic.Current.DeleteDevice(device); //鍒犻櫎璁惧鏂囦欢 string filePath = device.FilePath; @@ -710,18 +881,57 @@ #endregion + #region 鈻� 鍚屾璁惧___________________________ + /// <summary> + /// 鍚屾璁惧骞朵笖鍒锋柊缂撳瓨(鍚屾澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <param name="litdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param> + public async Task<bool> SynchronizationDevice(List<CommonDevice> listdevice) + { + //铏氭嫙浣忓畢鐨勮瘽,涓嶉渶瑕佸垹闄ょ綉鍏崇殑璁惧 + if (Config.Instance.Home.IsVirtually == false) + { + //鍚屾 + var result = await listdevice[0].SyncMsgToBindSource(listdevice[0].DeviceAddr, listdevice[0].DeviceEpoint); + if (result == null || result.result != 0) + { + //鍚屾鍒犻櫎澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.SynchronizationFailed); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + this.ShowErrorMsg(msg); + return false; + } + } + return true; + } + #endregion + #region 鈻� 娴嬭瘯璁惧___________________________ /// <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); } } @@ -732,19 +942,29 @@ /// <returns></returns> public bool DeviceIsCanFixedPosition(CommonDevice device) { - if (device.Type == DeviceType.DoorLock) + if (device.Type == DeviceType.DoorLock || device.Type == DeviceType.PMSensor) { //闂ㄩ攣娌℃湁瀹氫綅鍔熻兘 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閮芥病鏈夊畾浣嶅姛鑳� return true; } + else if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_SphericalMotion) + { + //鐞冨瀷绉诲姩浼犳劅鍣ㄨ櫧鐒舵槸鐢垫睜璁惧,浣嗘槸瀹冩湁瀹氫綅鍔熻兘 + return true; + } + return false; + } + //娓╂箍搴︿紶鎰熷櫒娌℃湁瀹氫綅鍔熻兘 + if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_TemperatureHumidity) + { return false; } @@ -755,6 +975,22 @@ { return true; } + } + return false; + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈変竴閿悓姝ュ姛鑳� + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool DeviceIsCanSynchronization(CommonDevice device) + { + //鑾峰彇璁惧绫诲瀷鐨� + var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction) + { + return true; } return false; } @@ -889,6 +1125,89 @@ } /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇绠�绾﹂潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄 + /// </summary> + /// <param name="listDevice"></param> + /// <returns></returns> + public List<CommonDevice> GetMutilfunctionPanelByMac(List<CommonDevice> listDevice, bool sort = true) + { + //鍜屽姜鍝ャ�佽澶囧拰浜у搧閮ㄥ悓浜嬬‘璁わ細 + //绠�绾﹀鍔熻兘闈㈡澘[涓嶆樉绀哄浣欑殑鍥炶矾锛屽彧鏄剧ず鎼哄甫鐨�2涓户鐢靛櫒锛�1涓俯搴︿紶鎰熷櫒锛�1涓箍搴︿紶鎰熷櫒 + var list = new List<CommonDevice>(); + foreach (var dev in listDevice) + { + if (dev.Type == DeviceType.TemperatureSensor) + { + if (dev.DeviceEpoint == 64) + { + list.Add(dev); + } + } + else if (dev.Type == DeviceType.FreshAirHumiditySensor) + { + if (dev.DeviceEpoint == 65) + { + list.Add(dev); + } + } + else if (dev.Type == DeviceType.OnOffOutput) + { + list.Add(dev); + } + } + + if (sort == false) + { + return list; + } + list.Sort((obj1, obj2) => + { + if (obj1.DeviceEpoint > obj2.DeviceEpoint) + { + return 1; + } + return -1; + }); + + return list; + } + + /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇鏂伴銆佺畝绾︾幆澧冮潰鏉垮叏閮ㄥ洖璺殑璁惧瀵硅薄 + /// </summary> + /// <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) + { + if (dev.Type == DeviceType.TemperatureSensor) + { + list.Add(dev); + } + else if (dev.Type == DeviceType.FreshAirHumiditySensor) + { + list.Add(dev); + } + } + if (sort == false) + { + return list; + } + list.Sort((obj1, obj2) => + { + + if (obj1.DeviceEpoint > obj2.DeviceEpoint) + { + return 1; + } + return -1; + }); + return list; + } + + /// <summary> /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(寮哄埗鎺掑簭) /// </summary> /// <param name="DeviceAddr">Mac鍦板潃</param> @@ -942,7 +1261,7 @@ public List<string> GetAllDeviceFile() { List<string> listDeviceFile = new List<string>(); - List<string> listAllFile = Global.FileListByHomeId(); + List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile(); foreach (string file in listAllFile) { @@ -1003,6 +1322,214 @@ #endregion + #region 鈻� 鑾峰彇璁惧淇℃伅_______________________ + + /// <summary> + /// 浠庣綉鍏宠鍙栧崟涓鐐瑰洖璺澶囦俊鎭� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public CommonDevice.DeviceInfoData ReadDeviceEpointDeviceInfo(CommonDevice device) + { + var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } }; + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetStatusRecord", jObject.ToString(), "GetStatusRecord_Respon"); + if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) + { + return null; + } + var info = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(result.ReceiptData); + 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 鈻� 璁剧疆璁惧鍔熻兘绫诲瀷___________________ + + /// <summary> + /// 璁剧疆璁惧鍔熻兘绫诲瀷鍒扮綉鍏� + /// </summary> + /// <param name="device">璁惧鍥炶矾</param> + /// <param name="functionType">鍔熻兘绫诲瀷</param> + /// <returns></returns> + public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType) + { + //濡傛灉鏄櫄鎷熶綇瀹� + 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; + } + var resultData = Newtonsoft.Json.Linq.JObject.Parse(result.ReceiptData); + if (resultData.Property("Result") != null) + { + //0:淇敼鎴愬姛 1:淇敼澶辫触 + 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 + #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________ /// <summary> @@ -1017,6 +1544,12 @@ { return dName; } + if (this.IsMiniLight(device) == true) + { + //Mini澶滅伅 + return Language.StringByID(R.MyInternationalizationString.uMiniNightLight); + } + //濡傛灉杩欎釜璁惧鍙湁涓�涓洖璺殑璇�,杩斿洖Mac鍚嶅瓧缁欏畠 if (this.GetDevicesCountByMac(device.DeviceAddr) <= 1) { @@ -1041,7 +1574,9 @@ } if (device.Type == DeviceType.OnOffOutput - || device.Type == DeviceType.DimmableLight || device.Type == DeviceType.ColorDimmableLight) + || device.Type == DeviceType.DimmableLight + || device.Type == DeviceType.ColorDimmableLight + || device.Type == DeviceType.ColorTemperatureLight) { //缁х數鍣�,鎺夊厜鍣ㄩ兘鍙洖璺� return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo; @@ -1050,16 +1585,6 @@ { //绌鸿皟閮藉彨瀹ゅ唴鏈� return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo; - } - else if (device.Type == DeviceType.FreshAir) - { - //鏂伴闈㈡澘涓殑鎸夐敭鍙柊椋� - return Language.StringByID(R.MyInternationalizationString.FreshAir); - } - else if (device.Type == DeviceType.FreshAirHumiditySensor) - { - //鏂伴闈㈡澘婀垮害浼犳劅鍣� - return Language.StringByID(R.MyInternationalizationString.HumiditySensor); } //鑾峰彇璁惧绫诲瀷 @@ -1074,24 +1599,43 @@ //鍏朵粬鐨勫共鎺ョ偣鍙共鎺ョ偣 else { - return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo; + var infoContent = this.GetDeviceModelIdNameInfo("A419"); + return infoContent != null ? infoContent.A瀹樻柟鍚嶅瓧 + epointNo : string.Empty; } + } + else if (device.Type == DeviceType.FreshAirHumiditySensor) + { + //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾︾幆澧冮潰鏉挎箍搴︿紶鎰熷櫒 + return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.HumiditySensor); } else if (device.Type == DeviceType.TemperatureSensor) { - if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir) + if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir + || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment + || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueEnvironment + || deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction) { - //鏂伴闈㈡澘涓殑Thermostat涓烘俯搴︿紶鎰熷櫒 - return Language.StringByID(R.MyInternationalizationString.TemperatureSensor); + //鏂伴闈㈡澘/绠�绾﹀鍔熻兘/绠�绾�/鏂规偊鐜闈㈡澘 娓╁害浼犳劅鍣� + return deviceInfoType.DeviceDefultName + Language.StringByID(R.MyInternationalizationString.TemperatureSensor); } else if (deviceInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) { //闈㈡澘鐨勬俯搴︽帰澶村彨 闈㈡澘鍚嶅瓧+娓╁害 - return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.uTemperature); + 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); } } //鍏朵粬鎯呭喌,浣跨敤瀹冪殑榛樿鍚嶇О - return Language.StringByID(deviceInfoType.DefultNameId) + epointNo; + return deviceInfoType.DeviceDefultName + epointNo; } /// <summary> @@ -1106,10 +1650,15 @@ { return dName; } + if (this.IsMiniLight(device) == true) + { + //Mini澶滅伅 + return Language.StringByID(R.MyInternationalizationString.uMiniNightLight); + } //鑾峰彇璁惧绫诲瀷 var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); - return Language.StringByID(deviceInfoType.DefultNameId); + return deviceInfoType.DeviceDefultName; } /// <summary> @@ -1118,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; } @@ -1129,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; } @@ -1152,32 +1701,6 @@ public string GetSimpleEpointName(CommonDevice device) { return device.DeviceEpointName; - } - - /// <summary> - /// 鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D - /// </summary> - private void InitDeviceDefultNameIDList() - { - if (this.dicDeviceAllNameID != null) - { - return; - } - this.dicDeviceAllNameID = new Dictionary<string, int>(); - Type type = typeof(R.MyInternationalizationString); - - var PropertyList = type.GetFields(); - foreach (var item in PropertyList) - { - if (item.Name.StartsWith(deviceModelIdName) == true - || item.Name.StartsWith("uDeviceBelongId") == true) - { - this.dicDeviceAllNameID[item.Name] = Convert.ToInt32(item.GetValue(null)); - } - } - - //鍒濆鍖栬澶囨灇涓� - this.InitDeviceModelIdEnum(); } #endregion @@ -1371,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> @@ -1441,7 +1970,6 @@ unSelectPath = imageFilePath; selectPath = imageSelectFilePath; } - #endregion @@ -1498,7 +2026,7 @@ //鑾峰彇鑷畾涔夎澶囩被鍨� var myInfoType = this.GetMyDeviceEnumInfo(listDevice); //鑾峰彇璁惧绫诲瀷鐨勭炕璇戝悕瀛� - string strName = Language.StringByID(myInfoType.ObjectTypeNameId); + string strName = myInfoType.ObjectTypeName; if (strName == string.Empty) { //鍔犱竴灞備繚闄�,鏈煡璁惧 @@ -1560,32 +2088,25 @@ return null; } - string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); - int ConcreteValue = Convert.ToInt32(strValue[0]); - int BeloneValue = Convert.ToInt32(strValue[1]); + var nameContent = this.dicDeviceModelIdEnum[modelKeys]; //璁剧疆璁惧鐨勩�愯澶囨墍灞炵被鍨嬨�� - info.BeloneType = (DeviceBeloneType)BeloneValue; - if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + BeloneValue) == true) - { - //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 - info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + BeloneValue]; - } + info.BeloneType = (DeviceBeloneType)nameContent.BeloneTypeValue; + info.BeloneText = nameContent.A鎵�灞炲悕瀛�; //璁惧鍏蜂綋绫诲瀷 - info.ConcreteType = (DeviceConcreteType)ConcreteValue; - if (info.ConcreteType.ToString() == ConcreteValue.ToString()) + info.ConcreteType = (DeviceConcreteType)nameContent.ConcreteTypeValue; + if (info.ConcreteType.ToString() == nameContent.ConcreteTypeValue.ToString()) { info.ConcreteType = DeviceConcreteType.UnKownDevice; } - string keyName = deviceModelIdName + ConcreteValue; - if (this.dicDeviceAllNameID.ContainsKey(keyName) == true) - { - //璁惧鐨勫畼鏂瑰悕绉� - info.ConcreteTextId = this.dicDeviceAllNameID[keyName]; - } + //璁惧鐨勫畼鏂瑰悕绉� + info.ConcreteText = nameContent.A瀹樻柟鍚嶅瓧; //璁惧鐨勭被鍨嬬炕璇戝悕绉� - info.ObjectTypeNameId = Convert.ToInt32(strValue[2]); + info.ObjectTypeName = nameContent.A绫诲瀷鍚嶅瓧; + + //璁惧榛樿鍚嶅瓧 + info.DeviceDefultName = nameContent.A澶囨敞鍚嶅瓧; return info; } @@ -1606,33 +2127,22 @@ || info.BeloneType == DeviceBeloneType.A褰╃伅) { //褰掍负鐏厜 - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; - info.BeloneType = DeviceBeloneType.A鐏厜; info.ConcreteType = DeviceConcreteType.Light; - info.ObjectTypeNameId = 60007;//璋冨厜妯″潡 - - int value = (int)info.BeloneType; - if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true) - { - //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 - info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value]; - } + info.ConcreteText = this.dicDeviceModelIdEnum["A418"].A瀹樻柟鍚嶅瓧; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.BeloneText = this.dicDeviceModelIdEnum["A418"].A瀹樻柟鍚嶅瓧; + 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.BeloneType = DeviceBeloneType.A浼犳劅鍣�; info.ConcreteType = DeviceConcreteType.Sensor; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; - info.ObjectTypeNameId = 60000;//浼犳劅鍣� - - int value = (int)info.BeloneType; - if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true) - { - //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 - info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value]; - } + info.ConcreteText = this.dicDeviceModelIdEnum["A402"].A瀹樻柟鍚嶅瓧; + info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; + info.BeloneText = this.dicDeviceModelIdEnum["A402"].A瀹樻柟鍚嶅瓧; + info.ObjectTypeName = this.dicDeviceModelIdEnum["A402"].A绫诲瀷鍚嶅瓧;//浼犳劅鍣� } return info; @@ -1660,50 +2170,50 @@ { if (listdevice.Count > 1) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200; + info.ConcreteText = this.dicDeviceModelIdEnum["A401"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; info.ConcreteType = DeviceConcreteType.ButtonPanel; } else { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16; + info.ConcreteText = this.dicDeviceModelIdEnum["A419"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A骞叉帴鐐�; info.ConcreteType = DeviceConcreteType.DryContact; } - info.ObjectTypeNameId = 60003;//鏅鸿兘闈㈡澘 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A401"].A绫诲瀷鍚嶅瓧;//鏅鸿兘闈㈡澘 } //3鍖呭惈绐楀笜鐨勮瘽,褰撶獥甯樺鐞� else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId100; + info.ConcreteText = this.dicDeviceModelIdEnum["A400"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A绐楀笜; info.ConcreteType = DeviceConcreteType.Curtain; - info.ObjectTypeNameId = 60002;//閬槼妯″潡 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A400"].A绫诲瀷鍚嶅瓧;//閬槼妯″潡 } //4绌烘皵寮�鍏� else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) { //榛樿鍊� - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100; + info.ConcreteText = this.dicDeviceModelIdEnum["A408"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A寮�鍏�; info.ConcreteType = DeviceConcreteType.AirSwitch; - info.ObjectTypeNameId = 60001;//寮�鍏虫ā鍧� + info.ObjectTypeName = this.dicDeviceModelIdEnum["A408"].A绫诲瀷鍚嶅瓧;//寮�鍏虫ā鍧� if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A寮�鍏�) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.ConcreteText = this.dicDeviceModelIdEnum["A416"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A寮�鍏�; info.ConcreteType = DeviceConcreteType.Switch; } else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鎻掑骇) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.ConcreteText = this.dicDeviceModelIdEnum["A417"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鎻掑骇; info.ConcreteType = DeviceConcreteType.Socket1; } else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鐏厜) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.ConcreteText = this.dicDeviceModelIdEnum["A418"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鐏厜; info.ConcreteType = DeviceConcreteType.Light; } @@ -1712,26 +2222,26 @@ else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) { //榛樿鍊� - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300; + info.ConcreteText = this.dicDeviceModelIdEnum["A403"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A缁х數鍣�; info.ConcreteType = DeviceConcreteType.Relay; - info.ObjectTypeNameId = 60001;//寮�鍏虫ā鍧� + info.ObjectTypeName = this.dicDeviceModelIdEnum["A403"].A绫诲瀷鍚嶅瓧;//寮�鍏虫ā鍧� if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A寮�鍏�) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.ConcreteText = this.dicDeviceModelIdEnum["A416"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A寮�鍏�; info.ConcreteType = DeviceConcreteType.Switch; } else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鎻掑骇) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.ConcreteText = this.dicDeviceModelIdEnum["A417"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鎻掑骇; info.ConcreteType = DeviceConcreteType.Socket1; } else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鐏厜) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.ConcreteText = this.dicDeviceModelIdEnum["A418"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鐏厜; info.ConcreteType = DeviceConcreteType.Light; } @@ -1739,58 +2249,58 @@ //6璋冨厜鍣� else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2500; + info.ConcreteText = this.dicDeviceModelIdEnum["A404"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A璋冨厜鍣�; info.ConcreteType = DeviceConcreteType.DimmableLight; - info.ObjectTypeNameId = 60007;//璋冨厜妯″潡 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A404"].A绫诲瀷鍚嶅瓧;//璋冨厜妯″潡 } //7褰╃伅 else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9; + info.ConcreteText = this.dicDeviceModelIdEnum["A410"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A褰╃伅; info.ConcreteType = DeviceConcreteType.ColorLight; - info.ObjectTypeNameId = 60007;//璋冨厜妯″潡 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A410"].A绫诲瀷鍚嶅瓧;//璋冨厜妯″潡 } //8绌鸿皟 else if (dicType.ContainsKey(DeviceType.Thermostat) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3600; + info.ConcreteText = this.dicDeviceModelIdEnum["A406"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A绌鸿皟; info.ConcreteType = DeviceConcreteType.AirConditioner; - info.ObjectTypeNameId = 60009;//绌鸿皟妯″潡 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A406"].A绫诲瀷鍚嶅瓧;//绌鸿皟妯″潡 } //9涓户鍣� else if (dicType.ContainsKey(DeviceType.Repeater) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3900; + info.ConcreteText = this.dicDeviceModelIdEnum["A407"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A涓户鍣�; info.ConcreteType = DeviceConcreteType.Repeater; - info.ObjectTypeNameId = 60006;//绯荤粺璁惧 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A407"].A绫诲瀷鍚嶅瓧;//绯荤粺璁惧 } //10杞崲鍣� else if (dicType.ContainsKey(DeviceType.Transverter) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4200; + info.ConcreteText = this.dicDeviceModelIdEnum["A409"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A杞崲鍣�; info.ConcreteType = DeviceConcreteType.Converter; - info.ObjectTypeNameId = 60008;//杞崲鍣� + info.ObjectTypeName = this.dicDeviceModelIdEnum["A409"].A绫诲瀷鍚嶅瓧;//杞崲鍣� } //11鏅鸿兘闂ㄩ攣 else if (dicType.ContainsKey(DeviceType.DoorLock) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2800; + info.ConcreteText = this.dicDeviceModelIdEnum["A405"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鏅鸿兘闂ㄩ攣; info.ConcreteType = DeviceConcreteType.IntelligentLocks; - info.ObjectTypeNameId = 60010;//鏅鸿兘闂ㄩ攣 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A405"].A绫诲瀷鍚嶅瓧;//鏅鸿兘闂ㄩ攣 } //12鍖呭惈浼犳劅鍣ㄧ殑璇�,褰撲紶鎰熷櫒澶勭悊 else if (dicType.ContainsKey(DeviceType.IASZone) == true) { info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; info.ConcreteType = DeviceConcreteType.Sensor; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; - info.ObjectTypeNameId = 60000;//浼犳劅鍣� + info.ConcreteText = this.dicDeviceModelIdEnum["A402"].A瀹樻柟鍚嶅瓧; + info.ObjectTypeName = this.dicDeviceModelIdEnum["A402"].A绫诲瀷鍚嶅瓧;//浼犳劅鍣� //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 this.SetSensorDeviceSpecificType(ref info, listdevice); } @@ -1821,48 +2331,53 @@ { //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A娓╂箍搴︿紶鎰熷櫒; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10; + info.ConcreteText = this.dicDeviceModelIdEnum["A411"].A瀹樻柟鍚嶅瓧; info.ConcreteType = DeviceConcreteType.Sensor_TemperatureHumidity; } else if (temperatrue == true && humidity == false) { //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A娓╁害浼犳劅鍣�; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11; + info.ConcreteText = this.dicDeviceModelIdEnum["A412"].A瀹樻柟鍚嶅瓧; info.ConcreteType = DeviceConcreteType.Sensor_Temperature; } else if (temperatrue == false && humidity == true) { //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 info.BeloneType = DeviceBeloneType.A婀垮害浼犳劅鍣�; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId12; + info.ConcreteText = this.dicDeviceModelIdEnum["A413"].A瀹樻柟鍚嶅瓧; info.ConcreteType = DeviceConcreteType.Sensor_Humidity; } - info.ObjectTypeNameId = 60000;//浼犳劅鍣� + info.ObjectTypeName = this.dicDeviceModelIdEnum["A411"].A绫诲瀷鍚嶅瓧;//浼犳劅鍣� } //14鏂伴璁惧 else if (dicType.ContainsKey(DeviceType.FreshAir) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId2310; + info.ConcreteText = this.dicDeviceModelIdEnum["A414"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.A鏂伴; info.ConcreteType = DeviceConcreteType.Relay_FangyueFreshAirModul; - info.ObjectTypeNameId = 60011;//鏂伴 + info.ObjectTypeName = this.dicDeviceModelIdEnum["A414"].A绫诲瀷鍚嶅瓧;//鏂伴 } //15 PM2.5浼犳劅鍣ㄨ澶� else if (dicType.ContainsKey(DeviceType.PMSensor) == true) { - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1307; + info.ConcreteText = this.dicDeviceModelIdEnum["A415"].A瀹樻柟鍚嶅瓧; info.BeloneType = DeviceBeloneType.APM2鐐�5绌烘皵璐ㄩ噺浼犳劅鍣�; info.ConcreteType = DeviceConcreteType.Sensor_PMTwoPointFive; - info.ObjectTypeNameId = 60000;//浼犳劅鍣� + info.ObjectTypeName = this.dicDeviceModelIdEnum["A415"].A绫诲瀷鍚嶅瓧;//浼犳劅鍣� + } + //16鑹叉俯鐏� + else if (dicType.ContainsKey(DeviceType.ColorTemperatureLight) == true) + { + info.ConcreteText = this.dicDeviceModelIdEnum["A420"].A瀹樻柟鍚嶅瓧; + info.BeloneType = DeviceBeloneType.A褰╃伅; + info.ConcreteType = DeviceConcreteType.ColorLight_Temperature; + info.ObjectTypeName = this.dicDeviceModelIdEnum["A420"].A绫诲瀷鍚嶅瓧;//璋冨厜妯″潡 } - int value = (int)info.BeloneType; - if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true) - { - //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 - info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value]; - } + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneText = info.ConcreteText; + info.DeviceDefultName = info.ConcreteText; return info; } @@ -1888,179 +2403,44 @@ { //杩愬姩浼犳劅鍣� info.ConcreteType = DeviceConcreteType.Sensor_Motion; - info.ConcreteTextId = R.MyInternationalizationString.uMotionSensor; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uMotionSensor); } else if (iasZone.IasDeviceType == 40) { //鐑熼浘浼犳劅鍣� info.ConcreteType = DeviceConcreteType.Sensor_Fire; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1302; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorFire); } else if (iasZone.IasDeviceType == 42) { //姘翠镜浼犳劅鍣� info.ConcreteType = DeviceConcreteType.Sensor_Water; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1304; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorWater); } else if (iasZone.IasDeviceType == 43) { //鐕冩皵浼犳劅鍣� info.ConcreteType = DeviceConcreteType.Sensor_CarbonMonoxide; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1300; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorCarbonMonoxide); } else if (iasZone.IasDeviceType == 44) { //绱ф�ユ寜閽� info.ConcreteType = DeviceConcreteType.Sensor_EmergencyButton; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1305; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorEmergencyButton); } else if (iasZone.IasDeviceType == 277) { //閽ュ寵鎵� info.ConcreteType = DeviceConcreteType.Sensor_Keyfob; - info.ConcreteTextId = R.MyInternationalizationString.uKeyfob; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uKeyfob); } else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22) { //闂ㄧ獥浼犳劅鍣� info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow; - info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301; + info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorDoorWindow); } - } - - #endregion - - #region 鈻� 鐗╃悊璁惧鎵�灞炴埧闂確__________________ - - /// <summary> - /// 鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍 - /// </summary> - private void InitRealDeviceRoomId() - { - this.dicDeviceRoomId = new Dictionary<string, string>(); - string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); - var strData = UserCenterLogic.LoadFileContent(fullName); - if (strData != null) - { - this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData); - } - } - - /// <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; - } - } - - if (save == true) - { - //淇濆瓨璁板綍 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); - UserCenterLogic.SaveFileContent(fullName, 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.GetFloorRoomName(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; - } - //淇濆瓨璁板綍 - string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); - UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId); - - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); } #endregion @@ -2134,41 +2514,8 @@ //鍏朵粬鐨勭湅鐫�鍔炲憲,閮芥槸鎺掑湪鍚庨潰鐨�,閮藉綊涓鸿繖涓睘鎬� list.Add(DeviceBeloneType.A鏈煡璁惧); - + return list; - } - - #endregion - - #region 鈻� 鑾峰彇璁惧鍦ㄧ嚎鐘舵�佸垪琛╛______________ - - /// <summary> - /// 鑾峰彇璁惧鍦ㄧ嚎鐘舵�佸垪琛�(娉ㄦ剰,涓�涓澶囧彧杩斿洖涓�涓洖璺�) - /// </summary> - /// <param name="gwId">缃戝叧id</param> - /// <returns></returns> - public List<CommonDevice> GetDeviceOnlineList(string gwId) - { - var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId); - int statu = 0; - var listDevice = this.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO); - if (statu == -1) - { - //褰撳嚭鐜板紓甯告椂,浣跨敤鍚庡鎿嶄綔,鐩存帴鑾峰彇鏈湴鐨勮澶囧垪琛� - listDevice = this.GetDeviceByGatewayID(gwId); - } - - var listCheck = new HashSet<string>(); - var listReturn = new List<CommonDevice>(); - foreach (var device in listDevice) - { - if (listCheck.Contains(device.DeviceAddr) == false) - { - listCheck.Add(device.DeviceAddr); - listReturn.Add(device); - } - } - return listReturn; } #endregion @@ -2179,9 +2526,15 @@ /// 浠庣紦瀛樺彉閲忔娴嬭澶囨槸鍚﹀湪绾� /// </summary> /// <param name="i_device"></param> + /// <param name="checkAll">鏄惁妫�娴嬪叏閮ㄥ洖璺�</param> /// <returns></returns> - public bool CheckDeviceIsOnline(CommonDevice i_device) + public bool CheckDeviceIsOnline(CommonDevice i_device, bool checkAll = true) { + if (checkAll == false) + { + //涓嶆娴嬪叏閮ㄥ洖璺� + return i_device.IsOnline == 1 || i_device.IsOnline == 2; + } var listDevice = this.GetDevicesByMac(i_device.DeviceAddr, false); foreach (var device in listDevice) { @@ -2211,16 +2564,8 @@ if (i_device.Type == DeviceType.OnOffOutput || i_device.Type == DeviceType.AirSwitch) { //2020.03.23杩藉姞寮忔牱:鏈寚瀹氱被鍨嬬殑缁х數鍣�,涓嶆樉绀� - if (i_device.DfunctionType == DeviceFunctionType.A鏈畾涔�) - { - return false; - } - } - //濡傛灉鏄柊椋庨潰鏉跨殑鏂伴璁惧,鍒欎笉鏄剧ず - else if (i_device.Type == DeviceType.FreshAir) - { - var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); - if (myInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir) + if (i_device.DfunctionType == DeviceFunctionType.A鏈畾涔� + || i_device.DfunctionType == DeviceFunctionType.A涓嶆寚瀹�) { return false; } @@ -2230,6 +2575,30 @@ { var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); if (myInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) + { + return false; + } + } + else if (i_device.Type == DeviceType.FreshAirHumiditySensor) + { + //鏂伴鐨勬箍搴︿紶鎰熷櫒涓嶆樉绀� + 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 }); + if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment) + { + return false; + } + else if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction) + { + if (i_device.Type != DeviceType.OnOffOutput) { return false; } @@ -2245,6 +2614,16 @@ public bool IsHdlDevice(CommonDevice device) { return device.ManufacturerName == "HDL"; + } + + /// <summary> + /// 鏄惁鏄疢ini澶滅伅 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool IsMiniLight(CommonDevice device) + { + return device.DriveCode != 0 && device.Type == DeviceType.ColorTemperatureLight; } /// <summary> @@ -2285,22 +2664,42 @@ } /// <summary> + /// 鑾峰彇妯″潡ID鎵�鎸囧悜鐨勫悇绉嶅悕瀛椾俊鎭� + /// </summary> + /// <param name="strKey"></param> + /// <returns></returns> + public DeviceNameContent GetDeviceModelIdNameInfo(string strKey) + { + if (this.dicDeviceModelIdEnum.ContainsKey(strKey) == false) + { + return new DeviceNameContent(); + } + return this.dicDeviceModelIdEnum[strKey]; + } + + /// <summary> /// 闄勫姞璁惧鐨勭増鏈唬鍙�(杩斿洖Ver.XXX) /// </summary> /// <param name="versionValue">鐗堟湰鍙�</param> /// <returns></returns> public string AppendVersion(int versionValue) { + //10101 3涓猙yte 鏄剧ず涓猴細ver.1.01.01 + //涓棿閭d釜byte涓哄鏁版椂锛屼唬琛ㄦ槸娴嬭瘯鐗堟湰,鍦ㄦ樉绀烘渶鏂扮増鏈椂,涓嶉渶瑕佹樉绀猴紝浣嗘槸鍦ㄥ巻鍙茬増鏈偅閲屽彲浠ユ樉绀� + //涓棿閭d釜byte涓哄伓鏁版椂, 浠h〃鏄寮忕増鏈� + //鐩存帴鏄�10杩涘埗 - string txt10 = Convert.ToString(versionValue).PadLeft(4, '0'); - //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫�� - int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2)); - //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫�� - int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2)); + string txt10 = Convert.ToString(versionValue).PadLeft(6, '0'); + //杩欎釜鏄涓�浣� + int value1 = Convert.ToInt32(txt10.Substring(0, 2)); + //杩欎釜鏄浜屼綅 + string value2 = txt10.Substring(2, 2); + //杩欎釜鏄涓変綅 + string value3 = txt10.Substring(4, 2); //Ver. string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); - return ver + value1 + "." + value2.ToString().PadLeft(2, '0'); + return ver + value1 + "." + value2 + "." + value3; } /// <summary> @@ -2309,9 +2708,9 @@ /// <param name="msg"></param> private void ShowErrorMsg(string msg) { - Application.RunOnMainThread(() => + HdlThreadLogic.Current.RunMain(() => { - var contr = new ShowMsgControl(ShowMsgType.Error, msg); + var contr = new ShowMsgControl(Phone.ShowMsgType.Error, msg); contr.Show(); }); } @@ -2322,9 +2721,9 @@ /// <param name="msg"></param> private void ShowTipMsg(string msg) { - Application.RunOnMainThread(() => + HdlThreadLogic.Current.RunMain(() => { - var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + var contr = new ShowMsgControl(Phone.ShowMsgType.Tip, msg); contr.Show(); }); } @@ -2336,168 +2735,300 @@ #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="ignoreTime">鏄惁鏃犺鏃堕棿(姝ゅ彉閲忔槸缁欒幏鍙栧湪绾跨姸鎬佺敤鐨�),true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param> + /// <param name="useLocalConnect">鏄惁浣跨敤鏈湴杩炴帴鍙戦��</param> /// <param name="mode">鏄惁鏄剧ず閿欒</param> /// <returns></returns> - public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, ShowErrorMode mode = ShowErrorMode.YES) + public List<CommonDevice> GetDeviceListFromGateway(string gatewayId, ref int statu, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES) { - if (ignoreTime == false) - { - if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000) - { - //涓嶆棤瑙嗘椂闂�,杩斿洖鏈湴璁惧鍒楄〃 - statu = 1; - return this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway)); - } - } - zbGateway.LastDateTime = DateTime.Now; - - //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭� - 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 = HdlGatewayLogic.Current.GetGatewayId(zbGateway); //瓒呮椂鏃堕棿 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); - } + //閲嶆柊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 } }; - realWay.Send("GetDeviceInfo", 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) + //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯,鍒欓噰鐢ㄦ寜搴忓彿鑾峰彇璁惧 + statu = this.GetDeviceListFromGatewayByMac(gatewayId, ref listDevice, ref listFucDevice, dicMacPointCount, useLocalConnect); + if (statu == 2) + { + //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯 + string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); + this.ShowTipMsg(msg); + } + } + else + { + if (mode == ShowErrorMode.YES) { //鑾峰彇璁惧鍒楄〃澶辫触 //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇� string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); - msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]"; + 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 - { - if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) - { - //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯 - string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); - this.ShowTipMsg(msg); - } - statu = 2; - } } else { statu = 1; } + if (listFucDevice.Count > 0) + { + //濡傛灉瀛樺湪闇�瑕佸彉鏇寸殑鍔熻兘绫诲瀷 + HdlThreadLogic.Current.RunThread(() => + { + for (int i = 0; i < listFucDevice.Count; i++) + { + this.SendDeviceFunctionTypeToGateway(listFucDevice[i], listFucDevice[i].DfunctionType); + System.Threading.Thread.Sleep(100); + } + }); + } + 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 @@ -2505,18 +3036,16 @@ #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________ /// <summary> - /// 鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + /// 鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚�(鏁版嵁鍦―eviceInfo涓�) /// </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 = HdlGatewayLogic.Current.GetGatewayId(zbGateway); - //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType); + CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType, jobject.Value<int>("Epoint")); if (device == null) { return null; @@ -2528,15 +3057,10 @@ { return null; } - this.SetMacName(device, string.Empty); - this.SetEpointName(device, string.Empty); //璁剧疆璁惧涓婚敭绫� this.SetNewDeviceMainKeys(device, jobject); - device.CurrentGateWayId = gwId; - - //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - this.SetDeviceInfoToMain(device, device); + device.CurrentGateWayId = gwid; return device; } @@ -2548,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; @@ -2563,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; @@ -2576,11 +3095,20 @@ mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier; //搴忓垪鍙� mainDevice.SerialNumber = device.DeviceInfo.ProductCode; + //璁惧鍔熻兘绫诲瀷 + mainDevice.DfunctionType = (DeviceFunctionType)device.DeviceInfo.FunctionType; + if (mainDevice.DfunctionType == DeviceFunctionType.A涓嶆寚瀹�) + { + //寮忔牱鍙樻洿:鍔熻兘绫诲瀷涓嶅厑璁搁�夋嫨涓虹┖ 缃戝叧榛樿鐨凢unctionType涓�0 + mainDevice.DfunctionType = DeviceFunctionType.A鏈畾涔�; + } mainDevice.InClusterList.Clear(); 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) @@ -2598,82 +3126,22 @@ } } } - //濡傛灉鏄皟鍏夊櫒 - else if (mainDevice.Type == DeviceType.DimmableLight) - { - mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; - if (mainDevice.IsCustomizeImage == false) - { - mainDevice.IconPath = "Device/Light.png"; - } - } - //濡傛灉鏄笁璺户鐢靛櫒鐨勫洖璺殑璇�,榛樿涓虹伅鍏� - else if (mainDevice.Type == DeviceType.OnOffOutput) - { - //2020.05.13鍙樻洿:缁х數鍣ㄩ兘榛樿涓虹伅鍏� - //var myType = this.GetHdlMyDeviceEnumInfo(mainDevice); - //if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad) - { - if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�) - { - mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; - } - if (mainDevice.IsCustomizeImage == false) - { - mainDevice.IconPath = "Device/Light.png"; - } - } - } - //濡傛灉鏄┖姘斿紑鍏崇殑璇� - else if (mainDevice.Type == DeviceType.AirSwitch) - { - //绌烘皵寮�鍏抽粯璁や负寮�鍏� - if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�) - { - mainDevice.DfunctionType = DeviceFunctionType.A寮�鍏�; - } - if (mainDevice.IsCustomizeImage == false) - { - mainDevice.IconPath = "Device/Switch.png"; - } - } - //濡傛灉鏄僵鐏殑璇� - else if (mainDevice.Type == DeviceType.ColorDimmableLight) - { - mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; - if (mainDevice.IsCustomizeImage == false) - { - mainDevice.IconPath = "Device/ColorLight.png"; - } - } } /// <summary> /// 鏍规嵁璁惧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.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.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.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; @@ -2696,6 +3164,139 @@ #endregion + #region 鈻� 鍒锋柊璁惧鍔熻兘绫诲瀷___________________ + + /// <summary> + /// 鍒锋柊璁惧鐨勫姛鑳界被鍨�,濡傛灉杩斿洖true,浠h〃闇�瑕佸彟澶栬皟鐢ㄣ�怱endDeviceFunctionTypeToGateway銆戝嚱鏁�,sendFucType涓簍rue鏃惰嚜鍔ㄨ皟鐢� + /// </summary> + /// <param name="mainDevice">涓昏澶囧璞�</param> + /// <param name="device">璁剧疆婧愯澶囧璞�</param> + /// <param name="sendFucType">褰撻渶瑕佸彉鏇存椂,鏄惁鍙戦�佸姛鑳界被鍨嬪埌缃戝叧(姝ゅ彉閲忕粰鑾峰彇璁惧鍒楄〃鏈夌壒娈婂惈涔�)</param> + public bool RefreshDeviceFunctionType(CommonDevice mainDevice, CommonDevice device, bool sendFucType) + { + //濡傛灉鏄皟鍏夊櫒 + if (mainDevice.Type == DeviceType.DimmableLight) + { + if (mainDevice.IsCustomizeImage == false) + { + mainDevice.IconPath = "Device/Light.png"; + } + mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; + if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜) + { + //璋冨厜鍣ㄥ浐瀹氱伅鍏� + if (sendFucType == true) + { + this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜); + } + return true; + } + } + //濡傛灉鏄壊娓╃伅 + else if (mainDevice.Type == DeviceType.ColorTemperatureLight) + { + if (mainDevice.IsCustomizeImage == false) + { + mainDevice.IconPath = "Device/ColorLightTemperature.png"; + } + mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; + if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜) + { + //鑹叉俯鐏浐瀹氱伅鍏� + if (sendFucType == true) + { + this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜); + } + return true; + } + } + //濡傛灉鏄笁璺户鐢靛櫒鐨勫洖璺殑璇�,榛樿涓虹伅鍏� + else if (mainDevice.Type == DeviceType.OnOffOutput) + { + //鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣 + this.ResetIconPathByDeviceFunctionType(mainDevice); + //2020.05.13鍙樻洿:缁х數鍣ㄩ兘榛樿涓虹伅鍏� + if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�) + { + mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; + if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜) + { + //缁х數鍣ㄩ粯璁や负鐏厜 + if (sendFucType == true) + { + this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A鐏厜); + } + return true; + } + } + } + //濡傛灉鏄┖姘斿紑鍏崇殑璇� + else if (mainDevice.Type == DeviceType.AirSwitch) + { + //鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣 + this.ResetIconPathByDeviceFunctionType(mainDevice); + //绌烘皵寮�鍏抽粯璁や负寮�鍏� + if (mainDevice.DfunctionType == DeviceFunctionType.A鏈畾涔�) + { + mainDevice.DfunctionType = DeviceFunctionType.A寮�鍏�; + if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A寮�鍏�) + { + //绌烘皵寮�鍏抽粯璁や负寮�鍏� + if (sendFucType == true) + { + this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A寮�鍏�); + } + return true; + } + } + } + //濡傛灉鏄僵鐏殑璇� + else if (mainDevice.Type == DeviceType.ColorDimmableLight) + { + if (mainDevice.IsCustomizeImage == false) + { + mainDevice.IconPath = "Device/ColorLight.png"; + } + mainDevice.DfunctionType = DeviceFunctionType.A鐏厜; + if (device.DeviceInfo != null && device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A鐏厜) + { + //褰╃伅榛樿涓哄紑鍏� + if (sendFucType == true) + { + this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A寮�鍏�); + } + return true; + } + } + return false; + } + + /// <summary> + /// 鏍规嵁鍔熻兘绫诲瀷,閲嶆柊璁剧疆璁惧鍥炶矾鍥炬爣 + /// </summary> + /// <param name="device"></param> + private void ResetIconPathByDeviceFunctionType(CommonDevice device) + { + if (device.IsCustomizeImage == true) + { + return; + } + if (device.DfunctionType == DeviceFunctionType.A寮�鍏�) + { + device.IconPath = "Device/Switch.png"; + } + else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇) + { + device.IconPath = "Device/Socket1.png"; + } + else + { + device.IconPath = "Device/Light.png"; + } + } + + #endregion + //----------------------------------鍒嗗壊绾�(璁惧妯″潡ID)--------------------------------------------- #region 鈻� 鑷畾涔夎澶囨ā鍧桰D___________________ @@ -2705,104 +3306,49 @@ /// </summary> private void InitDeviceModelIdEnum() { + //********************************************************************* + //鏂拌澶囨坊鍔犳柟娉曪細 + //1銆佸湪鏈�涓嬮潰娣诲姞 DeviceConcreteType 锛岀劧鍚庢槸 DeviceBeloneType + //2銆佷互璁惧鐨勫叿浣撶被鍨嬩负鍚嶅瓧DeviceConcreteType(鍘绘帀銆�-銆�)娣诲姞璁惧鐨勩�愭墍灞炲浘鐗囥�戯紝銆愮湡瀹炵墿鐞嗗浘鐗囥�戙�傚洖璺浘鐗囬渶瑕佺壒娈婂鐞� + //3銆佸鏋滈渶瑕佸叡鏈夊浘鐗�,鍒欏湪杩欎釜鍑芥暟鐨勬渶搴曚笅娣诲姞 + //4銆佹樉绀虹殑妯″潡ID闇�瑕佷氦鎹㈢殑璇�,鍒欏湪杩欎釜鍑芥暟鐨勬渶搴曚笅娣诲姞 + //********************************************************************* + if (this.dicDeviceModelIdEnum != null) { return; } - this.dicDeviceModelIdEnum = new Dictionary<string, string>(); + this.dicDeviceModelIdEnum = new Dictionary<string, DeviceNameContent>(); - //********************************************************************* - //鏂拌澶囨坊鍔犳柟娉曪細 - //1銆佸湪杩欓噷濉啓涓婃ā鍧桰D锛岀劧鍚庢槸 DeviceConcreteType 锛岀劧鍚庢槸 DeviceBeloneType , 鐒跺悗鏄� 璁惧绫诲瀷鐨勭炕璇慖D - //2銆佺劧鍚庡湪鏈�涓嬮潰鐨勩�愯嚜瀹氫箟璁惧绫诲瀷銆戞姌鍙犳爮閲屾坊鍔犮�愯澶囩殑鍏蜂綋绫诲瀷銆戯紝銆愯澶囩殑鎵�灞炵被鍨嬨�� - //3銆佷互璁惧鐨勫叿浣撶被鍨嬩负鍚嶅瓧(鍘绘帀銆�-銆�)娣诲姞璁惧鐨勩�愭墍灞炲浘鐗囥�戯紝銆愮湡瀹炵墿鐞嗗浘鐗囥�戙�傚洖璺浘鐗囬渶瑕佺壒娈婂鐞� - //4銆佹坊鍔燫鏂囦欢(uDeviceModelId),娣诲姞Language鏂囦欢 - //5銆佸鏋滈渶瑕佸叡鏈夊浘鐗�,鍒欏湪杩欎釜鍑芥暟鐨勬渶搴曚笅娣诲姞 - //********************************************************************* - - //鍓嶈█锛氬洜涓簔igbeehome鐨勮澶囨嫢鏈夊洓绉嶅悕瀛楋細 - //1銆佽澶囧畼鏂瑰悕绉� ----瀹冪敱DeviceConcreteType鐨勬暟鍊兼墍鍐冲畾(涓汉涓績涓撶敤) - //2銆佽澶囧叆缃戝悗鐨勯粯璁ゅ悕绉� ----瀹冧笉闇�瑕佸湪浠g爜閲岄潰瀹氫箟,瀹冪洿鎺ュ湪Language鏂囦欢閲岄潰瀹氫箟 - // 鑼冨洿锛�50000寮�濮�,瀹冪殑瑙勫垯鏄疍eviceConcreteType瀵瑰簲鐨凴鏂囦欢閲岄潰鐨処D鐨勬暟鍊�+20000, - //3銆佽澶囨墍灞炲悕绉� ----瀹冩湁DeviceBeloneType鐨勬暟鍊兼墍鍐冲畾 - //4銆佽澶囩被鍨嬪悕绉� ----瀹冪敱銆愯澶囩被鍨嬬殑缈昏瘧ID銆戞墍鍐冲畾,杩欎釜鍊兼槸涓汉涓績涓撶敤, - // 瀹冩槸Language鏂囦欢閲岄潰鐨� 60000涔嬪悗鐨勯偅浜涘�� - - //瀹氫箟瑙勫垯锛氭ā鍧桰D(宸茬炕璇�) = 璁惧鍏蜂綋绫诲瀷鍊� - 璁惧鎵�灞炵被鍨嬪�� - 璁惧绫诲瀷鐨勭炕璇慖D - //璁惧鍏蜂綋绫诲瀷鍊硷細DeviceConcreteType(鍦ㄨ繖涓枃浠舵渶涓嬮潰杩涜瀹氫箟) - //璁惧鎵�灞炵被鍨嬪��: DeviceBeloneType(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互,鍦ㄨ繖涓枃浠舵渶涓嬮潰杩涜瀹氫箟) - //璁惧绫诲瀷鐨勭炕璇慖D:杩欎釜鍊兼槸涓汉涓績涓撶敤,瀹冩槸Language鏂囦欢閲岄潰鐨� 60000涔嬪悗鐨勯偅浜涘�� - - //=========鈽呪槄寮�鍚堝笜绫�(100-199)鈽呪槄========= - this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100-60002";//鏅鸿兘寮�鍚堝笜鐢垫満 - this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100-60002";//鏅鸿兘绠$姸鐢垫満 - - //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄========= - this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200-60003";//4鎸夐敭瑙︽懜闈㈡澘(甯�4璺户鐢靛櫒搴曞骇) - this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200-60003";//3鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200-60003";//2鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200-60003";//12鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200-60003";//4鎸夐敭瑙︽懜闈㈡澘(鍙甫鐢垫簮搴曞骇) - this.dicDeviceModelIdEnum["MPT4R4L/S-ZB.18"] = "220-200-60003";//绠�绾�4鎸夐敭闈㈡澘 - this.dicDeviceModelIdEnum["MPT3R3L/S-ZB.18"] = "221-200-60003";//绠�绾�3鎸夐敭闈㈡澘 - this.dicDeviceModelIdEnum["MPT2R2L/S-ZB.18"] = "222-200-60003";//绠�绾�2鎸夐敭闈㈡澘 - this.dicDeviceModelIdEnum["MPT4SC/S-ZB.18"] = "224-200-60003";//绠�绾�4鎸夐敭鍦烘櫙闈㈡澘 - this.dicDeviceModelIdEnum["MPT2W/S-ZB.18"] = "226-200-60003";//绠�绾�2璺獥甯橀潰鏉� - this.dicDeviceModelIdEnum["MP2B/TILE-ZB.18"] = "240-200-60003";//鏂规偊鍗曞紑鍙屾帶闈㈡澘 - this.dicDeviceModelIdEnum["MP4B/TILE-ZB.18"] = "241-200-60003";//鏂规偊鍙屽紑鍥涙帶闈㈡澘 - this.dicDeviceModelIdEnum["MP8B/TILE-ZB.18"] = "242-200-60003";//鏂规偊鍥涘紑鍏帶闈㈡澘 - this.dicDeviceModelIdEnum["MPFA/TILE-ZB.18"] = "250-200-60003";//鏂规偊鏂伴闈㈡澘 - this.dicDeviceModelIdEnum["MPTE3/TILE-ZB.18"] = "253-200-60003";//鏂规偊鐜闈㈡澘 - this.dicDeviceModelIdEnum["MP2W/TILE-ZB.18"] = "256-200-60003";//绐楀笜闈㈡澘 - - //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= - this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir浼犳劅鍣�220 - - //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄========= - //杩欓噷鏄害涔愬厠鐨� - this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1200-60000";//鐕冩皵浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1200-60000";//闂ㄧ獥纾佷紶鎰熷櫒 - this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1200-60000";//鐑熼浘浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1200-60000";//绾㈠浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1200-60000";//姘存蹈浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1200-60000";//绱ф�ユ寜閿� - //杩欓噷鏄渤涓滅殑 - this.dicDeviceModelIdEnum["MSG01/M-ZB.10"] = "1300-1200-60000";//鐕冩皵浼犳劅鍣� - this.dicDeviceModelIdEnum["MSDC01/M-ZB.10"] = "1301-1200-60000";//闂ㄧ獥纾佷紶鎰熷櫒 - this.dicDeviceModelIdEnum["MSS01/M-ZB.10"] = "1302-1200-60000";//鐑熼浘浼犳劅鍣� - this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1200-60000";//绾㈠浼犳劅鍣� - this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1200-60000";//姘存蹈浼犳劅鍣� - this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1200-60000";//绱ф�ユ寜閿� - this.dicDeviceModelIdEnum["MGCD01/ZB.10"] = "1306-1200-60000";//鍚搁《鐕冩皵浼犳劅鍣� - - //PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� 銆愯璁惧灞炰簬绗笁鏂硅澶囷紝娌℃湁闀滃儚ID銆� - this.dicDeviceModelIdEnum["SZ_PM100"] = "1307-1200-60000";//PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� - - //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄========= - this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300-60001";//3璺户鐢靛櫒灏忔ā鍧� - this.dicDeviceModelIdEnum["MFA01-ZB.10"] = "2310-2300-60011";//鏂规偊鏂伴灏忔ā鍧� - - //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄========= - this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500-60007";//1璺皟鍏夊櫒灏忔ā鍧� - - //=========鈽呪槄鏅鸿兘闂ㄩ攣绫�(2800-????)鈽呪槄========= - this.dicDeviceModelIdEnum["H06C"] = "2800-2800-60010";//鏅鸿兘闂ㄩ攣(H06C) - this.dicDeviceModelIdEnum["S-one"] = "2802-2800-60010";//鏅鸿兘闂ㄩ攣(S-one) - - //=========鈽呪槄绌鸿皟绫�(3600-3899)鈽呪槄========= - this.dicDeviceModelIdEnum["MAC/GW-ZB.10"] = "3600-3600-60009";//zigbee绌鸿皟缃戝叧妯″潡 - - //=========鈽呪槄涓户鍣ㄧ被(3900-3999)鈽呪槄========= - this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900-60006"; //zigbee涓户鍣� - - //=========鈽呪槄绌烘皵寮�鍏崇被(4100-4199)鈽呪槄========= - this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100-60001";//zigbee寰柇浜戞帶鍒跺櫒 - - //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄========= - this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200-60008";//zigbee杞琤uspro鍗忚杞崲鍣� - this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200-60008";//zigbee杞�485鍗忚杞崲鍣� - - + var listText = this.GetDeviceNameFileContent(); + foreach (var dataText in listText) + { + if (dataText == string.Empty || dataText.StartsWith(";") == true) + { + //杩欐槸娉ㄩ噴 + continue; + } + string[] strArry1 = dataText.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries); + if (strArry1.Length != 2) + { + //闈炴硶璁剧疆 + continue; + } + string[] strArry2 = strArry1[1].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); + if (strArry2.Length < 6) + { + //闈炴硶璁剧疆 + continue; + } + var content = new DeviceNameContent(); + 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.A鎵�灞炲悕瀛� = strArry2[4].Trim(); + content.A绫诲瀷鍚嶅瓧 = strArry2[5].Trim(); + this.dicDeviceModelIdEnum[strArry1[0].Trim()] = content; + } //鉁┾湬鉁┾湬鉁╅渶瑕佷氦鎹㈢殑妯″潡ID鉁┾湬鉁┾湬鉁� this.dicDeviceModelIdChanged = new Dictionary<string, string>(); @@ -2814,8 +3360,6 @@ this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//姘存蹈浼犳劅鍣� this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//绱ф�ユ寜閿� - - //鉁┾湬鉁┾湬鉁╅渶瑕佸叡鏈夌殑鍥剧墖瀵硅薄鉁┾湬鉁┾湬鉁� //涓よ�呴兘鏄疍eviceConcreteType //Keys:鎸囧畾鐨勮澶� value:娌跨敤鐨勫浘鐗囨槸鍝璁惧鐨� @@ -2825,6 +3369,55 @@ 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> + /// 鑾峰彇璁惧鍚嶅瓧鏂囦欢鐨勫唴瀹� + /// </summary> + /// <returns></returns> + private List<string> GetDeviceNameFileContent() + { + System.IO.StreamReader streamReader = null; + var listText = new List<string>(); + try + { +#if iOS + string textFile = Foundation.NSBundle.MainBundle.PathForResource("DeviceName.ini", null); + streamReader = new System.IO.StreamReader(textFile, Encoding.UTF8); + string text; + while ((text = streamReader.ReadLine()) != null) + { + listText.Add(text.Trim()); + } + return listText; +#endif +#if Android + var stream = Application.Activity.Assets.Open("DeviceName.ini"); + streamReader = new System.IO.StreamReader(stream, Encoding.UTF8); + string text; + while ((text = streamReader.ReadLine()) != null) + { + listText.Add(text.Trim()); + } + stream.Close(); + return listText; +#endif + } + catch + { + return listText; + } + finally + { + try + { + streamReader?.Close(); + } + catch + { + } + } } #endregion @@ -2833,13 +3426,10 @@ #region 鈻� 鑷畾涔夎澶囩被鍨媉________________________ /// <summary> - /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囩殑鍏蜂綋銆愯澶囩被鍨嬨��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceConcreteType鍊�)</para> - /// <para>鍙橀噺鍚嶅彲浠ヤ綔涓恒�愯澶囩被鍨嬨�戝浘鐗�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> + /// <para>璁惧鐨勫叿浣撱�愯澶囩被鍨嬨��,鍙橀噺鍚嶅彲浠ヤ綔涓恒�愯澶囩被鍨嬨�戝浘鐗�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> /// </summary> public enum DeviceConcreteType { - //瀹氫箟瑙勫垯锛氥�愯澶囩被鍨嬨�戝浘鐗囧悕瀛�=LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceConcreteType鍊� - /// <summary> /// 鏈煡璁惧 /// </summary> @@ -2928,6 +3518,14 @@ /// 绐楀笜闈㈡澘 闀滃儚id锛�256 /// </summary> ButtonPanel_Curtain = 256, + /// <summary> + /// 绠�绾﹀鍔熻兘闈㈡澘 闀滃儚ID锛�212 + /// </summary> + ButtonPanel_SimpleMultifunction = 212, + /// <summary> + /// 绠�绾︾幆澧冮潰鏉� + /// </summary> + ButtonPanel_SimpleEnvironment = 230, //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= /// <summary> @@ -2938,6 +3536,10 @@ /// pir浼犳劅鍣�220 闀滃儚id锛�1200 /// </summary> Sensor_Pir = 1200, + /// <summary> + /// 鐞冨舰绉诲姩浼犳劅鍣� 闀滃儚id锛�1205 + /// </summary> + Sensor_SphericalMotion = 1205, //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄========= /// <summary> @@ -2972,6 +3574,10 @@ /// PM2.5绌烘皵璐ㄩ噺浼犳劅鍣� /// </summary> Sensor_PMTwoPointFive = 1307, + /// <summary> + /// 娓╂箍搴︿紶鎰熷櫒(杩欎釜鍗曡瘝鎷奸敊浜�,浣嗘槸閿欎簡灏遍敊浜嗗憲,灏辫繖鏍蜂簡) + /// </summary> + Sensor_TemperatureHumidity = 1308, /// <summary> /// 杩愬姩浼犳劅鍣� @@ -2982,11 +3588,7 @@ /// </summary> Sensor_Keyfob = -1307, /// <summary> - /// 娓╂箍搴︿紶鎰熷櫒 - /// </summary> - Sensor_TemperatureHumidity = -1308, - /// <summary> - /// 娓╁害浼犳劅鍣� + /// 娓╁害浼犳劅鍣�(杩欎釜鍗曡瘝鎷奸敊浜�,浣嗘槸閿欎簡灏遍敊浜嗗憲,灏辫繖鏍蜂簡) /// </summary> Sensor_Temperature = -1309, /// <summary> @@ -3007,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> /// 璋冨厜鍣� @@ -3037,6 +3651,10 @@ /// 褰╃伅 /// </summary> ColorLight = -10, + /// <summary> + /// 鑹叉俯鐏�(瀹冪殑闀滃儚ID鏈畾,鏆傚畾20000) + /// </summary> + ColorLight_Temperature = 20000, //=========鈽呪槄绌鸿皟(3600-3899)鈽呪槄========= /// <summary> @@ -3102,8 +3720,7 @@ } /// <summary> - /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囨墍灞炵殑銆愯澶囩绫汇��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceBeloneType鍊�)</para> - /// <para>杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> + /// <para>璁惧鎵�灞炴灇涓�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> /// </summary> public enum DeviceBeloneType { -- Gitblit v1.8.0