HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-28 8b4d79ca03495e522a1953e04ca17527f33c853a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
    }
}