From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Common/Device.cs | 3009 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 3,009 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs new file mode 100755 index 0000000..0f8e7c2 --- /dev/null +++ b/ZigbeeApp/Shared/Common/Device.cs @@ -0,0 +1,3009 @@ +锘縰sing Shared.Phone.UserCenter; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using ZigBee.Device; + +namespace Shared.Common +{ + /// <summary> + /// 鏈湴璁惧 + /// </summary> + public class LocalDevice + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鏈湴璁惧 + /// </summary> + private static LocalDevice m_Current = null; + /// <summary> + /// 鏈湴璁惧 + /// </summary> + public static LocalDevice Current + { + get + { + if (m_Current == null) + { + m_Current = new LocalDevice(); + } + return m_Current; + } + set + { + m_Current = value; + } + } + /// <summary> + /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨 + /// </summary> + public List<CommonDevice> listAllDevice + { + get + { + lock (dicAllDevice) + { + //鍏堣幏鍙栧叏閮ㄧ殑Mac + var listMac = new List<string>(); + foreach (var strMac in this.dicDeviceEpoint.Keys) + { + listMac.Add(strMac); + } + //鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(寮哄埗鎺掑簭) + return this.GetDevicesByMac(listMac); + } + } + } + + /// <summary> + /// R鏂囦欢閲岄潰璁惧妯″潡ID鐨勭炕璇戝悕瀛楃殑鍓嶇紑 + /// </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; + /// <summary> + /// 闇�瑕佽浆鎹㈢殑璁惧鐨勬ā鍧桰D(keys:鏃фā鍧桰D,value:鏂版ā鍧桰D) + /// </summary> + private Dictionary<string, string> dicDeviceModelIdChanged = null; + /// <summary> + /// 鍥剧墖鍏辨湁(keys:鎸囧畾璁惧鐨勫叿浣撶被鍨� value:鎸囧畾鍏辨湁瀵硅薄鐨勫叿浣撶被鍨�) + /// </summary> + private Dictionary<string, string> dicPictrueShard = null; + /// <summary> + /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(闈炲叕寮�) + /// </summary> + private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>(); + /// <summary> + /// 鏈湴鎵�鏈夌殑椤剁偣鍗囩骇璁惧(闈炲叕寮�锛屼富閿槸MAC+200绔彛) + /// </summary> + private Dictionary<string, OTADevice> dicOTADevice = new Dictionary<string, OTADevice>(); + /// <summary> + /// 璁惧鐨勬�诲洖璺�(keys:Mac鍦板潃 value:鍏ㄩ儴绔彛鍙�) + /// </summary> + private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>(); + /// <summary> + /// 鐗╃悊璁惧灞炰簬鍝釜鎴块棿鐨勮褰� + /// </summary> + private Dictionary<string, string> dicDeviceRoomId = null; + + #endregion + + #region 鈻� 鍒锋柊璁惧___________________________ + + /// <summary> + /// 鍒锋柊鏈湴璁惧淇℃伅 + /// </summary> + public void ReFreshByLocal() + { + this.dicAllDevice.Clear(); + this.dicDeviceEpoint.Clear(); + + //鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D + this.InitDeviceDefultNameIDList(); + + //鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� + List<string> listFile = this.GetAllDeviceFile(); + foreach (string file in listFile) + { + CommonDevice device = null; + //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞� + try + { + device = CommonDevice.CommonDeviceByFilePath(file); + } + 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; + } + //濡傛灉杩欎釜璁惧鐨勭綉鍏矷D涓嶅瓨鍦ㄧ殑璇� + if (HdlGatewayLogic.Current.IsGatewayExist(device.CurrentGateWayId) == false) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //濡傛灉浠栨槸鎴愬憳鐨勮瘽,甯粬鏂板缓涓�涓綉鍏� + HdlGatewayLogic.Current.AddVirtualGateway(device.CurrentGateWayId); + } + 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; + } + } + + string mainKey = this.GetDeviceMainKeys(device); + if (device is OTADevice) + { + //200绔彛涓嶉渶瑕佸鐞� + this.dicOTADevice[mainKey] = (OTADevice)device; + continue; + } + //娣诲姞缂撳瓨 + this.dicAllDevice[mainKey] = device; + + //鍥炶矾鏀堕泦 + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false) + { + this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>(); + } + this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint); + + //妫�娴婾i鍥剧墖鏄惁姝g‘,杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true) + { + //涓嶅瓨鍦ㄧ殑璇濓紝閲嶆柊鐢熸垚 + device.IconPath = string.Empty; + device.ReSave(); + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + } + //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 + this.DeleteGatewayFileByMemberModel(); + //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍 + this.InitRealDeviceRoomId(); + } + + /// <summary> + /// 鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 + /// </summary> + private void DeleteGatewayFileByMemberModel() + { + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + return; + } + var listId = new HashSet<string>(); + + lock (dicAllDevice) + { + foreach (var device in this.dicAllDevice.Values) + { + if (listId.Contains(device.CurrentGateWayId) == false) + { + listId.Add(device.CurrentGateWayId); + } + } + } + var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway(); + foreach (var gateway in listGateway) + { + string gwId = HdlGatewayLogic.Current.GetGatewayId(gateway); + if (listId.Contains(gwId) == false) + { + //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑 + HdlGatewayLogic.Current.DeleteGatewayFile(gwId); + } + } + } + + #endregion + + #region 鈻� 娣诲姞璁惧___________________________ + + /// <summary> + /// <para>灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚)</para> + /// <para>-1:寮傚父 1:姝e父 2:璁惧淇℃伅缂烘崯</para> + /// </summary> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway) + { + //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧 + int statu = 0; + List<CommonDevice> listDevice = new List<CommonDevice>(); + List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, true); + if (list == null) + { + return -1; + } + listDevice.AddRange(list); + + //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶� + string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID); + //鑾峰彇ota璁惧 + foreach (var ota in this.dicOTADevice.Values) + { + if (ota.CurrentGateWayId == gwID) + { + listLocalDevices.Add(ota); + } + } + + Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>(); + foreach (var device in listLocalDevices) + { + string maikey = this.GetDeviceMainKeys(device); + dicExist[maikey] = device; + } + + //娣诲姞璁惧鐨勭紦瀛� + for (int i = 0; i < listDevice.Count; i++) + { + var device = listDevice[i]; + if (device == null || device.DeviceAddr == null) + { + continue; + } + //娣诲姞缂撳瓨 + this.AddDeviceToMemory(ref device); + + //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� + string maikey = this.GetDeviceMainKeys(device); + if (dicExist.ContainsKey(maikey) == true) + { + dicExist.Remove(maikey); + } + //鑾峰彇璁惧鐨勫浐瀹氬睘鎬� + HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device); + } + + for (int i = 0; i < listDevice.Count; i++) + { + var device = listDevice[i]; + //瀵规湭鍛藉悕鐨勮櫄鎷熻澶囬噸鏂板懡鍚� + 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); + }); + } + } + + //鍙湁瀹屽叏鑾峰彇鐨勬椂鍊�,鎵嶄細鍘诲鐞嗗垹闄ょ殑闂 + if (statu != 1) + { + return statu; + } + + //濡傛灉鏈湴鍜岀綉鍏崇殑璁惧涓嶄竴鑷寸殑鏃跺�欙紝鍒犻櫎鏈湴鐨勮澶� + var listDeleteMac = new List<string>(); + foreach (var device in dicExist.Values) + { + if (device is OTADevice) + { + this.DeleteMemmoryOtaDevice(device.DeviceAddr); + } + else + { + this.DeleteMemmoryDevice(device, true); + } + if (listDeleteMac.Contains(device.DeviceAddr) == false) + { + //鏀堕泦琚垹闄ょ殑Mac + listDeleteMac.Add(device.DeviceAddr); + } + } + if (listDeleteMac.Count > 0) + { + //灏嗙湡瀹炵墿鐞嗚澶囦粠鎴块棿涓Щ闄� + this.DeleteRealDeviceFromRoom(listDeleteMac); + } + + return statu; + } + + /// <summary> + /// 娣诲姞璁惧鍒扮紦瀛�,瀛樺湪鏃惰鐩� + /// </summary> + /// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param> + public void AddDeviceToMemory(ref CommonDevice device) + { + string mainKeys = this.GetDeviceMainKeys(device); + //濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠� + if (device is OTADevice) + { + if (this.dicOTADevice.ContainsKey(mainKeys) == false) + { + this.dicOTADevice[mainKeys] = (OTADevice)device; + } + else + { + //浜ゆ崲灞炴�� + var tempDevice = this.dicOTADevice[mainKeys]; + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(tempDevice, device); + device = tempDevice; + } + + bool exists = Global.IsExistsByHomeId(device.FilePath); + device.ReSave(); + if (exists == false) + { + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + return; + } + + lock (dicAllDevice) + { + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + //浜ゆ崲灞炴�� + var tempDevice = this.dicAllDevice[mainKeys]; + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(tempDevice, device); + device = tempDevice; + } + else + { + this.dicAllDevice[mainKeys] = device; + } + } + + //璁惧鍥炶矾鏀堕泦 + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false) + { + this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>(); + } + if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false) + { + this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint); + } + + bool exists2 = Global.IsExistsByHomeId(device.FilePath); + device.ReSave(); + if (exists2 == false) + { + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + } + + #endregion + + #region 鈻� 淇敼璁惧___________________________ + + /// <summary> + /// 鏇存敼绔偣鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <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) + { + //鍏堝埆绠¢偅涔堝锛屾洿鏀瑰悕瀛楀悗锛屽埛鏂拌澶囩紦瀛� + this.SetEpointName(device, newName); + + this.BackupDeviceAfterReName(device); + + //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� + //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName); + if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) + { + //璁惧鍚嶇О淇敼澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + if (mode == ShowErrorMode.YES) + { + this.ShowErrorMsg(msg); + } + return false; + } + //澶囦唤鏁版嵁 + await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绔偣鍚嶇О, newName); + } + return true; + } + + /// <summary> + /// 鏇存敼Mac鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <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) + { + if (listDevice.Count == 0) + { + return true; + } + //鍏堝埆绠¢偅涔堝锛屽厛淇敼缂撳瓨 + for (int i = 0; i < listDevice.Count; i++) + { + var device2 = listDevice[i]; + //杩欎袱涓笢瑗垮緢鐗规畩 + this.SetMacName(device2, newMacName); + + //鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 + this.BackupDeviceAfterReName(device2); + } + + CommonDevice device = listDevice[0]; + //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� + //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + //淇敼鐗╃悊鍚嶅瓧 + var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName); + if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0) + { + //璁惧鍚嶇О淇敼澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + if (mode == ShowErrorMode.YES) + { + this.ShowErrorMsg(msg); + } + 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); + } + //濡傛灉瀹冩湁涓や釜绔偣鏃�,pir浼犳劅鍣ㄧ壒娈婂鐞� + else if (this.dicDeviceEpoint[device.DeviceAddr].Count == 2) + { + var myType = this.GetMyDeviceEnumInfo(listDevice); + if (myType.ConcreteType == DeviceConcreteType.Sensor_Pir) + { + foreach (var myDevice in listDevice) + { + if (myDevice.Type == DeviceType.IASZone) + { + return await this.ReName(myDevice, newMacName); + } + } + } + } + } + } + return true; + } + + /// <summary> + /// 鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 + /// </summary> + /// <param name="device"></param> + private void BackupDeviceAfterReName(CommonDevice device) + { + lock (dicAllDevice) + { + string mainKeys = this.GetDeviceMainKeys(device); + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + //涓�鑸澶� + this.dicAllDevice[mainKeys] = device; + device.ReSave(); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + else if (this.dicOTADevice.ContainsKey(mainKeys) == true) + { + //Ota璁惧 + this.dicOTADevice[mainKeys] = (OTADevice)device; + device.ReSave(); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + + } + } + } + + #endregion + + #region 鈻� 鍒犻櫎璁惧___________________________ + + /// <summary> + /// 鍒犻櫎璁惧骞朵笖鍒锋柊缂撳瓨(鍒犻櫎澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <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) + { + //璁惧鍒犻櫎澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + this.ShowErrorMsg(msg); + return false; + } + + //鍒犻櫎缂撳瓨鐨凮ta璁惧 + this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr); + //鍒犻櫎涓�鑸澶囨枃浠� + foreach (CommonDevice device in listdevice) + { + this.DeleteMemmoryDevice(device); + } + + if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true) + { + //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮� + this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr); + this.SaveRealDeviceRoomId(null, null); + } + return true; + } + + /// <summary> + /// 鍒犻櫎缂撳瓨鐨勪竴鑸澶� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="deleteRoom">鏄惁浠庢埧闂村垹闄�</param> + public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) + { + if (deleteRoom == true) + { + //浠庢埧闂翠腑鍒犻櫎 + HdlRoomLogic.Current.DeleteDevice(device); + //鍒犻櫎鎴戠殑鍠滅埍鐨勮澶� + HdlRoomLogic.Current.DeleteLoveDevice(device); + } + + //鍒犻櫎缂撳瓨 + string mainKeys = this.GetDeviceMainKeys(device); + lock (dicAllDevice) + { + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + this.dicAllDevice.Remove(mainKeys); + } + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true) + { + //鍙樻洿绔偣鏁� + this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint); + } + } + + //鍒犻櫎璁惧鏂囦欢 + string filePath = device.FilePath; + if (Global.IsExistsByHomeId(filePath) == true) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� + Global.DeleteFilebyHomeId(filePath); + } + else + { + //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� + Global.DeleteFilebyHomeId(filePath); + //鍒犻櫎鑷姩澶囦唤 + HdlAutoBackupLogic.DeleteFile(device.FilePath); + } + } + } + + /// <summary> + /// 鍒犻櫎缂撳瓨鐨凮ta璁惧 + /// </summary> + /// <param name="macAdrr"></param> + /// <param name="ePoint"></param> + public void DeleteMemmoryOtaDevice(string macAdrr, int ePoint = 200) + { + //鍒犻櫎200绔彛鏂囦欢 + string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint); + if (this.dicOTADevice.ContainsKey(otaKeys) == true) + { + string otaFile = this.dicOTADevice[otaKeys].FilePath; + if (Global.IsExistsByHomeId(otaFile) == true) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� + Global.DeleteFilebyHomeId(otaFile); + } + else + { + //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� + Global.DeleteFilebyHomeId(otaFile); + //鍒犻櫎鑷姩澶囦唤 + HdlAutoBackupLogic.DeleteFile(otaFile); + } + } + this.dicOTADevice.Remove(otaKeys); + } + } + + #endregion + + #region 鈻� 娴嬭瘯璁惧___________________________ + + /// <summary> + /// 鍙戦�佸畾浣嶆寚浠ゅ埌璁惧 + /// </summary> + /// <param name="device"></param> + public void SetFixedPositionCommand(CommonDevice device) + { + device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5); + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊畾浣嶇殑鍔熻兘 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool DeviceIsCanFixedPosition(CommonDevice device) + { + if (device.Type == DeviceType.DoorLock) + { + //闂ㄩ攣娌℃湁瀹氫綅鍔熻兘 + return false; + } + if (device.Type == DeviceType.IASZone) + { + var myTypeInfo = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_Pir) + { + //浼犳劅鍣ㄩ櫎浜哖ir閮芥病鏈夊畾浣嶅姛鑳� + return true; + } + return false; + } + + foreach (var data in device.InClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.InCluster == 3) + { + return true; + } + } + return false; + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳嚭绨�) + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool OutDeviceIsCanOnOff(CommonDevice device) + { + foreach (var data in device.OutClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.OutCluster == 6) + { + return true; + } + } + return false; + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳叆绨�) + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool InDeviceIsCanOnOff(CommonDevice device) + { + foreach (var data in device.InClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.InCluster == 6) + { + return true; + } + } + return false; + } + + #endregion + + #region 鈻� 鑾峰彇璁惧___________________________ + + /// <summary> + /// 鏍规嵁缃戝叧ID鑾峰彇鎵�鏈夌殑璁惧 + /// </summary> + /// <param name="gwId">缃戝叧ID</param>> + /// <returns></returns> + public List<CommonDevice> GetDeviceByGatewayID(string gwId) + { + lock (dicAllDevice) + { + var listMac = new List<string>(); + //鍚勭綉鍏崇殑鎵�鏈夎澶囩殑Mac + foreach (CommonDevice device in this.dicAllDevice.Values) + { + if (gwId == device.CurrentGateWayId) + { + listMac.Add(device.DeviceAddr); + } + } + return this.GetDevicesByMac(listMac); + } + } + + /// <summary> + /// 鑾峰彇鎸囧畾璁惧(涓婚敭鏄細Mac鍦板潃+绔彛鍙�),涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull + /// </summary> + /// <param name="mainKeys">Mac鍦板潃+绔彛鍙�</param> + /// <returns></returns> + public CommonDevice GetDevice(string mainKeys) + { + lock (dicAllDevice) + { + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + return this.dicAllDevice[mainKeys]; + } + } + return null; + } + + /// <summary> + /// 鑾峰彇鎸囧畾璁惧,涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <param name="DeviceEpoint">绔彛鍙�</param> + /// <returns></returns> + public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint) + { + string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint); + return this.GetDevice(mainkeys); + } + + /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞� + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <param name="sort">鏄惁鎺掑簭</param> + /// <returns></returns> + public List<CommonDevice> GetDevicesByMac(string DeviceAddr, bool sort = true) + { + var list = new List<CommonDevice>(); + if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false) + { + return list; + } + foreach (var point in dicDeviceEpoint[DeviceAddr]) + { + var device = this.GetDevice(DeviceAddr, point); + if (device != null) + { + list.Add(device); + } + } + 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> + /// <returns></returns> + public List<CommonDevice> GetDevicesByMac(List<string> listMacAddr) + { + //鍏堟帓搴� + listMacAddr.Sort(); + + var list = new List<CommonDevice>(); + foreach (string strMac in listMacAddr) + { + var listEpoint = new List<int>(); + //鑾峰彇鍏ㄩ儴鐨勭鐐� + foreach (int epoint in this.dicDeviceEpoint[strMac]) + { + listEpoint.Add(epoint); + } + //鐒跺悗鎺掑簭 + listEpoint.Sort(); + foreach (int epoint in listEpoint) + { + var device = this.GetDevice(strMac, epoint); + if (device != null) + { + list.Add(device); + } + } + } + return list; + } + + /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勬暟閲� + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <returns></returns> + public int GetDevicesCountByMac(string DeviceAddr) + { + if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false) + { + return 0; + } + return dicDeviceEpoint[DeviceAddr].Count; + } + + /// <summary> + /// 鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� + /// </summary> + /// <returns></returns> + public List<string> GetAllDeviceFile() + { + List<string> listDeviceFile = new List<string>(); + List<string> listAllFile = Global.FileListByHomeId(); + + foreach (string file in listAllFile) + { + if (file.StartsWith("Device_") == false) + { + //濡傛灉涓嶆槸璁惧鏂囦欢 + continue; + } + listDeviceFile.Add(file); + } + return listDeviceFile; + } + + /// <summary> + /// 鑾峰彇OTA璁惧(200绔彛鐨�) + /// </summary> + /// <param name="macAdrr"></param> + /// <param name="ePoint"></param> + /// <returns></returns> + public OTADevice GetOTADevice(string macAdrr, int ePoint = 200) + { + string mainkeys = this.GetDeviceMainKeys(macAdrr, ePoint); + if (this.dicOTADevice.ContainsKey(mainkeys) == false) + { + return null; + } + return this.dicOTADevice[mainkeys]; + } + + /// <summary> + /// 鑾峰彇鐗规畩鐨�,娌℃湁鍏朵粬鍥炶矾,鍗曠函鍙湁200绔偣鐨凮TA璁惧 + /// </summary> + /// <param name="gwId">缃戝叧ID</param> + /// <returns></returns> + public List<OTADevice> GetSpecialOtaDevice(string gwId) + { + var list = new List<OTADevice>(); + foreach (var ota in this.dicOTADevice.Values) + { + if (ota.CurrentGateWayId != gwId) + { + //涓嶆槸鍚屼竴涓綉鍏� + continue; + } + //娌℃湁鍏朵粬鍥炶矾 + if (dicDeviceEpoint.ContainsKey(ota.DeviceAddr) == false + || dicDeviceEpoint[ota.DeviceAddr].Count == 0) + { + //鐩墠鍙拡瀵逛腑澶┖璋� + if (ota.ModelIdentifier == "MAC/GW-ZB.10") + { + list.Add(ota); + } + } + } + return list; + } + + #endregion + + #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________ + + /// <summary> + /// 鑾峰彇璁惧绔偣鐨勫悕绉�(鏈夌壒鏁�) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetDeviceEpointName(CommonDevice device) + { + string dName = this.GetSimpleEpointName(device); + if (string.IsNullOrEmpty(dName) == false) + { + return dName; + } + //濡傛灉杩欎釜璁惧鍙湁涓�涓洖璺殑璇�,杩斿洖Mac鍚嶅瓧缁欏畠 + if (this.GetDevicesCountByMac(device.DeviceAddr) <= 1) + { + return this.GetDeviceMacName(device); + } + + //鍚屼竴璁惧閲岄潰,涓嶅悓绫诲瀷鐨勫洖璺�,瀹冪殑鍛藉悕閮戒粠1寮�濮� + int epointNo = 0; + var listSort = this.GetDevicesByMac(device.DeviceAddr); + foreach (var myDevice in listSort) + { + if (myDevice.Type == device.Type) + { + //鍚屼竴绫诲瀷缂栧彿+1 + epointNo++; + if (myDevice.DeviceEpoint == device.DeviceEpoint) + { + //宸茬粡鍒拌揪瀹冭嚜宸� + break; + } + } + } + + if (device.Type == DeviceType.OnOffOutput + || device.Type == DeviceType.DimmableLight || device.Type == DeviceType.ColorDimmableLight) + { + //缁х數鍣�,鎺夊厜鍣ㄩ兘鍙洖璺� + return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo; + } + if (device.Type == DeviceType.Thermostat) + { + //绌鸿皟閮藉彨瀹ゅ唴鏈� + 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); + } + + //鑾峰彇璁惧绫诲瀷 + var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (device.Type == DeviceType.OnOffSwitch) + { + //闈㈡澘鐨勫共鎺ョ偣鍙寜閿� + if (deviceInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) + { + return Language.StringByID(R.MyInternationalizationString.uPanelButton) + epointNo; + } + //鍏朵粬鐨勫共鎺ョ偣鍙共鎺ョ偣 + else + { + return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo; + } + } + else if (device.Type == DeviceType.TemperatureSensor) + { + if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir) + { + //鏂伴闈㈡澘涓殑Thermostat涓烘俯搴︿紶鎰熷櫒 + return Language.StringByID(R.MyInternationalizationString.TemperatureSensor); + } + else if (deviceInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) + { + //闈㈡澘鐨勬俯搴︽帰澶村彨 闈㈡澘鍚嶅瓧+娓╁害 + return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.uTemperature); + } + } + //鍏朵粬鎯呭喌,浣跨敤瀹冪殑榛樿鍚嶇О + return Language.StringByID(deviceInfoType.DefultNameId) + epointNo; + } + + /// <summary> + /// 鑾峰彇璁惧MAC鍚嶇О + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetDeviceMacName(CommonDevice device) + { + string dName = this.GetSimpleMacName(device); + if (string.IsNullOrEmpty(dName) == false) + { + return dName; + } + + //鑾峰彇璁惧绫诲瀷 + var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + return Language.StringByID(deviceInfoType.DefultNameId); + } + + /// <summary> + /// 闈炲叕寮�,璁剧疆璁惧鐨凪ac鍚嶅瓧(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="macName">Mac鍚嶅瓧</param> + /// <returns></returns> + private void SetMacName(CommonDevice device, string macName) + { + device.DeviceName = macName; + } + + /// <summary> + /// 闈炲叕寮�,璁剧疆璁惧鐨勭鐐瑰悕瀛�(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="epointName">绔偣鍚嶅瓧</param> + /// <returns></returns> + private void SetEpointName(CommonDevice device, string epointName) + { + device.DeviceEpointName = epointName; + } + + /// <summary> + /// 鍗曠函鑾峰彇璁惧鐨凪ac鍚嶅瓧 + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetSimpleMacName(CommonDevice device) + { + return device.DeviceName; + } + + /// <summary> + /// 鍗曠函鑾峰彇璁惧鐨勭鐐瑰悕瀛� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + 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 + + #region 鈻� 璁剧疆鍥炬爣___________________________ + + /// <summary> + /// 鍙樻洿璁惧鐨勫浘鏍� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="unSelPath">鍥剧墖鍦板潃(闈為�夋嫨)</param> + public void ChangedDeviceIcon(CommonDevice device, string unSelPath) + { + if (unSelPath == string.Empty) + { + return; + } + device.IconPath = unSelPath; + device.IsCustomizeImage = true; + device.ReSave(); + + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + + /// <summary> + /// 璁剧疆璁惧銆愬浘鏍囥�戝埌鎸囧畾鐨勬帶浠� + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public void SetDeviceIconToControl(Button btnIcon, CommonDevice device) + { + if (device == null) + { + btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png"; + return; + } + string unSelectFilePath = string.Empty; + string selectFilePath = string.Empty; + + //鑾峰彇璁惧銆愬浘鏍囥�� + this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath); + if (btnIcon.UnSelectedImagePath != unSelectFilePath) + { + btnIcon.UnSelectedImagePath = unSelectFilePath; + } + if (btnIcon.SelectedImagePath != selectFilePath) + { + btnIcon.SelectedImagePath = selectFilePath; + } + } + + /// <summary> + /// 璁剧疆璁惧銆愬浘鏍囥�戝埌鎸囧畾鐨勬帶浠�(娉ㄦ剰,姝ゅ嚱鏁拌缃殑閫夋嫨鐘舵�佺殑鍥剧墖鏄櫧鑹茬殑) + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public void SetDeviceIconToControl2(Button btnIcon, CommonDevice device) + { + if (device == null) + { + btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png"; + return; + } + string unSelectFilePath = device.IconPath; + string selectFilePath = unSelectFilePath.Replace(".png", "Selected2.png"); + + //鑾峰彇璁惧銆愬浘鏍囥�� + if (btnIcon.UnSelectedImagePath != unSelectFilePath) + { + btnIcon.UnSelectedImagePath = unSelectFilePath; + } + if (btnIcon.SelectedImagePath != selectFilePath) + { + btnIcon.SelectedImagePath = selectFilePath; + } + } + + /// <summary> + /// 鑾峰彇璁惧銆愬浘鏍囥�� + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceIcon(CommonDevice device, ref string unSelectPath, ref string selectPath) + { + if (string.IsNullOrEmpty(device.IconPath) == true) + { + return; + } + unSelectPath = device.IconPath; + + string selPath = device.OnlineIconPath; + if (string.IsNullOrEmpty(selPath) == false) + { + selectPath = selPath; + } + } + + /// <summary> + /// 璁剧疆璁惧鐨勭湡瀹炲浘鐗囧埌鎸囧畾鐨勬帶浠� + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + public void SetRealDeviceIconToControl(Button btnIcon, List<CommonDevice> listdevice) + { + //鑾峰彇璁惧鐨勭湡瀹炲浘鐗� + string imagePath = this.GetRealDeviceIcon(listdevice); + btnIcon.UnSelectedImagePath = imagePath; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勭湡瀹炲浘鐗� + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + public string GetRealDeviceIcon(List<CommonDevice> listdevice) + { + //鑾峰彇瀹冨睘浜庝粈涔堢被鍨嬬殑璁惧 + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); + + //鍥剧墖鍏辨湁 + if (this.dicPictrueShard.ContainsKey(strConcrete) == true) + { + strConcrete = this.dicPictrueShard[strConcrete]; + } + + string strType = strConcrete.Replace("_", string.Empty); + //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� + string imageFilePath = "RealDevice/" + strType + ".png"; + //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� + string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None); + if (arry.Length == 1) + { + //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 + return "RealDevice/CommonDevice.png"; + } + imageFilePath = "RealDevice/" + arry[0] + ".png"; + //濡傛灉瀹冭嚜宸辩殑鍏遍�氬浘鐗囪繕鏄笉瀛樺湪鐨勮瘽,鍒欑洿鎺ヤ娇鐢ㄦ墍鏈夎澶囩殑鍏遍�氬浘鐗� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + imageFilePath = "RealDevice/CommonDevice.png"; + } + } + return imageFilePath; + } + + /// <summary> + /// 璁剧疆銆愯澶囩被鍨嬨�戠殑鍥炬爣鍒版寚瀹氱殑鎺т欢 + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <returns></returns> + public void SetDeviceObjectIconToControl(Button btnIcon, List<CommonDevice> listdevice) + { + //鑾峰彇鑷畾涔夎澶囩被鍨� + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + + string imageUnSelectFilePath = string.Empty; + string imageSelectFilePath = string.Empty; + + //鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); + + //璁剧疆鍥剧墖 + btnIcon.UnSelectedImagePath = imageUnSelectFilePath; + btnIcon.SelectedImagePath = imageSelectFilePath; + } + + /// <summary> + /// 鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceObjectIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) + { + //鑾峰彇鑷畾涔夎澶囩被鍨� + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + + //鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); + } + + /// <summary> + /// 鑾峰彇銆愯澶囩被鍨嬨�戠殑鍥炬爣 + /// </summary> + /// <param name="specificType">鑷畾涔夎澶囩被鍨�</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) + { + //灏嗗叿浣撶被鍨嬭浆瀛楃涓� + string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType); + //鍥剧墖鍏辨湁 + if (this.dicPictrueShard.ContainsKey(strSpecific) == true) + { + strSpecific = this.dicPictrueShard[strSpecific]; + } + + string strType = strSpecific.Replace("_", string.Empty); + //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� + string imageFilePath = "Device/" + strType + ".png"; + string imageSelectFilePath = "Device/" + strType + "Selected.png"; + + //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� + string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None); + //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 + if (arry.Length > 1) + { + imageFilePath = "Device/" + arry[0] + ".png"; + imageSelectFilePath = "Device/" + arry[0] + "Selected.png"; + } + } + //濡傛灉閭f璁惧杩炲叡閫氬浘鐗囬兘娌℃湁鐨勮瘽 + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + imageFilePath = "Device/ThirdPartyDevice.png"; + imageSelectFilePath = "Device/ThirdPartyDeviceSelected.png"; + } + //璁剧疆鍥剧墖 + unSelectPath = imageFilePath; + selectPath = imageSelectFilePath; + } + + #endregion + + #region 鈻� 鑾峰彇鑷畾涔夌殑璁惧绫诲瀷_______________ + + /// <summary> + /// 鑾峰彇銆愯嚜瀹氫箟鐨勮澶囩被鍨嬨��,涓ょ绫诲瀷閮借缃簡 + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <returns></returns> + public DeviceEnumInfo GetMyDeviceEnumInfo(List<CommonDevice> listdevice) + { + CommonDevice checkDevice = listdevice[0]; + foreach (var temp in listdevice) + { + //鎷挎嫢鏈夋ā鍧桰D鐨勯偅涓洖璺潵鍒ゆ柇 + if (temp.ModelIdentifier != string.Empty) + { + checkDevice = temp; + } + } + + //鑾峰彇娌充笢璁惧鐨勮澶囩被鍨� + DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(checkDevice); + if (info != null) + { + return info; + } + //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� + info = this.GetNotHdlMyDeviceEnumInfo(listdevice); + //杩欓噷鍐嶆鍒ゆ柇鏄惁鏄渤涓滆澶�,鏈夊彲鑳藉畠鐨勬ā鍧桰D鍐欓敊浜� + info.IsHdlDevice = this.IsHdlDevice(checkDevice); + + return info; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勩�愯澶囩被鍨嬨�戠殑缈昏瘧鏂囨湰(浼樺厛闀滃儚) + /// </summary> + /// <param name="listDevice"></param> + /// <param name="ApendFalge">绗笁鏂规垨鑰呰櫄鎷熻澶囩殑鏃跺�欙紝鏄惁娣诲姞鏍囪瘑</param> + /// <returns></returns> + public string GetDeviceObjectText(List<CommonDevice> listDevice, bool ApendFalge = true) + { + CommonDevice checkDevice = listDevice[0]; + foreach (var temp in listDevice) + { + //鎷挎嫢鏈夋ā鍧桰D鐨勯偅涓洖璺潵鍒ゆ柇 + if (temp.ModelIdentifier != string.Empty) + { + checkDevice = temp; + } + } + //鑾峰彇鑷畾涔夎澶囩被鍨� + var myInfoType = this.GetMyDeviceEnumInfo(listDevice); + //鑾峰彇璁惧绫诲瀷鐨勭炕璇戝悕瀛� + string strName = Language.StringByID(myInfoType.ObjectTypeNameId); + if (strName == string.Empty) + { + //鍔犱竴灞備繚闄�,鏈煡璁惧 + strName = Language.StringByID(R.MyInternationalizationString.UnknowDevice); + } + + if (ApendFalge == true) + { + if (listDevice[0].DriveCode > 0) + { + //铏氭嫙璁惧鍔犱釜鏍囪瘑 + strName += "鉁�"; + } + else + { + foreach (var temp in listDevice) + { + //鎷挎嫢鏈夋ā鍧桰D鐨勯偅涓洖璺潵鍒ゆ柇 + if (temp.ModelIdentifier != string.Empty) + { + if (this.IsHdlDevice(checkDevice) == false) + { + //绗笁鏂硅澶囧姞涓爣璇� + strName += "鈽�"; + break; + } + } + } + } + } + return strName; + } + + #endregion + + #region 鈻� 鑾峰彇娌充笢璁惧鐨勮澶囩被鍨媉____________ + + /// <summary> + /// 鑾峰彇Hdl璁惧鐨勩�愯嚜瀹氫箟鐨勮澶囩被鍨嬨�� + /// </summary> + /// <param name="device">闅忎究鏌愪竴鍥炶矾</param> + /// <returns></returns> + private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device) + { + //璁惧鍏蜂綋绫诲瀷 + var info = new DeviceEnumInfo(); + info.IsHdlDevice = this.IsHdlDevice(device); + if (device.ModelIdentifier == string.Empty) + { + return null; + } + string modelKeys = device.ModelIdentifier; + //浜ゆ崲涓�涓嬫ā鍧桰D(楹︿箰鍏嬮偅杈圭殑浼犳劅鍣�) + this.ChangedDeviceModeId(ref modelKeys); + + if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) + { + //娌℃湁鍖归厤鍒版ā鍧桰D锛屽垯鐩存帴璧扮涓夋柟璁惧鐨勫垽鏂� + return null; + } + + string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); + int ConcreteValue = Convert.ToInt32(strValue[0]); + int BeloneValue = Convert.ToInt32(strValue[1]); + //璁剧疆璁惧鐨勩�愯澶囨墍灞炵被鍨嬨�� + info.BeloneType = (DeviceBeloneType)BeloneValue; + if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + BeloneValue) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + BeloneValue]; + } + + //璁惧鍏蜂綋绫诲瀷 + info.ConcreteType = (DeviceConcreteType)ConcreteValue; + if (info.ConcreteType.ToString() == ConcreteValue.ToString()) + { + info.ConcreteType = DeviceConcreteType.UnKownDevice; + } + string keyName = deviceModelIdName + ConcreteValue; + if (this.dicDeviceAllNameID.ContainsKey(keyName) == true) + { + //璁惧鐨勫畼鏂瑰悕绉� + info.ConcreteTextId = this.dicDeviceAllNameID[keyName]; + } + + //璁惧鐨勭被鍨嬬炕璇戝悕绉� + info.ObjectTypeNameId = Convert.ToInt32(strValue[2]); + + return info; + } + + #endregion + + #region 鈻� 鑾峰彇绗笁鏂硅澶囩殑璁惧绫诲瀷___________ + + /// <summary> + /// 鑾峰彇璁惧鐨勩�愭墍灞炵被鍨嬩俊鎭��,姝ゆ柟娉曚細鎶婃墍鏈夌殑浼犳劅鍣ㄩ兘褰掍负銆愪紶鎰熷櫒銆�(鍖呮嫭娓╂箍搴︿紶鎰熷櫒) + /// </summary> + /// <param name="device">璁惧鍥炶矾</param> + /// <returns></returns> + public DeviceEnumInfo GetDeviceBelongEnumInfo(CommonDevice device) + { + var info = this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }); + if (info.BeloneType == DeviceBeloneType.A璋冨厜鍣� + || 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]; + } + } + else if (info.BeloneType == DeviceBeloneType.A浼犳劅鍣� + || device.Type == DeviceType.TemperatureSensor) + { + //浼犳劅鍣ㄥ悎骞� + 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]; + } + } + + return info; + } + + /// <summary> + /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨��(涓嶅缓璁娇鐢�) + /// </summary> + /// <param name="listdevice">Mac閮戒竴鏍风殑璁惧鍒楄〃</param> + /// <returns></returns> + public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice) + { + var dicType = new Dictionary<DeviceType, CommonDevice>(); + foreach (CommonDevice device in listdevice) + { + if (dicType.ContainsKey(device.Type) == false) + { + dicType[device.Type] = device; + } + } + var info = new DeviceEnumInfo(); + info.IsHdlDevice = false; + //1鍖呭惈闈㈡澘鐨勮瘽,褰撻潰鏉垮鐞� + if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true) + { + if (listdevice.Count > 1) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200; + info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; + info.ConcreteType = DeviceConcreteType.ButtonPanel; + } + else + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16; + info.BeloneType = DeviceBeloneType.A骞叉帴鐐�; + info.ConcreteType = DeviceConcreteType.DryContact; + } + info.ObjectTypeNameId = 60003;//鏅鸿兘闈㈡澘 + } + //3鍖呭惈绐楀笜鐨勮瘽,褰撶獥甯樺鐞� + else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId100; + info.BeloneType = DeviceBeloneType.A绐楀笜; + info.ConcreteType = DeviceConcreteType.Curtain; + info.ObjectTypeNameId = 60002;//閬槼妯″潡 + } + //4绌烘皵寮�鍏� + else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) + { + //榛樿鍊� + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100; + info.BeloneType = DeviceBeloneType.A寮�鍏�; + info.ConcreteType = DeviceConcreteType.AirSwitch; + info.ObjectTypeNameId = 60001;//寮�鍏虫ā鍧� + + if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A寮�鍏�) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.BeloneType = DeviceBeloneType.A寮�鍏�; + info.ConcreteType = DeviceConcreteType.Switch; + } + else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鎻掑骇) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.BeloneType = DeviceBeloneType.A鎻掑骇; + info.ConcreteType = DeviceConcreteType.Socket1; + } + else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A鐏厜) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.ConcreteType = DeviceConcreteType.Light; + } + } + //5缁х數鍣� + else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) + { + //榛樿鍊� + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300; + info.BeloneType = DeviceBeloneType.A缁х數鍣�; + info.ConcreteType = DeviceConcreteType.Relay; + info.ObjectTypeNameId = 60001;//寮�鍏虫ā鍧� + + if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A寮�鍏�) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13; + info.BeloneType = DeviceBeloneType.A寮�鍏�; + info.ConcreteType = DeviceConcreteType.Switch; + } + else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鎻掑骇) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14; + info.BeloneType = DeviceBeloneType.A鎻掑骇; + info.ConcreteType = DeviceConcreteType.Socket1; + } + else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A鐏厜) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15; + info.BeloneType = DeviceBeloneType.A鐏厜; + info.ConcreteType = DeviceConcreteType.Light; + } + } + //6璋冨厜鍣� + else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2500; + info.BeloneType = DeviceBeloneType.A璋冨厜鍣�; + info.ConcreteType = DeviceConcreteType.DimmableLight; + info.ObjectTypeNameId = 60007;//璋冨厜妯″潡 + } + //7褰╃伅 + else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9; + info.BeloneType = DeviceBeloneType.A褰╃伅; + info.ConcreteType = DeviceConcreteType.ColorLight; + info.ObjectTypeNameId = 60007;//璋冨厜妯″潡 + } + //8绌鸿皟 + else if (dicType.ContainsKey(DeviceType.Thermostat) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3600; + info.BeloneType = DeviceBeloneType.A绌鸿皟; + info.ConcreteType = DeviceConcreteType.AirConditioner; + info.ObjectTypeNameId = 60009;//绌鸿皟妯″潡 + } + //9涓户鍣� + else if (dicType.ContainsKey(DeviceType.Repeater) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3900; + info.BeloneType = DeviceBeloneType.A涓户鍣�; + info.ConcreteType = DeviceConcreteType.Repeater; + info.ObjectTypeNameId = 60006;//绯荤粺璁惧 + } + //10杞崲鍣� + else if (dicType.ContainsKey(DeviceType.Transverter) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4200; + info.BeloneType = DeviceBeloneType.A杞崲鍣�; + info.ConcreteType = DeviceConcreteType.Converter; + info.ObjectTypeNameId = 60008;//杞崲鍣� + } + //11鏅鸿兘闂ㄩ攣 + else if (dicType.ContainsKey(DeviceType.DoorLock) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2800; + info.BeloneType = DeviceBeloneType.A鏅鸿兘闂ㄩ攣; + info.ConcreteType = DeviceConcreteType.IntelligentLocks; + info.ObjectTypeNameId = 60010;//鏅鸿兘闂ㄩ攣 + } + //12鍖呭惈浼犳劅鍣ㄧ殑璇�,褰撲紶鎰熷櫒澶勭悊 + else if (dicType.ContainsKey(DeviceType.IASZone) == true) + { + info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; + info.ConcreteType = DeviceConcreteType.Sensor; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; + info.ObjectTypeNameId = 60000;//浼犳劅鍣� + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + this.SetSensorDeviceSpecificType(ref info, listdevice); + } + //13鍖呭惈娓╁害浼犳劅鍣ㄧ殑璇� + else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true) + { + bool temperatrue = false; + bool humidity = false; + //鑾峰彇鍏ㄩ儴鐨勫洖璺� + var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false); + foreach (var device in listTemp) + { + if (device is TemperatureSensor) + { + //娓╁害浼犳劅鍣� + if (((TemperatureSensor)device).SensorDiv == 1) + { + temperatrue = true; + } + //婀垮害浼犳劅鍣� + else if (((TemperatureSensor)device).SensorDiv == 2) + { + humidity = true; + } + } + } + if (temperatrue == true && humidity == true) + { + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + info.BeloneType = DeviceBeloneType.A娓╂箍搴︿紶鎰熷櫒; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10; + info.ConcreteType = DeviceConcreteType.Sensor_TemperatureHumidity; + } + else if (temperatrue == true && humidity == false) + { + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + info.BeloneType = DeviceBeloneType.A娓╁害浼犳劅鍣�; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11; + info.ConcreteType = DeviceConcreteType.Sensor_Temperature; + } + else if (temperatrue == false && humidity == true) + { + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + info.BeloneType = DeviceBeloneType.A婀垮害浼犳劅鍣�; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId12; + info.ConcreteType = DeviceConcreteType.Sensor_Humidity; + } + info.ObjectTypeNameId = 60000;//浼犳劅鍣� + } + + int value = (int)info.BeloneType; + if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value]; + } + + return info; + } + + #endregion + + #region 鈻� 浼犳劅鍣ㄥ叿浣撶殑绫诲瀷___________________ + + /// <summary> + /// 璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + /// </summary> + /// <param name="info">鑷畾涔夎澶囨灇涓句俊鎭�</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice) + { + //濡傛灉杩欎釜璁惧鎷ユ湁澶氫釜鍥炶矾鐨勮瘽,鎴戜篃涓嶇煡閬撴�庝箞鍛藉悕,鍙兘缁欎釜榛樿鍚嶅瓧 + if (listdevice.Count > 1) + { + return; + } + var iasZone = (IASZone)listdevice[0]; + if (iasZone.IasDeviceType == 13) + { + //杩愬姩浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Motion; + info.ConcreteTextId = R.MyInternationalizationString.uMotionSensor; + } + else if (iasZone.IasDeviceType == 40) + { + //鐑熼浘浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Fire; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1302; + } + else if (iasZone.IasDeviceType == 42) + { + //姘翠镜浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Water; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1304; + } + else if (iasZone.IasDeviceType == 43) + { + //鐕冩皵浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_CarbonMonoxide; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1300; + } + else if (iasZone.IasDeviceType == 44) + { + //绱ф�ユ寜閽� + info.ConcreteType = DeviceConcreteType.Sensor_EmergencyButton; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1305; + } + else if (iasZone.IasDeviceType == 277) + { + //閽ュ寵鎵� + info.ConcreteType = DeviceConcreteType.Sensor_Keyfob; + info.ConcreteTextId = R.MyInternationalizationString.uKeyfob; + } + else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22) + { + //闂ㄧ獥浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301; + } + } + + #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) + { + if (roomId == string.Empty) + { + //閫夋嫨鐨勬槸鏈垎閰� + this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr); + } + else + { + this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId; + } + } + + //淇濆瓨璁板綍 + string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); + UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); + + //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜� + if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1) + { + if (listDevice[0] is OTADevice) + { + //鍗曠函鍙槸Ota璁惧鍒欎笉澶勭悊 + return; + } + HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false); + } + } + + /// <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) + { + foreach (var deviceMacAddr in listMac) + { + this.dicDeviceRoomId.Remove(deviceMacAddr); + } + //淇濆瓨璁板綍 + string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile); + UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile); + } + + #endregion + + #region 鈻� 璁惧鎺掑簭___________________________ + + /// <summary> + /// 璁惧鎺掑簭 + /// </summary> + /// <param name="i_listDevice">璇风‘淇濊繖涓笢瑗垮凡缁忔寜mac鍜岀鐐规帓搴忎簡</param> + /// <returns></returns> + public List<CommonDevice> SortDeviceByBelongType(List<CommonDevice> i_listDevice) + { + //鑾峰彇鎺掑簭瑙勫垯 + var listRule = this.GetBelongTypeSortRule(); + var dicDevice = new Dictionary<DeviceBeloneType, List<CommonDevice>>(); + dicDevice[DeviceBeloneType.A鏈煡璁惧] = new List<CommonDevice>(); + + foreach (var device in i_listDevice) + { + //鑾峰彇鎵�灞炵被鍨� + var typeInfo = this.GetDeviceBelongEnumInfo(device); + if (listRule.Contains(typeInfo.BeloneType) == false) + { + //涓嶅湪鎺掑簭鑼冨洿鍐�,閮戒涪鍦ㄦ渶鍚庨潰 + dicDevice[DeviceBeloneType.A鏈煡璁惧].Add(device); + continue; + } + if (dicDevice.ContainsKey(typeInfo.BeloneType) == false) + { + dicDevice[typeInfo.BeloneType] = new List<CommonDevice>(); + } + dicDevice[typeInfo.BeloneType].Add(device); + } + + var listSort = new List<CommonDevice>(); + foreach (var myType in listRule) + { + //鏍规嵁瑙勫垯椤哄簭,娣诲姞璁惧 + if (dicDevice.ContainsKey(myType) == false || dicDevice[myType].Count == 0) + { + continue; + } + listSort.AddRange(dicDevice[myType]); + } + + return listSort; + } + + /// <summary> + /// 鑾峰彇璁惧鎵�灞炵被鍨嬬殑鐨勬帓搴忚鍒� + /// </summary> + /// <returns></returns> + public HashSet<DeviceBeloneType> GetBelongTypeSortRule() + { + //璋佸湪鍓嶉潰,璋佸氨浼樺厛鏄剧ず + var list = new HashSet<DeviceBeloneType>(); + list.Add(DeviceBeloneType.A鐏厜); + list.Add(DeviceBeloneType.A褰╃伅); + list.Add(DeviceBeloneType.A寮�鍏�); + list.Add(DeviceBeloneType.A鎻掑骇); + list.Add(DeviceBeloneType.A璋冨厜鍣�); + list.Add(DeviceBeloneType.A绐楀笜); + list.Add(DeviceBeloneType.A绌鸿皟); + list.Add(DeviceBeloneType.A缁х數鍣�); + list.Add(DeviceBeloneType.A骞叉帴鐐�); + list.Add(DeviceBeloneType.A鏅鸿兘闂ㄩ攣); + list.Add(DeviceBeloneType.A鏅鸿兘绌哄紑); + list.Add(DeviceBeloneType.A浼犳劅鍣�); + + //鍏朵粬鐨勭湅鐫�鍔炲憲,閮芥槸鎺掑湪鍚庨潰鐨�,閮藉綊涓鸿繖涓睘鎬� + list.Add(DeviceBeloneType.A鏈煡璁惧); + + return list; + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鍒ゆ柇璇ヨ澶囨槸鍚﹀彲浠ユ樉绀哄湪涓婚〉 + /// </summary> + /// <param name="i_device"></param> + /// <returns></returns> + public bool CanShowInHomeHomeMainPage(CommonDevice i_device) + { + if (i_device == null || i_device.Type == DeviceType.OnOffSwitch)//骞叉帴鐐� + { + //杩欎釜璁惧涓嶈浜� + return false; + } + 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) + { + return false; + } + } + //2020.03.30杩藉姞寮忔牱:濡傛灉鏄潰鏉跨殑娓╁害鎺㈠ご,涓嶆樉绀� + else if (i_device.Type == DeviceType.TemperatureSensor && ((TemperatureSensor)i_device).SensorDiv == 1) + { + var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device }); + if (myInfoType.BeloneType == DeviceBeloneType.A鎸夐敭闈㈡澘) + { + return false; + } + } + return true; + } + + /// <summary> + /// 鍒ゆ柇鏄笉鏄渤涓滅殑璁惧 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool IsHdlDevice(CommonDevice device) + { + return device.ManufacturerName == "HDL"; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public string GetDeviceMainKeys(CommonDevice device) + { + return this.GetDeviceMainKeys(device.DeviceAddr, device.DeviceEpoint); + } + + /// <summary> + /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 + /// </summary> + /// <param name="DeviceAddr">MAC鍦板潃</param> + /// <param name="DeviceEpoint">绔彛鍙�</param> + /// <returns></returns> + public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint) + { + return DeviceAddr + "_" + DeviceEpoint; + } + + /// <summary> + /// 浜ゆ崲璁惧鐨勬ā鍧桰D + /// </summary> + /// <param name="modeId">妯″潡ID</param> + /// <returns></returns> + public bool ChangedDeviceModeId(ref string modeId) + { + if (this.dicDeviceModelIdChanged.ContainsKey(modeId) == false) + { + return false; + } + modeId = this.dicDeviceModelIdChanged[modeId]; + + return true; + } + + /// <summary> + /// 闄勫姞璁惧鐨勭増鏈唬鍙�(杩斿洖Ver.XXX) + /// </summary> + /// <param name="versionValue">鐗堟湰鍙�</param> + /// <returns></returns> + public string AppendVersion(int versionValue) + { + //鐩存帴鏄�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)); + + //Ver. + string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); + return ver + value1 + "." + value2.ToString().PadLeft(2, '0'); + } + + /// <summary> + /// 鏄剧ず閿欒淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowErrorMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Error, msg); + contr.Show(); + }); + } + + /// <summary> + /// 鏄剧ずTip淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowTipMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + contr.Show(); + }); + } + + #endregion + + //----------------------------------鍒嗗壊绾�(鑷畾涔夋帴鍙�)--------------------------------------------- + + #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________ + + /// <summary> + /// <para>浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(杩斿洖鐨勮澶囦负铏氭嫙鍑烘潵鐨�)</para> + /// <para>statu鐘舵�� -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</para> + /// </summary> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + /// <param name="statu">鐘舵��-> -1:寮傚父,浼氳繑鍥瀗ull, 1锛氭病鏈夊紓甯�, 2:鏁版嵁鎺ユ敹涓嶅叏</param> + /// <param name="ignoreTime">鏄惁鏃犺鏃堕棿(姝ゅ彉閲忔槸缁欒幏鍙栧湪绾跨姸鎬佺敤鐨�),true:姣忔璋冪敤閮藉幓缃戝叧鑾峰彇,false:3鍒嗛挓鍐呰繑鍥炵殑鏄湰鍦扮殑璁惧</param> + /// <param name="mode">鏄惁鏄剧ず閿欒</param> + /// <returns></returns> + public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, 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; + } + + //鏄惁杈炬垚涓柇鐨勬椂鏈� + bool canBreak = false; + //缃戝叧ID + string gatewayID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + //瓒呮椂鏃堕棿 + int TimeOut = 0; + //璁惧鎬绘暟 + int deviceCount = -1; + //鎺ユ敹鏁� + int receiveCount = 0; + //璁惧鍒楄〃 + var listDevice = new List<CommonDevice>(); + //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾 + var listCheck = new HashSet<string>(); + Action<string, string> getDeviceAction = (topic, message) => + { + if (topic == gatewayID + "/DeviceInfoRespon") + { + try + { + lock (listDevice) + { + //璁惧鎺ユ敹鏁� + 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; + } + + var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); + if (device != null) + { + string mainkeys = this.GetDeviceMainKeys(device); + //缃戝叧閲岄潰鏈夊彲鑳戒細鏈夐噸澶嶇殑鍥炶矾 + if (listCheck.Contains(mainkeys) == false) + { + listDevice.Add(device); + + listCheck.Add(mainkeys); + } + } + } + } + //Log鍑哄姏 + catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } + + if (receiveCount == deviceCount && deviceCount != -1) + { + //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚 + canBreak = true; + } + } + else if (topic == gatewayID + "/DeviceInfoResponEnd") + { + } + }; + + 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) + { + System.Threading.Thread.Sleep(100); + TimeOut++; + } + + realWay.Actions -= getDeviceAction; + getDeviceAction = null; + + if (TimeOut >= 60) + { + if (listDevice.Count == 0) + { + if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) + { + //鑾峰彇璁惧鍒楄〃澶辫触 + //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇� + string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); + msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).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; + } + return listDevice; + } + + #endregion + + #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________ + + /// <summary> + /// 鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + /// </summary> + /// <param name="deviceType">璁惧绫诲瀷</param> + /// <param name="jobject">涓婚Data</param> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + /// <returns></returns> + private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway) + { + string gwId = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType); + if (device == null) + { + return null; + } + + //璁剧疆璁惧灞炴�х被 + device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString()); + if (device.DeviceInfo == null) + { + return null; + } + this.SetMacName(device, string.Empty); + this.SetEpointName(device, string.Empty); + + //璁剧疆璁惧涓婚敭绫� + this.SetNewDeviceMainKeys(device, jobject); + device.CurrentGateWayId = gwId; + + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(device, device); + + return device; + } + + /// <summary> + /// 灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + /// </summary> + /// <param name="mainDevice">涓昏澶囧璞�</param> + /// <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.CurrentGateWayId = device.CurrentGateWayId; + mainDevice.IsOnline = device.DeviceInfo.IsOnline; + mainDevice.DriveCode = device.DeviceInfo.DriveCode; + mainDevice.IasDeviceType = device.DeviceInfo.DeviceType; + mainDevice.Profile = device.DeviceInfo.Profile; + mainDevice.Type = device.Type; + + //鍥轰欢鐗堟湰 + mainDevice.ImgVersion = device.DeviceInfo.ImgVersion; + //纭欢鐗堟湰 + mainDevice.HwVersion = device.DeviceInfo.HwVersion; + //闀滃儚ID + mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId; + //鍘傚晢鍚嶇О + mainDevice.ManufacturerName = device.DeviceInfo.ManufacturerName; + //妯″潡ID + mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier; + //搴忓垪鍙� + mainDevice.SerialNumber = device.DeviceInfo.ProductCode; + + 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) + { + //杈撳嚭鏃� 1026:娓╁害浼犳劅鍣� 1029:婀垮害浼犳劅鍣� + foreach (var data in mainDevice.OutClusterList) + { + if (data.OutCluster == 1029) + { + ((TemperatureSensor)mainDevice).SensorDiv = 2; + } + else if (data.OutCluster == 1026) + { + ((TemperatureSensor)mainDevice).SensorDiv = 1; + } + } + } + //濡傛灉鏄皟鍏夊櫒 + 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) + { + 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> + /// <returns></returns> + public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType) + { + CommonDevice device = null; + + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); } + else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); } + else if (deviceType == DeviceType.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.FreshAirHumiditySensor) { device = new HumiditySensor(); } + else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); } + else { return null; } + + device.DeviceEpointName = string.Empty; + device.DeviceName = string.Empty; + + return device; + } + + /// <summary> + /// 缁欐柊璁惧璁剧疆涓婚敭灞炴�� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="jobject">涓婚Data</param> + public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject) + { + //璁剧疆璁惧涓婚敭绫� + device.Time = jobject.Value<int>("Time"); + device.DeviceID = jobject.Value<int>("Device_ID"); + device.DeviceAddr = jobject.Value<string>("DeviceAddr"); + device.DeviceEpoint = jobject.Value<int>("Epoint"); + device.DataID = jobject.Value<int>("Data_ID"); + } + + #endregion + + //----------------------------------鍒嗗壊绾�(璁惧妯″潡ID)--------------------------------------------- + + #region 鈻� 鑷畾涔夎澶囨ā鍧桰D___________________ + + /// <summary> + /// 鍒濆鍖栬澶囩殑妯″潡ID鐨勬灇涓� + /// </summary> + private void InitDeviceModelIdEnum() + { + if (this.dicDeviceModelIdEnum != null) + { + return; + } + this.dicDeviceModelIdEnum = new Dictionary<string, string>(); + + //********************************************************************* + //鏂拌澶囨坊鍔犳柟娉曪細 + //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-1300-60000";//鐕冩皵浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300-60000";//闂ㄧ獥纾佷紶鎰熷櫒 + this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300-60000";//鐑熼浘浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300-60000";//绾㈠浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300-60000";//姘存蹈浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300-60000";//绱ф�ユ寜閿� + //杩欓噷鏄渤涓滅殑 + this.dicDeviceModelIdEnum["MSG01/M-ZB.10"] = "1300-1300-60000";//鐕冩皵浼犳劅鍣� + this.dicDeviceModelIdEnum["MSDC01/M-ZB.10"] = "1301-1300-60000";//闂ㄧ獥纾佷紶鎰熷櫒 + this.dicDeviceModelIdEnum["MSS01/M-ZB.10"] = "1302-1300-60000";//鐑熼浘浼犳劅鍣� + this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1300-60000";//绾㈠浼犳劅鍣� + this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1300-60000";//姘存蹈浼犳劅鍣� + this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1300-60000";//绱ф�ユ寜閿� + + //=========鈽呪槄缁х數鍣ㄧ被(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鍗忚杞崲鍣� + + + + //鉁┾湬鉁┾湬鉁╅渶瑕佷氦鎹㈢殑妯″潡ID鉁┾湬鉁┾湬鉁� + this.dicDeviceModelIdChanged = new Dictionary<string, string>(); + //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫烩槄鈽�========= + this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//鐕冩皵浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-MECI--EA01"] = "MSDC01/M-ZB.10";//闂ㄧ獥纾佷紶鎰熷櫒 + this.dicDeviceModelIdChanged["MULTI-FIRE--EA05"] = "MSS01/M-ZB.10";//鐑熼浘浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//绾㈠浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//姘存蹈浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//绱ф�ユ寜閿� + + + + //鉁┾湬鉁┾湬鉁╅渶瑕佸叡鏈夌殑鍥剧墖瀵硅薄鉁┾湬鉁┾湬鉁� + //涓よ�呴兘鏄疍eviceConcreteType + //Keys:鎸囧畾鐨勮澶� value:娌跨敤鐨勫浘鐗囨槸鍝璁惧鐨� + this.dicPictrueShard = new Dictionary<string, string>(); + this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//绠�绾�4鎸夐敭闈㈡澘 娌跨敤 4鎸夐敭鐨勫浘鏍� + this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//绠�绾�3鎸夐敭闈㈡澘 娌跨敤 3鎸夐敭鐨勫浘鏍� + this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//绠�绾�2鎸夐敭闈㈡澘 娌跨敤 2鎸夐敭鐨勫浘鏍� + this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one鐨勯棬閿佸浘鐗囨部鐢℉06C鐨勫浘鏍� + this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//鏂规偊鏂伴灏忔ā鍧楀浘鐗囨部鐢�3璺户鐢靛櫒鐨勫浘鏍� + + } + + #endregion + } + + #region 鈻� 鑷畾涔夎澶囩被鍨媉________________________ + + /// <summary> + /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囩殑鍏蜂綋銆愯澶囩被鍨嬨��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceConcreteType鍊�)</para> + /// <para>鍙橀噺鍚嶅彲浠ヤ綔涓恒�愯澶囩被鍨嬨�戝浘鐗�,杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> + /// </summary> + public enum DeviceConcreteType + { + //瀹氫箟瑙勫垯锛氥�愯澶囩被鍨嬨�戝浘鐗囧悕瀛�=LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceConcreteType鍊� + + /// <summary> + /// 鏈煡璁惧 + /// </summary> + UnKownDevice = -1, + + //=========鈽呪槄绐楀笜绫�(100-199)鈽呪槄========= + /// <summary> + /// 绐楀笜 + /// </summary> + Curtain = -100, + /// <summary> + /// 鏅鸿兘寮�鍚堝笜鐢垫満 闀滃儚id锛�100 + /// </summary> + Curtain_AutoOpen = 100, + /// <summary> + /// 鏅鸿兘绠$姸鐢垫満 闀滃儚id锛�101 + /// </summary> + Curtain_Siphonate = 101, + + //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄========= + /// <summary> + /// 鎸夐敭闈㈡澘 + /// </summary> + ButtonPanel = -200, + /// <summary> + /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�4璺户鐢靛櫒搴曞骇) 闀滃儚id锛�200 + /// </summary> + ButtonPanel_Four = 200, + /// <summary> + /// 3鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�3璺户鐢靛櫒搴曞骇) 闀滃儚id锛�201 + /// </summary> + ButtonPanel_Three = 201, + /// <summary> + /// 2鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�2璺户鐢靛櫒搴曞骇) 闀滃儚id锛�202 + /// </summary> + ButtonPanel_Two = 202, + /// <summary> + /// 12鎸夐敭澶氬姛鑳借Е鎽搁潰鏉�(甯�1璺户鐢靛櫒搴曞骇) 闀滃儚id锛�203 + /// </summary> + ButtonPanel_Twelve = 203, + /// <summary> + /// 4鎸夐敭澶氬姛鑳借Е鎽搁潰鏉匡紙鍙甫鐢垫簮搴曞骇锛� 闀滃儚id锛�210 + /// </summary> + ButtonPanel_FourNotPower = 210, + /// <summary> + /// 绠�绾�4鎸夐敭闈㈡澘 闀滃儚id锛�220 + /// </summary> + ButtonPanel_SimpleFour = 220, + /// <summary> + /// 绠�绾�3鎸夐敭闈㈡澘 闀滃儚id锛�221 + /// </summary> + ButtonPanel_SimpleThree = 221, + /// <summary> + /// 绠�绾�2鎸夐敭闈㈡澘 闀滃儚id锛�222 + /// </summary> + ButtonPanel_SimpleTwo = 222, + /// <summary> + /// 绠�绾�4鎸夐敭鍦烘櫙闈㈡澘 闀滃儚id锛�224 + /// </summary> + ButtonPanel_FourButtonScene = 224, + /// <summary> + /// 绠�绾�2璺獥甯橀潰鏉� 闀滃儚id锛�226 + /// </summary> + ButtonPanel_TwoButtonCurtain = 226, + /// <summary> + /// 鏂规偊2鎸夐敭杞昏Е寮忛潰鏉� 闀滃儚id锛�240 + /// </summary> + ButtonPanel_FangyueTwo = 240, + /// <summary> + /// 鏂规偊4鎸夐敭杞昏Е寮忛潰鏉� 闀滃儚id锛�241 + /// </summary> + ButtonPanel_FangyueFour = 241, + /// <summary> + /// 鏂规偊8鎸夐敭杞昏Е寮忛潰鏉� 闀滃儚id锛�242 + /// </summary> + ButtonPanel_FangyueEight = 242, + /// <summary> + /// 鏂规偊鏂伴闈㈡澘 闀滃儚id锛�250 + /// </summary> + ButtonPanel_FangyueFreshAir = 250, + /// <summary> + /// 鏂规偊鐜闈㈡澘 闀滃儚id锛�253 + /// </summary> + ButtonPanel_FangyueEnvironment = 253, + /// <summary> + /// 绐楀笜闈㈡澘 闀滃儚id锛�256 + /// </summary> + ButtonPanel_Curtain = 256, + + //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= + /// <summary> + /// 浼犳劅鍣� + /// </summary> + Sensor = -1200, + /// <summary> + /// pir浼犳劅鍣�220 闀滃儚id锛�1200 + /// </summary> + Sensor_Pir = 1200, + + //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄========= + /// <summary> + /// 鐕冩皵浼犳劅鍣� + /// </summary> + Sensor_CarbonMonoxide = 1300, + /// <summary> + /// 闂ㄧ獥浼犳劅鍣� + /// </summary> + Sensor_DoorWindow = 1301, + /// <summary> + /// 鐑熼浘浼犳劅鍣� + /// </summary> + Sensor_Fire = 1302, + /// <summary> + /// 绾㈠浼犳劅鍣� + /// </summary> + Sensor_Infrared = 1303, + /// <summary> + /// 姘翠镜浼犳劅鍣� + /// </summary> + Sensor_Water = 1304, + /// <summary> + /// 绱ф�ユ寜閽� + /// </summary> + Sensor_EmergencyButton = 1305, + /// <summary> + /// 杩愬姩浼犳劅鍣� + /// </summary> + Sensor_Motion = -1306, + /// <summary> + /// 閽ュ寵鎵� + /// </summary> + Sensor_Keyfob = -1307, + /// <summary> + /// 娓╂箍搴︿紶鎰熷櫒 + /// </summary> + Sensor_TemperatureHumidity = -1308, + /// <summary> + /// 娓╁害浼犳劅鍣� + /// </summary> + Sensor_Temperature = -1309, + /// <summary> + /// 婀垮害浼犳劅鍣� + /// </summary> + Sensor_Humidity = -1310, + + //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄========= + /// <summary> + /// 缁х數鍣� + /// </summary> + Relay = -2300, + /// <summary> + /// 涓夎矾缁х數鍣� 闀滃儚id锛�2300 + /// </summary> + Relay_ThreeLoad = 2300, + /// <summary> + /// 鏂规偊鏂伴灏忔ā鍧� 闀滃儚id锛�2310 + /// </summary> + Relay_FangyueFreshAirModul = 2310, + + //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄========= + /// <summary> + /// 璋冨厜鍣� + /// </summary> + DimmableLight = -2500, + /// <summary> + /// 1璺皟鍏夊櫒灏忔ā鍧� + /// </summary> + DimmableLight_OneLoad = 2500, + + //=========鈽呪槄鏅鸿兘闂ㄩ攣绫�(2800-????)鈽呪槄========= + /// <summary> + /// 鏅鸿兘闂ㄩ攣 + /// </summary> + IntelligentLocks = -2800, + /// <summary> + /// H06C + /// </summary> + IntelligentLocks_H06C = 2800, + /// <summary> + /// S-one + /// </summary> + IntelligentLocks_Sone = 2802, + + //=========鈽呪槄褰╃伅绫�(????-????)鈽呪槄========= + /// <summary> + /// 褰╃伅 + /// </summary> + ColorLight = -10, + + //=========鈽呪槄绌鸿皟(3600-3899)鈽呪槄========= + /// <summary> + /// 绌鸿皟 + /// </summary> + AirConditioner = -3600, + /// <summary> + /// zigbee绌鸿皟缃戝叧妯″潡 + /// </summary> + AirConditioner_ZbGateway = 3600, + + //=========鈽呪槄涓户鍣�(3900-3999)鈽呪槄========= + /// <summary> + /// 涓户鍣� + /// </summary> + Repeater = -3900, + /// <summary> + /// zigbee涓户鍣� 闀滃儚id锛�3900 + /// </summary> + Repeater_Zigbee = 3900, + + //=========鈽呪槄绌烘皵寮�鍏崇被(4100-????)鈽呪槄========= + /// <summary> + /// 鏅鸿兘绌哄紑 + /// </summary> + AirSwitch = -4100, + /// <summary> + /// 鏅鸿兘绌哄紑 闀滃儚id锛�4100 + /// </summary> + AirSwitch_CloudContr = 4100, + + //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄========= + /// <summary> + /// 杞崲鍣� + /// </summary> + Converter = -4200, + /// <summary> + /// zigbee杞�485鍗忚杞崲鍣� + /// </summary> + Converter_Zb485 = 4200, + /// <summary> + /// zigbee杞琤uspro鍗忚杞崲鍣� + /// </summary> + Converter_ZbBuspro = 4201, + + //=========鈽呪槄鍏朵粬绫�(????-????)鈽呪槄========= + /// <summary> + /// 骞叉帴鐐�(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + DryContact = -10000, + /// <summary> + /// 鐏厜(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Light = -10001, + /// <summary> + /// 鎻掑骇(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Socket1 = -10002, + /// <summary> + /// 寮�鍏�(娉ㄦ剰,瀹冨睘浜庡叾浠栫被,涓嶆槸璁惧绫诲瀷) + /// </summary> + Switch = -10003, + } + + /// <summary> + /// <para>浠呴檺搴曞眰浣跨敤锛氳澶囨墍灞炵殑銆愯澶囩绫汇��,鑷畾涔変笌妯″潡id鍏宠仈鐨勬灇涓�(鍊间负LocalDevice閲岄潰dicDeviceModelIdEnum鎵�鎸囧畾鐨凞eviceBeloneType鍊�)</para> + /// <para>杩欎釜鍊兼槸鐬庡啓鐨�,娌′粈涔堢壒娈婃剰涔�</para> + /// </summary> + public enum DeviceBeloneType + { + /// <summary> + /// 鏈煡璁惧 + /// </summary> + A鏈煡璁惧 = 0, + /// <summary> + /// 绐楀笜(100-199) + /// </summary> + A绐楀笜 = 100, + /// <summary> + /// 鎸夐敭闈㈡澘(200-1199) + /// </summary> + A鎸夐敭闈㈡澘 = 200, + /// <summary> + /// 浼犳劅鍣�(1200-2299) + /// </summary> + A浼犳劅鍣� = 1200, + /// <summary> + /// 缁х數鍣�(2300-2499) + /// </summary> + A缁х數鍣� = 2300, + /// <summary> + /// 璋冨厜鍣�(2500-2799) + /// </summary> + A璋冨厜鍣� = 2500, + /// <summary> + /// 鏅鸿兘闂ㄩ攣(2800-????) + /// </summary> + A鏅鸿兘闂ㄩ攣 = 2800, + /// <summary> + /// 绌鸿皟(3600-3899) + /// </summary> + A绌鸿皟 = 3600, + /// <summary> + /// 涓户鍣�(3900-3999) + /// </summary> + A涓户鍣� = 3900, + /// <summary> + /// 鏅鸿兘绌哄紑(4100-4199) + /// </summary> + A鏅鸿兘绌哄紑 = 4100, + /// <summary> + /// 杞崲鍣�(4200-4699) + /// </summary> + A杞崲鍣� = 4200, + /// <summary> + /// 褰╃伅 + /// </summary> + A褰╃伅 = 9, + /// <summary> + /// 娓╂箍搴︿紶鎰熷櫒 + /// </summary> + A娓╂箍搴︿紶鎰熷櫒 = 10, + /// <summary> + /// 娓╁害浼犳劅鍣� + /// </summary> + A娓╁害浼犳劅鍣� = 11, + /// <summary> + /// 婀垮害浼犳劅鍣� + /// </summary> + A婀垮害浼犳劅鍣� = 12, + /// <summary> + /// 寮�鍏� + /// </summary> + A寮�鍏� = 13, + /// <summary> + /// 鎻掑骇 + /// </summary> + A鎻掑骇 = 14, + /// <summary> + /// 鐏厜 + /// </summary> + A鐏厜 = 15, + /// <summary> + /// 骞叉帴鐐� + /// </summary> + A骞叉帴鐐� = 16 + } + + #endregion +} -- Gitblit v1.8.0