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()
{
}
///
/// 获取功能类型
///
///
protected override string GetFunctionType()
{
string type = "Relay";
if (PropertyArray.Contains("brightness"))
{
type = "Dimmer";
if (PropertyArray.Contains("color"))
{
type = "RGB";
}
}
return type;
}
///
/// 开关状态
/// 0:关
/// 1:开
///
public int state = 0;
///
/// 拼接、获取A协议操作数据
///
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;
}
}
}