wxr
2020-06-08 b71dfb3ca100340005d56e1298292807da82322d
HDL_ON/Entity/Function/Light.cs
@@ -32,7 +32,7 @@
            {
                if (trait_brightness == null)
                {
                    trait_brightness = propertList.Find((obj) => obj.attri == "brightness");
                    trait_brightness = function.Find((obj) => obj.attri == "brightness");
                    //找不到属性需要声明一个,防止报错闪退
                    if (trait_brightness == null)
                    {
@@ -54,7 +54,7 @@
                {
                    if (trait_brightness == null)
                    {
                        trait_brightness = propertList.Find((obj) => obj.attri == "brightness");
                        trait_brightness = function.Find((obj) => obj.attri == "brightness");
                        //找不到属性需要声明一个,防止报错闪退
                        if (trait_brightness == null)
                        {
@@ -91,7 +91,7 @@
            {
                if (trait_color == null)
                {
                    trait_color = propertList.Find((obj) => obj.attri == "color");
                    trait_color = function.Find((obj) => obj.attri == "color");
                    //找不到属性需要声明一个,防止报错闪退
                    if (trait_color == null)
                    {
@@ -212,29 +212,92 @@
            if (command == CommandType_A.write)
            {
                sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } };
                JObject data = null;
#if DEBUG
                switch(sid)
                {
                    case "00010114051D0A300C92C902020200010001":
                        sid = "00010114041710193123D402020200010001";
                        break;
                    case "00010114051D0A300C92C902020200020001":
                        sid = "00010114041710193123D402020200020001";
                        break;
                    case "00010114051D0A300C92C902020200030001":
                        sid = "00010114041710193123D402020200030001";
                        break;
                    case "00010114051D0A300C92C902020200040001":
                        sid = "00010114041710193123D402020200040001";
                        break;
                }
#endif
                sendJob = new JObject { { "vendor_code", vendor_code }, { "command", command.ToString() }, { "type", "device" } };
                JObject data = new JObject { { "sid", sid } };
                sendJob.Add("objects", data);
                List<ControlData> controlData = new List<ControlData>();
                switch (functionType)
                {
                    case FunctionType.Relay:
                        data = new JObject { { "sid", sid }, { "switch", on_off } };
                        controlData.Add(new ControlData()
                        {
                            name = "on_off",
                            data_type = "Bool",
                            value = on_off
                        });
                        break;
                    case FunctionType.Dimmer:
                        data = new JObject { { "sid", sid }, { "brightness", brightness } };
                        controlData.Add(new ControlData()
                        {
                            name = "on_off",
                            data_type = "Bool",
                            value = on_off
                        });
                        controlData.Add(new ControlData()
                        {
                            name = "brightness",
                            data_type = "int",
                            value = brightness.ToString(),
                        });
                        break;
                    case FunctionType.RGB:
                        data = new JObject { { "sid", sid }, { "brightness", brightness }, { "color", color } };
                        controlData.Add(new ControlData()
                        {
                            name = "on_off",
                            data_type = "Bool",
                            value = on_off
                        });
                        controlData.Add(new ControlData()
                        {
                            name = "brightness",
                            data_type = "int",
                            value = brightness.ToString(),
                        });
                        controlData.Add(new ControlData()
                        {
                            name = "brightness",
                            data_type = "int",
                            value = color.ToString(),
                        });
                        break;
                }
                sendJob.Add("objects", data);
                AProtocolEntity ape = new AProtocolEntity()
                {
                    command = command.ToString(),
                    vendor_code = vendor_code,
                    type = "device_sid",
                };
                ape.ControlFunction(sid, controlData);
                sendJob = JObject.FromObject(ape);
            }
            else if (command == CommandType_A.read)
            {
                sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } };
                sendJob = new JObject { { "vendor_code", vendor_code }, { "command", command.ToString() }, { "type", "device" } };
                var data = new JObject {{ "sid", sid } };
                sendJob.Add("objects", data);
            }
            return sendJob;
        }
    }
}