using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace ZigBee.Device
{
///
///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
///
[System.Serializable]
public class Airer : CommonDevice
{
public Airer()
{
this.Type = DeviceType.Airer;
}
///
/// 开光状态:0=关,1=开,
///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
///
[Newtonsoft.Json.JsonIgnore]
public int OnOffStatus = 0;
///
/// 烘干状态:0=关,1=开,
///
[Newtonsoft.Json.JsonIgnore]
public int DryOnOffStatus = 0;
///
/// 风干状态:0=关,1=开,
///
[Newtonsoft.Json.JsonIgnore]
public int WindOnOffStatus = 0;
///
/// 消毒状态:0=关,1=开,
///
[Newtonsoft.Json.JsonIgnore]
public int DisinfectOnOffStatus = 0;
///
/// 烘干时间
///
[Newtonsoft.Json.JsonIgnore]
public int DryTime = 0;
///
/// 剩余烘干时间 (默认0秒)
///
[Newtonsoft.Json.JsonIgnore]
public int DryRemainTime = 0;
///
/// 风干时间
///
[Newtonsoft.Json.JsonIgnore]
public int WindTime = 0;
///
/// 剩余风干时间 (默认0秒)
///
[Newtonsoft.Json.JsonIgnore]
public int WindRemainTime = 0;
///
/// 消毒时间
///
[Newtonsoft.Json.JsonIgnore]
public int DisinfectTime = 0;
///
/// 剩余消毒时间 (默认0秒)
///
[Newtonsoft.Json.JsonIgnore]
public int DisinfectRemainTime = 0;
#region 开关
///
///衣架开关停控制
/// command的值
///0 : 衣架设备上拉或打开
///1: 衣架设备下降或关闭
///2:衣架设备停止
///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
///
public void AirerUpDownStopControl(int command)
{
var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", command }, { "SendMode", 2 } };
Gateway?.Send("DeviceControl", jobject.ToString());
System.Console.WriteLine("CurtainOpenControl_发送数据" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString());
}
#endregion
#region ■ 设备时间设置___________________________
///
///设备时间设
///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
///
public async System.Threading.Tasks.Task SetAirerTimeAsync(int time, int controlEpoint)
{
if (Gateway == null)
{
return null;
}
return await System.Threading.Tasks.Task.Run(async () =>
{
SetWritableValueResponAllData d = null;
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "SetWritableValue_Respon")
{
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (tempData == null)
{
d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
DebugPrintLog($"UI收到通知后的主题_{ topic}");
}
}
};
Gateway.Actions += action;
DebugPrintLog("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString());
try
{
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", controlEpoint }, { "Cluster_ID", 6 }, { "Command", 120 } };
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 16385 }, { "AttributeDataType", 33 }, { "AttributeData", time } };
jObject.Add("Data", data);
Gateway.Send("SetWritableValue", jObject.ToString());
}
catch { }
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" };
}
Gateway.Actions -= action;
DebugPrintLog("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
#endregion
#region ■ 设备时间设置___________________________
///
/// 设置时间到衣架
///注意事项:晾衣架,只显示并存储1端点,其他端点(2~5)过滤,不存储,
///因为其他端点只有控制作用,(端点2:控制照明,端点3:控制风干,端点4:控制烘干,端点5:控制消毒)
///
public async void SetAirerFunTimeDevice(int time, int controlEpoint)
{
await SetAirerTimeAsync(time, controlEpoint);
}
#endregion
#region 开关
///
///开关控制(仅用于cluster=6的设备)
/// 设备支持cluster=6的设备才能调用该接口
/// command的值
///0 : 关闭
///1: 打开
///2:取反
///
public void SwitchControl(int command, int ctrlEpoint)
{
try
{
var jobject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", ctrlEpoint }, { "Cluster_ID", 6 }, { "Command", command }, { "SendMode", 2 } };
Gateway?.Send(("DeviceControl"), jobject.ToString());
System.Console.WriteLine("SwitchControl_发送数据" + "_" + jobject.ToString() + "_" + System.DateTime.Now.ToString());
}
catch { }
}
#endregion
}
}