HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-11-13 8b9ce384b26c414db32f98e94e088f5334869c2d
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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;
            }
            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A空调自定义模式, data);
 
            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
    }
}