wxr
2020-09-09 c3e1b733fc45bd9f0b88bfb560cfa87a270b079b
HDL_ON/Entity/Function/Curtain.cs
@@ -7,48 +7,48 @@
    public class Curtain : Function
    {
        /*
        窗帘属性列表:trait: [switch,openLevel,lock]
        窗帘属性列表:trait: [switch,percent,lock]
        属性   描述
        on_off   on/off/stop;
        openLevel   0-100;
        percent   0-100;
        lock   boolean (Lock锁定控制)
        */
        public Curtain()
        {
        }
        }//percent
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_openLevel;
        public Trait trait_percent;
        /// <summary>
        /// 开关百分比
        /// 0-100
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int openLevel
        public int percent
        {
            get
            {
                try
                {
                    if(trait_openLevel==null)
                    if(trait_percent==null)
                    {
                        trait_openLevel = function.Find((obj) => obj.name == "openLevel");
                        if (trait_openLevel == null)
                        trait_percent = function.Find((obj) => obj.name == "percent");
                        if (trait_percent == null)
                        {
                            trait_openLevel = new Trait()
                            trait_percent = new Trait()
                            {
                                name = "openLevel",
                                name = "percent",
                                value_key = new List<string> { "up", "down" },
                                max = 100,
                                min = 0,
                            };
                        }
                        trait_openLevel.value = trait_openLevel.min;
                        trait_percent.value = trait_percent.min;
                    }
                    return Convert.ToInt32( trait_openLevel.value);
                    return Convert.ToInt32( trait_percent.value);
                }
                catch
                {
                    MainPage.Log("openLevel 数据获取失败.");
                    MainPage.Log("percent 数据获取失败.");
                    return 0;
                }
            }
@@ -56,46 +56,14 @@
            {
                try
                {
                    trait_openLevel.value = value;
                    trait_percent.value = value;
                }
                catch
                {
                    MainPage.Log("openLevel 数据刷新失败.");
                    MainPage.Log("percent 数据刷新失败.");
                }
            }
        }
        /// <summary>
        /// 拼接、获取A协议操作数据
        /// </summary>
        public override JObject GetSendJObject(CommandType_A command)
        {
            var sendJob = new JObject();
            if (command == CommandType_A.write)
            {
                sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } };
                JObject data = null;
                switch (functionType)
                {
                    case FunctionType.Curtain:
                        data = new JObject { { "on_off", trait_on_off.value.ToString() }, { "sid", sid } };
                        break;
                    case FunctionType.MotorCurtain:
                    case FunctionType.RollingShutter:
                        data = new JObject { { "openLevel", openLevel}, { "sid", sid } };
                        break;
                }
                sendJob.Add("objects", data);
            }
            else if (command == CommandType_A.read)
            {
                sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } };
                var data = new JObject { { "sid", sid } };
                sendJob.Add("objects", data);
            }
            return sendJob;
        }
    }
}