gxc
2019-11-07 a4924de3136289d10cabbf2f61a228387d44ded7
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceAirConditionerLogic.cs
New file
@@ -0,0 +1,182 @@
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="device">空调对象</param>
        /// <param name="data">从二进制转换的十进制值</param>
        /// <returns></returns>
        public async Task<bool> SetAcModeSupport(AC device, int data)
        {
            var result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(device, 513, 4099, 25, data);
            //检测网关返回的共通错误状态码
            string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
            if (error != null)
            {
                this.ShowTipMsg(error);
                return false;
            }
            if (result == null || result.setWritableValueResponData == null)
            {
                //设置空调模式失败
                string msg = Language.StringByID(R.MyInternationalizationString.uSetAcModeFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
                this.ShowTipMsg(msg); ;
                return false;
            }
            if (result.setWritableValueResponData.Status != 0)
            {
                //设置空调模式失败
                string msg = Language.StringByID(R.MyInternationalizationString.uSetAcModeFail);
                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
    }
}