From 5de5a26d3825b3182a7d3a18ed1cbdbb78a3f9aa Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期四, 23 七月 2020 16:39:59 +0800 Subject: [PATCH] 2020-07-23 --- HDL_ON/Entity/Function/Function.cs | 166 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 107 insertions(+), 59 deletions(-) diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs index b7a8a44..64225a0 100644 --- a/HDL_ON/Entity/Function/Function.cs +++ b/HDL_ON/Entity/Function/Function.cs @@ -19,7 +19,7 @@ /// <summary> /// 灞炴�х殑鍊� /// </summary> - public string value; + public List<string> value; /// <summary> /// 鏈�澶у�� /// </summary> @@ -28,6 +28,18 @@ /// 鏈�灏忓�� /// </summary> public int min; + + /// <summary> + /// + /// </summary> + public string data_type = ""; + + /// <summary> + /// 褰撳墠鍊� + /// app杞欢鑷畾涔夊睘鎬� + /// 鐢ㄦ潵璁板綍褰撳墠鐘舵�� + /// </summary> + public object curValues; } public class Function @@ -41,17 +53,18 @@ 鏁版嵁琛ㄧ储寮曞湴鍧�锛�2bytes 鍥炶矾锛�2bytes 涓句緥锛� 0001-00-2019101209001234-01-0001-0001 + 0001-01-14051D0A300C92C9-02-0202-0001-0001 */ public Function() { - dicPropert = new Dictionary<string, string>(); - if (trait == null || trait.Count == 0) - { - foreach (var t in trait) - { - dicPropert.TryAdd(t.attri,t.min.ToString()); - } - } + //dicPropert = new Dictionary<string, string>(); + //if (propertList == null || propertList.Count == 0) + //{ + // foreach (var t in propertList) + // { + // dicPropert.TryAdd(t.attri,t.min.ToString()); + // } + //} } #region base info /// <summary> @@ -75,11 +88,11 @@ public string sid = "00010112345678901234560101230123AABB"; /// <summary> - /// A鍗忚鍔熻兘鐨勯�氳 + /// A鍗忚鍔熻兘鐨勭壒鎬� /// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature /// attri /// </summary> - public List<Trait> trait = new List<Trait>(); + public List<Trait> function = new List<Trait>(); /// <summary> /// 鎴块棿ID鍒楄〃 @@ -95,10 +108,10 @@ #endregion - /// <summary> - /// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃 - /// </summary> - public Dictionary<string, string> dicPropert; + ///// <summary> + ///// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃 + ///// </summary> + //public Dictionary<string, string> dicPropert; /// <summary> /// 鍔熻兘绫诲埆 @@ -108,8 +121,17 @@ { get { - var _functionCategoryString = sid.Substring(22, 2); - return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), Convert.ToInt32(_functionCategoryString)); + try + { + var _functionCategoryString = sid.Substring(24, 2); + var _functionCategory = Convert.ToInt32(_functionCategoryString, 16); + return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory); + } + catch (Exception ex) + { + MainPage.Log($"get FunctionCategory error : {ex.Message}"); + return FunctionCategory.UnKown; + } } } @@ -135,7 +157,7 @@ { string vendorCode = "HDL"; var code = sid.Substring(0, 4); - if (code == "00001") + if (code == "0001") vendorCode = "HDL"; return vendorCode; } @@ -146,7 +168,8 @@ /// </summary> public string lastState = ""; - + [Newtonsoft.Json.JsonIgnore] + public Trait trait_on_off; /// <summary> /// 寮�鍏崇姸鎬� /// 0:鍏� @@ -159,14 +182,34 @@ { try { - string o = "off"; - dicPropert.TryGetValue("on_off", out o); - return o == "" ? "off" : o; + if (trait_on_off == null) + { + trait_on_off = function.Find((obj) => obj.attri == "on_off"); + //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂�� + if (trait_on_off == null) + { + trait_on_off = new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }; + } + trait_on_off.curValues = trait_on_off.value[trait_on_off.min]; + } + return trait_on_off.curValues.ToString(); } catch { MainPage.Log("on_off 鏁版嵁鑾峰彇澶辫触."); - dicPropert.TryAdd("on_off", "0"); + function.Add( new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }); return "off"; } } @@ -174,12 +217,34 @@ { try { - dicPropert["on_off"] = value.ToString(); + if (trait_on_off == null) + { + trait_on_off = function.Find((obj) => obj.attri == "on_off"); + //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂�� + if (trait_on_off == null) + { + trait_on_off = new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }; + } + trait_on_off.curValues = trait_on_off.min; + } + trait_on_off.curValues = value; } - catch + catch (Exception ex) { - MainPage.Log("on_off 鏁版嵁鍒锋柊澶辫触."); - dicPropert.TryAdd("on_off", value.ToString()); + MainPage.Log($"on_off 鏁版嵁鍒锋柊澶辫触: {ex.Message}"); + function.Add(new Trait() + { + attri = "on_off", + value = new List<string> { "on", "off" }, + max = 1, + min = 0, + }); } } } @@ -196,49 +261,25 @@ /// <summary> /// 浣跨敤棰戠巼 /// </summary> - public double usageFrequency = 0; + public double usageFrequency { + get + { + return usageCount / 7; + } + } /// <summary> /// 鍥哄畾鐨勫簭鍙� /// </summary> public int fixedSerialNumber = int.MaxValue; /// <summary> - /// A鍗忚鏁版嵁 - /// </summary> - public List<string> PropertyArray - { - get - { - try - { - if (trait == null) - return new List<string>(); - var proArr = trait.Split(',').ToList(); - foreach (var pro in proArr) - { - if (!dicPropert.ContainsKey(pro)) - { - dicPropert.TryAdd(pro, "0"); - } - } - return proArr; - } - catch (Exception ex) - { - MainPage.Log($"Get PropertyArray error : {ex.Message}"); - return new List<string>(); - } - } - } - - /// <summary> /// 鑾峰彇A鍗忚鎺у埗瀛楃涓� /// </summary> /// <param name="command">鎺у埗鍛戒护锛歸rite锛宺ead</param> /// <returns></returns> - public virtual JObject GetSendJObject(string command) + public virtual JObject GetSendJObject(CommandType_A command) { - var sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command }, { "Type", "device" }, }; + var sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" }, }; var data = new JObject { { "sid", sid } }; sendJob.Add("objects", data); return sendJob; @@ -264,6 +305,8 @@ foreach(var roomId in roomIdList) { var findRoom = DB_ResidenceData.residenceData.rooms.Find(obj => obj.sid == roomId); + if (findRoom == null) + continue; if(roomNameList != "") { roomNameList += ","; @@ -272,5 +315,10 @@ } return roomNameList; } + + /// <summary> + /// 鏇存柊鏃堕棿 + /// </summary> + public DateTime refreshTime = DateTime.MinValue; } } -- Gitblit v1.8.0