wei
2021-08-20 41995c4cd30ca1c5a814ea0af6f70d3b86368137
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
using System;
using System.Collections.Generic;
using HDL_ON.Common;
using Shared;
 
namespace HDL_ON.Entity
{
    public class SecurityAlarm
    {
        /// <summary>
        /// 安防sid
        /// </summary>
        public string sid;
        /// <summary>
        /// 安防名称
        /// </summary>
        public string name;
        /// <summary>
        /// 安防延时
        /// </summary>
        public string delay;
        /// <summary>
        /// 状态 enable布防、disable撒防
        /// </summary>
        public string status;
        /// <summary>
        /// 类型
        /// "all"--全宅布防,
        /// "normal"--普通模式,
        /// "all_day":24小时,
        /// "mute":静音
        /// </summary>
        public string type;
        /// <summary>
        /// 更新时间
        /// </summary>
        public string modifyTime;
        /// <summary>
        /// 安防输入条件
        /// </summary>
        public List<SecurityInput> input = new  List<SecurityInput>();
        /// <summary>
        /// 安防输出
        /// </summary>
        public List<SecurityOutput> output = new List<SecurityOutput>();
        /// <summary>
        /// 安防通知配置
        /// </summary>
        public SecurityNoticeConfig noticeConfig = new SecurityNoticeConfig();
        /// <summary>
        /// 安防推送配置
        /// </summary>
        public List<SecurityPushConfig> pushConfigs = new List<SecurityPushConfig>();
 
        /// <summary>
        /// 数据存储文件名
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string savePath
        {
            get
            {
                return "SecurityData_" + sid;
            }
        }
        /// <summary>
        /// 保存文件
        /// </summary>
        public void SaveFile()
        {
            var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
            FileUtlis.Files.WriteFileByBytes(savePath, ssd);
        }
    }
 
    /// <summary>
    /// 安防状态配置
    /// </summary>
    public class SecurityState
    {
        /// <summary>
        /// 安防云端id
        /// </summary>
        public string userSecurityId;
        /// <summary>
        /// 网关id 网关id 如果传的是sid该字段需要传
        /// </summary>
        public string gatewayId;
        /// <summary>
        /// 安防sid
        /// </summary>
        public string sid;
        /// <summary>
        /// 状态 enable布防、disable撒防
        /// </summary>
        public string status;
    }
 
    /// <summary>
    /// 安防bypass设置对象
    /// </summary>
    public class SecurityBypass
    {
        /// <summary>
        /// 安防云端id
        /// </summary>
        public string userSecurityId;
        /// <summary>
        /// 输入设备bypass状态列表
        /// </summary>
        public List<SecurityBypassInput> input = new List<SecurityBypassInput>();
        
    }
    /// <summary>
    /// 输入设备bypass状态
    /// </summary>
    public class SecurityBypassInput
    {
        /// <summary>
        /// 设备sid
        /// </summary>
        public string sid;
        /// <summary>
        /// true:启用
        /// false:停用(临时bypass)
        /// </summary>
        public string bypass;
    }
 
 
    /// <summary>
    /// 安防输入
    /// </summary>
    public class SecurityInput
    {
        /// <summary>
        /// 输入条件(功能)的sid
        /// 输入设备sid
        /// </summary>
        public string sid;
        /// <summary>
        /// Bypass设置 true:启用中、false:临时bypass中
        /// </summary>
        public string bypass;
        /// <summary>
        /// 安防输入条件
        /// </summary>
        public List<SecurityInputCondition> condition = new List<SecurityInputCondition>();
 
        [Newtonsoft.Json.JsonIgnore]
        Function _function = null;
        /// <summary>
        /// 对应的功能对象
        /// </summary>
        /// <returns></returns>
        public Function GetFunction()
        {
            if (_function == null)
            {
                _function = FunctionList.List.Functions.Find((obj) => obj.sid == sid);
            }
            return _function;
        }
 
        /// <summary>
        /// 状态文本
        /// </summary>
        /// <returns></returns>
        public string StateText ()
        {
            string text = "";
            switch(GetFunction().spk)
            {
                case SPK.SensorGas:
                case SPK.SensorSmoke:
                    foreach (var con in condition)
                    {
                        if (con.value == "true")
                        {
                            text += Language.StringByID(StringId.InAlarm) + " ";
                        }
                        else if (con.value == "false")
                        {
                            text += Language.StringByID(StringId.Normal) + " ";
                        }
                    }
                    break;
                case SPK.SensorPir:
                    foreach (var con in condition)
                    {
                        if (con.value == "true")
                        {
                            text += Language.StringByID(StringId.youren) + " ";
                        }
                        else if (con.value == "false")
                        {
                            text += Language.StringByID(StringId.wuren) + " ";
                        }
                    }
                    break;
                case SPK.SensorWater:
                    foreach (var con in condition)
                    {
                        if (con.value == "true")
                        {
                            text += Language.StringByID(StringId.WaterLeakage) + " ";
                        }
                        else if (con.value == "false")
                        {
                            text += Language.StringByID(StringId.Normal) + " ";
                        }
                    }
                    break;
                case SPK.SensorDoorWindow:
                    foreach (var con in condition)
                    {
                        if (con.value == "true")
                        {
                            text += Language.StringByID(StringId.Open) + " ";
                        }
                        else if (con.value == "false")
                        {
                            text += Language.StringByID(StringId.Close) + " ";
                        }
                    }
                    break;
            }
 
            return text;
        }
        
    }
    /// <summary>
    /// 安防输入条件
    /// </summary>
    public class SecurityInputCondition
    {
        /// <summary>
        /// 属性(条件)名称
        /// </summary>
        public string key;
        /// <summary>
        /// 操作(执行)条件
        /// < 小于 > 大于  ==等于
        /// </summary>
        public string comparator;
        /// <summary>
        /// 条件值类型
        /// int \float\ string
        /// </summary>
        public string data_type = "string";
        /// <summary>
        /// 值    
        /// </summary>
        public string value;
    }
 
    /// <summary>
    /// 安防输出
    /// </summary>
    public class SecurityOutput
    {
        /// <summary>
        /// 控制目标类型
        /// 0:设备
        /// 1:场景
        /// 2:自动化
        /// </summary>
        public string target_type ="0";
        /// <summary>
        /// 输出目标的sid
        /// </summary>
        public string sid;
        /// <summary>
        /// 安防输出状态
        /// </summary>
        public List<SecurityOutputStatus> status = new List<SecurityOutputStatus>();
 
        [Newtonsoft.Json.JsonIgnore]
        Function _function = null;
        /// <summary>
        /// 对应的功能对象
        /// </summary>
        /// <returns></returns>
        public Function GetFunction()
        {
            if (_function == null)
            {
                _function = FunctionList.List.Functions.Find((obj) => obj.sid == sid);
            }
            return _function;
        }
 
 
        /// <summary>
        /// 状态文本
        /// </summary>
        /// <returns></returns>
        public string StateText()
        {
            string text = "";
            if (target_type == "0")
            {
                switch (GetFunction().spk)
                {
                    case SPK.LightDimming:
                    case SPK.LightCCT:
                    case SPK.LightRGB:
                    case SPK.LightSwitch:
                        foreach (var state in status)
                        {
                            if (state.key == FunctionAttributeKey.Brightness)
                            {
                                if (state.value == "0")
                                {
                                    text = Language.StringByID(StringId.Close);
                                }
                                else
                                {
                                    text = Language.StringByID(StringId.Open);
                                }
                            }
                        }
                        break;
                }
            }else if(target_type == "1")
            {
 
            }
 
            return text;
        }
 
    }
    /// <summary>
    /// 安防输出状态
    /// </summary>
    public class SecurityOutputStatus
    {
        public string key;
        public string value;
    }
 
    /// <summary>
    /// 安防通知配置
    /// </summary>
    public class SecurityNoticeConfig
    {
        /// <summary>
        /// 是否开启通知
        /// </summary>
        public bool enable;
        /// <summary>
        /// 通知内容
        /// </summary>
        public string noticeContent;
        
    }
    /// <summary>
    /// 安防推送配置
    /// </summary>
    public class SecurityPushConfig
    {
        /// <summary>
        /// 推送方式
        /// APP:app push
        /// SMS:短信
        /// </summary>
        public string pushMethod;
        /// <summary>
        /// 推送目标
        /// </summary>
        public List<string> pushTarget = new List<string>();
    }
}