wxr
2020-03-13 171bf03f3664226eeff2b20ee9bd2e914b63a17d
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
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
 
namespace HDL_ON.Entity
{
    public class Light : Function
    {
        /*
        灯光类:trait: [switch,brightness,color,cct,delay,fadeTime]
        属性    描述
        switch    on/off;
        brightness    0-100;
        color    int (red (0-255) green (0-255) blue (0-255))
        cct    int (warm light(0-255) cold light (0-255) )
        delay    0-3600s
        fadetime    0-3600s
        */
        public Light()
        {
        }
        /// <summary>
        /// 获取功能类型
        /// </summary>
        /// <returns></returns>
        protected override string GetFunctionType()
        {
            string type = "Relay";
            if (PropertyArray.Contains("brightness"))
            {
                type = "Dimmer";
                if (PropertyArray.Contains("color"))
                {
                    type = "RGB";
                }
            }
            return type;
        }
 
        /// <summary>
        /// 开关状态
        /// 0:关
        /// 1:开
        /// </summary>
        public int state = 0;
 
 
        /// <summary>
        /// 拼接、获取A协议操作数据
        /// </summary>
        public override JObject GetSendJObject(string command )
        {
            var sendJob = new JObject();
            if (command == "write")
            {
 
                sendJob = new JObject { { "Namespace", a_Protocol_Namespace }, { "Command", command }, { "Type", "device" } };
                JObject data = null;
                switch (functionType)
                {
                    case "Relay"://继电器控制
                        data = new JObject { { "switch", state }, { "sid", sid } };
                        break;
                    case "Dimmer":
                        data = new JObject { { "switch", state }, { "brightness", dicPropert["brightness"] }, { "sid", sid } };
                        break;
                }
                sendJob.Add("objects", data);
            }
            else if(command == "read")
            {
                sendJob = new JObject { { "Namespace", a_Protocol_Namespace }, { "Command", command }, { "Type", "device" } };
                var data = new JObject {{ "sid", sid } };
                sendJob.Add("objects", data);
            }
            return sendJob;
        }
    }
}