using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Threading.Tasks;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 空调的逻辑
|
/// </summary>
|
public class HdlDeviceAirConditionerLogic
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 空调的逻辑
|
/// </summary>
|
private static HdlDeviceAirConditionerLogic m_Current = null;
|
/// <summary>
|
/// 空调的逻辑
|
/// </summary>
|
public static HdlDeviceAirConditionerLogic Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
m_Current = new HdlDeviceAirConditionerLogic();
|
}
|
return m_Current;
|
}
|
}
|
|
#endregion
|
|
#region ■ 打开空调___________________________
|
|
/// <summary>
|
/// 打开空调
|
/// </summary>
|
/// <param name="device">空调对象</param>
|
/// <returns></returns>
|
public async Task<bool> OpenAirConditioner(AC device)
|
{
|
var result = await device.Open();
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
|
{
|
//打开空调失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//打开空调失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uOpenAirConditionerFail);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 打开空调___________________________
|
|
/// <summary>
|
/// 打开空调
|
/// </summary>
|
/// <param name="device">空调对象</param>
|
/// <returns></returns>
|
public async Task<bool> CloseAirConditioner(AC device)
|
{
|
var result = await device.Close();
|
//检测网关返回的共通错误状态码
|
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
if (error != null)
|
{
|
this.ShowTipMsg(error);
|
return false;
|
}
|
if (result == null || result.setWritableValueResponData == null || result.setWritableValueResponData.Status != 0)
|
{
|
//关闭空调失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
|
//拼接上【网关回复超时】的Msg
|
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
if (result.setWritableValueResponData.Status != 0)
|
{
|
//关闭空调失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uCloseAirConditionerFail);
|
this.ShowTipMsg(msg);
|
return false;
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 显示错误信息窗口
|
/// </summary>
|
/// <param name="msg"></param>
|
private void ShowErrorMsg(string msg)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var contr = new ShowMsgControl(ShowMsgType.Error, msg);
|
contr.Show();
|
});
|
}
|
|
/// <summary>
|
/// 显示Tip信息窗口
|
/// </summary>
|
/// <param name="msg"></param>
|
private void ShowTipMsg(string msg)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
|
contr.Show();
|
});
|
}
|
|
#endregion
|
}
|
}
|