wxr
2020-09-09 c3e1b733fc45bd9f0b88bfb560cfa87a270b079b
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Shared;
 
namespace HDL_ON.Entity
{
    public class AC : Function
    {
        /*
         * 空调:trait: [switch, mode, fan, temperature, swing, lock]
         * 属性    描述
         * on_off    on/off
         * mode    mode: auto, cool, heat, dry, fan
         * fan    high, medium, low, auto
         * temperature    up,down,value
         * swing    up/down/left/right
         * lock    boolean (Lock锁定控制)
         */
        public AC()
        {
        }
        /// <summary>
        /// 当前温度模式
        /// 0:摄氏度
        /// 1:华氏度
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int curTempType = 0;
        /// <summary>
        /// 当前温度模式字符
        /// </summary>
        public string tempUnitString
        {
            get
            {
                if (curTempType == 0)
                {
                    return "°C";
                }
                else
                {
                    return "°F";
                }
            }
        }
 
        /// <summary>
        /// 当前模式索引
        /// bus控制命令使用
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public byte curModeIndex
        {
            get
            {
                try
                {
                    byte index = 0;
                    switch (trait_mode.value.ToString())
                    {
                        case "auto":
                            index = 3;
                            break;
                        case "cool":
                            index = 0;
                            break;
                        case "heat":
                            index = 1;
                            break;
                        case "dry":
                            index = 4;
                            break;
                        case "fan":
                            index = 2;
                            break;
                        default:
                            index = 0;
                            break;
                    }
                    return index;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"get curModeIndex error : {ex.Message}");
                    return 0;
                }
            }
            set
            {
                switch (value)
                {
                    case 0:
                        trait_mode.value = "cool";
                        break;
                    case 1:
                        trait_mode.value = "heat";
                        break;
                    case 2:
                        trait_mode.value = "fan";
                        break;
                    case 3:
                        trait_mode.value = "auto";
                        break;
                    case 4:
                        trait_mode.value = "dry";
                        break;
                    default:
                        trait_mode.value = "cool";
                        break;
 
                }
            }
        }
        /// <summary>
        /// 当前风速索引
        /// bus控制命令使用
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public byte curFanIndex
        {
            get
            {
                try
                {
                    byte index = 0;
                    switch (trait_fan.value.ToString())
                    {
                        case "high":
                            index = 1;
                            break;
                        case "medium":
                            index = 2;
                            break;
                        case "low":
                            index = 3;
                            break;
                        case "auto":
                            index = 0;
                            break;
                        default:
                            index = 0;
                            break;
                    }
                    return index;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"get curFanIndex error : {ex.Message}");
                    return 0;
                }
            }
            set
            {
                switch (value)
                {
                    case 0:
                        trait_fan.value = "auto";
                        break;
                    case 1:
                        trait_fan.value = "high";
                        break;
                    case 2:
                        trait_fan.value = "medium";
                        break;
                    case 3:
                        trait_fan.value = "low";
                        break;
                    default:
                        trait_fan.value = "high";
                        break;
                }
            }
        }
 
        Trait _trait_mode;
        /// <summary>
        /// 模式属性
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_mode
        {
            get
            {
                if (_trait_mode == null)
                {
                    _trait_mode = function.Find((obj) => obj.name == "mode");
                    //找不到属性需要声明一个,防止报错闪退
                    if (_trait_mode == null)
                    {
                        _trait_mode = new Trait()
                        {
                            name = "mode",
                            value_key = new List<string> { "auto", "cool", "heat", "dry", "fan" },
                            max = 4,
                            min = 0,
                        };
                    }
                    _trait_mode.value = _trait_mode.value_key.Count > 0 ? _trait_mode.value_key[0] : "";
                }
                return _trait_mode;
            }
        }
 
        Trait _trait_fan;
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_fan
        {
            get
            {
                if (_trait_fan == null)
                {
                    _trait_fan = function.Find((obj) => obj.name == "fan");
                    //找不到属性需要声明一个,防止报错闪退
                    if (_trait_fan == null)
                    {
                        _trait_fan = new Trait()
                        {
                            name = "fan",
                            value_key = new List<string> { "high", "medium", "low", "auto" },
                            max = 3,
                            min = 0,
                        };
                    }
                    _trait_fan.value = _trait_fan.value_key.Count > 0 ? _trait_fan.value_key[0] : "";
                }
                return _trait_fan;
            }
        }
 
        Trait _trait_temp;
        /// <summary>
        /// 当前空调温度
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_temp
        {
            get
            {
                if (_trait_temp == null)
                {
                    _trait_temp = function.Find((obj) => obj.name == "temperature");
                    //找不到属性需要声明一个,防止报错闪退
                    if (_trait_temp == null)
                    {
                        _trait_temp = new Trait()
                        {
                            name = "temperature",
                            value_key = new List<string> { },
                            max = 32,
                            min = 16,
                        };
                    }
                    _trait_temp.value = 16;
                }
                return _trait_temp;
            }
        }
 
 
        Trait _trait_swting;
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_swting
        {
            get
            {
                if (_trait_swting == null)
                {
                    _trait_swting = function.Find((obj) => obj.name == "swting");
                    //找不到属性需要声明一个,防止报错闪退
                    if (_trait_swting == null)
                    {
                        _trait_swting = new Trait()
                        {
                            name = "swting",
                            value_key = new List<string> { "up", "down", "left", "right" },
                            max = 3,
                            min = 0,
                        };
                    }
                    _trait_swting.value = _trait_swting.value_key.Count > 0 ? _trait_swting.value_key[trait_mode.min] : "";
                }
                return _trait_swting;
            }
        } 
        /// <summary>
        /// 空调扫风模式列表
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<string> swting
        {
            get
            {
                try
                {
                    return trait_swting.value_key;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"ac get swting error : {ex.Message}");
                    return new List<string> { "up", "down", "left", "right" };
                }
            }
        }
        /// <summary>
        /// 室内温度
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int indoorTemp = 20;
 
        /// <summary>
        /// 当前模式的icon路径
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string curModeImage
        {
            get
            {
                try
                {
                    var imagePath = "FunctionIcon/AC/CoolIcon.png";
                    switch (trait_mode.value.ToString())
                    {
                        case "auto":
                            imagePath = "FunctionIcon/AC/AutoIcon.png";
                            break;
                        case "cool":
                            imagePath = "FunctionIcon/AC/CoolIcon.png";
                            break;
                        case "heat":
                            imagePath = "FunctionIcon/AC/HeatingIcon.png";
                            break;
                        case "dry":
                            imagePath = "FunctionIcon/AC/DehumidificationIcon.png";
                            break;
                        case "fan":
                            imagePath = "FunctionIcon/AC/AirSupplyIcon.png";
                            break;
                        default:
                            imagePath = "FunctionIcon/AC/CoolIcon.png";
                            break;
                    }
                    return imagePath;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"ac ge curModeImage error : {ex.Message}");
                    return "FunctionIcon/AC/CoolIcon.png";
                }
            }
        }
        /// <summary>
        /// 当前风速的icon路径
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string curFanImage
        {
            get
            {
                try
                {
                    var imagePath = "FunctionIcon/AC/WindHighIcon.png";
                    switch (trait_fan.value.ToString())
                    {
                        case "high":
                            imagePath = "FunctionIcon/AC/WindHighIcon.png";
                            break;
                        case "medium":
                            imagePath = "FunctionIcon/AC/WindMediumIcon.png";
                            break;
                        case "low":
                            imagePath = "FunctionIcon/AC/WindLowIcon.png";
                            break;
                        case "auto":
                            imagePath = "FunctionIcon/AC/AutoIcon.png";
                            break;
                        default:
                            imagePath = "FunctionIcon/AC/WindHighIcon.png";
                            break;
                    }
                    return imagePath;
                }catch (Exception ex)
                {
                    MainPage.Log($"ac get curFanImage error : {ex.Message}");
                    return "FunctionIcon/AC/WindHighIcon.png";
                }
            }
        }
 
    }
}