wxr
2020-05-11 7f233a10afa6882b4d9531185af60e8843bc1af2
HDL_ON/Entity/Function/Function.cs
@@ -28,6 +28,13 @@
        /// 最小值
        /// </summary>
        public int min;
        /// <summary>
        /// 当前值
        /// app软件自定义属性
        /// 用来记录当前状态
        /// </summary>
        public object curValues;
    }
    public class Function
@@ -44,14 +51,14 @@
        */
        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 +82,11 @@
        public string sid = "00010112345678901234560101230123AABB";
        /// <summary>
        /// A协议功能的通行
        /// A协议功能的特性
        /// 如:是AC功能:特性:on_off,mode,fan,temperature
        /// attri
        /// </summary>
        public List<Trait> trait = new List<Trait>();
        public List<Trait> propertList = new List<Trait>();
        /// <summary>
        /// 房间ID列表
@@ -95,10 +102,10 @@
        #endregion
        /// <summary>
        /// 功能附带的属性与值的列表
        /// </summary>
        public Dictionary<string, string> dicPropert;
        ///// <summary>
        ///// 功能附带的属性与值的列表
        ///// </summary>
        //public Dictionary<string, string> dicPropert;
        /// <summary>
        /// 功能类别
@@ -111,7 +118,8 @@
                try
                {
                    var _functionCategoryString = sid.Substring(24, 2);
                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), Convert.ToInt32(_functionCategoryString));
                    var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
                }
                catch (Exception ex)
                {
@@ -154,7 +162,8 @@
        /// </summary>
        public string lastState = "";
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_on_off;
        /// <summary>
        /// 开关状态
        /// 0:关
@@ -167,14 +176,34 @@
            {
                try
                {
                    string o = "off";
                    dicPropert.TryGetValue("on_off", out o);
                    return o == "" ? "off" : o;
                    if (trait_on_off == null)
                    {
                        trait_on_off = propertList.Find((obj) => obj.attri == "on_off");
                        //找不到属性需要声明一个,防止报错闪退
                        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");
                    propertList.Add( new Trait()
                    {
                        attri = "on_off",
                        value = new List<string> { "on", "off" },
                        max = 1,
                        min = 0,
                    });
                    return "off";
                }
            }
@@ -182,12 +211,34 @@
            {
                try
                {
                    dicPropert["on_off"] = value.ToString();
                    if (trait_on_off == null)
                    {
                        trait_on_off = propertList.Find((obj) => obj.attri == "on_off");
                        //找不到属性需要声明一个,防止报错闪退
                        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}");
                    propertList.Add(new Trait()
                    {
                        attri = "on_off",
                        value = new List<string> { "on", "off" },
                        max = 1,
                        min = 0,
                    });
                }
            }
        }
@@ -214,39 +265,6 @@
        /// 固定的序号
        /// </summary>
        public int fixedSerialNumber = int.MaxValue;
        /// <summary>
        /// A协议数据
        /// </summary>
        public List<string> PropertyArray
        {
            get
            {
                try
                {
                    if (trait == null)
                        return new List<string>();
                    var proArr = new List<string>();
                    foreach (var pro in trait)
                    {
                        if (!dicPropert.ContainsKey(pro.attri))
                        {
                            dicPropert.TryAdd(pro.attri, "0");
                        }
                        if (!proArr.Contains(pro.attri))
                        {
                            proArr.Add(pro.attri);
                        }
                    }
                    return proArr;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"Get PropertyArray error : {ex.Message}");
                    return new List<string>();
                }
            }
        }
        /// <summary>
        /// 获取A协议控制字符串