wxr
2020-08-13 6a9ad7ec93218913a2ce3b898bb036f18f8f0da4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
 
namespace HDL_ON.Entity
{
    public class Curtain : Function
    {
        /*
        窗帘属性列表:trait: [switch,openLevel,lock]
        属性    描述
        on_off    on/off/stop;
        openLevel    0-100;
        lock    boolean (Lock锁定控制)
        */
        public Curtain()
        {
        }
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_openLevel;
        /// <summary>
        /// 开关百分比
        /// 0-100
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int openLevel
        {
            get
            {
                try
                {
                    if(trait_openLevel==null)
                    {
                        trait_openLevel = function.Find((obj) => obj.attri == "openLevel");
                        if (trait_openLevel == null)
                        {
                            trait_openLevel = new Trait()
                            {
                                attri = "openLevel",
                                value = new List<string> { "up", "down" },
                                max = 100,
                                min = 0,
                            };
                        }
                        trait_openLevel.curValues = trait_openLevel.min;
                    }
                    return Convert.ToInt32( trait_openLevel.curValues);
                }
                catch
                {
                    MainPage.Log("openLevel 数据获取失败.");
                    return 0;
                }
            }
            set
            {
                try
                {
                    trait_openLevel.curValues = value;
                }
                catch
                {
                    MainPage.Log("openLevel 数据刷新失败.");
                }
            }
        }
 
        /// <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", on_off }, { "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;
        }
 
 
    }
}