using System; using Newtonsoft.Json.Linq; namespace ZigBee.Device { [System.Serializable] public class FreshAir : Panel { /// /// 该类(新风对象)包含新风设备和新风面板 /// public FreshAir() { this.Type = DeviceType.FreshAir; } /// /// 风速模式 /// 5:自动 /// 6:Smart /// 15:手动 /// [Newtonsoft.Json.JsonIgnore] public int currentFanMode = 0; /// /// 风速档位 /// 1:低风 /// 2:中风 /// 3:高风 /// [Newtonsoft.Json.JsonIgnore] public int currentFanSpeed = 0; /// /// 风扇状态 /// 0:关闭 /// 4:打开 /// [Newtonsoft.Json.JsonIgnore] public int currentFanStatus = 0; /// /// 关闭 /// /// The close. public async System.Threading.Tasks.Task Close() { return await SetFanModeAsync(FanMode.Off); } /// /// 开启 /// /// The open. public async System.Threading.Tasks.Task Open() { return await SetFanModeAsync(FanMode.On); } /// /// 高风 /// /// The close. public async System.Threading.Tasks.Task SetHighSpeed() { return await SetFanModeAsync(FanMode.High); } /// /// 低风 /// /// The open. public async System.Threading.Tasks.Task SetLowSpeed() { return await SetFanModeAsync(FanMode.Low); } /// /// 手动 /// /// The close. public async System.Threading.Tasks.Task SetManual() { return await SetFanModeAsync(FanMode.Manual); } /// /// 自动 /// /// The open. public async System.Threading.Tasks.Task SetAuto() { return await SetFanModeAsync(FanMode.Auto); } /// ///设置恒温器设备当前风速. /// public async System.Threading.Tasks.Task SetFanModeAsync(FanMode fanMode) { 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", DeviceEpoint }, { "Cluster_ID", 514 }, { "Command", 120 } }; var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0 }, { "AttributeDataType", 48 }, { "AttributeData", (int)fanMode } }; 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; }); } #region ◆ 当前新风开关状态____________________ /// /// 当前新风开关状态 /// /// /// public bool IsOpen(FreshAir freshAir) { if (freshAir.currentFanStatus == 4) { return true; } return false; } #endregion /// /// 风速档位 /// public enum FanMode { /// /// 关闭 /// Off = 0, /// /// 低风 /// Low = 1, /// /// 中风 /// Medium = 2, /// /// 高风 /// High = 3, /// /// 打开 /// On = 4, /// /// 自动 /// Auto = 5, /// /// Smart /// Smart = 6, /// /// 手动 /// Manual = 15, } } }