using System;
using Newtonsoft.Json.Linq;
namespace ZigBee.Device
{
[System.Serializable]
public class FreshAir : Panel
{
///
/// 该类(新风对象)包含新风设备和新风面板
///
public FreshAir()
{
this.Type = DeviceType.FreshAir;
}
///
/// 恒温设备当前模式
/// 恒温设备具备功能,SystemMode Attribute Values如下
/// 0:Off
/// 1:Auto
/// 3:Cool
/// 4:Heat
/// 5:Emergency heating
/// 6:Precooling
/// 7:Fan only
/// 8:Dry
/// 9:Sleep
///
public int currentSystemMode = 0;
///
///设置恒温器设备当前工作模式.
///
public async System.Threading.Tasks.Task SetSystemModeAsync(AcMode acMode)
{
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 gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
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 gatewayTemp = new ZbGateway() { DeviceID = jobject.Value("Device_ID"), DeviceAddr = jobject.Value("DeviceAddr"), DeviceEpoint = jobject.Value("Epoint"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
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", DeviceEpoint }, { "Cluster_ID", 513 }, { "Command", 120 } };
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 28 }, { "AttributeDataType", 48 }, { "AttributeData", (int)acMode } };
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;
});
}
public enum AcMode
{
///
/// 关闭模式(测试恒温面板时发现:2,5,6,7,8,9都是可以打开的)
///
Off = 0,
///
/// 自动模式
///
Auto = 1,
///
/// 制冷模式
///
Cool = 3,
///
/// 制热模式
///
Heat = 4,
///
/// 紧急制热模式
///
EmergencyHeating = 5,
///
/// 预冷模式
///
Precooling = 6,
///
/// 只有风速模式
///
FanOnly = 7,
///
/// 干燥模式
///
Dry = 8,
///
/// 睡眠模式
///
Sleep = 9
}
///
/// 关闭
///
/// The close.
public async System.Threading.Tasks.Task Close()
{
return await SetSystemModeAsync(AcMode.Off);
}
///
/// 开启
///
/// The open.
/// Ac mode.
public async System.Threading.Tasks.Task Open(AcMode acMode = AcMode.Cool)
{
return await SetSystemModeAsync(acMode);
}
}
}