wxr
2021-06-09 cb6e11c5067ecaba4d8f9907989154167c1e8943
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
using System;
using System.IO;
using System.Net;
using HDL_ON.DAL.Server;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Shared;
using HDL_ON.Entity;
 
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
 
    public class PirSend
    {
        /// <summary>
        /// 网关ID(获取嘉乐网关ID)
        /// </summary>
        public static string GatewayId
        {
            get
            {
                if (Entity.DB_ResidenceData.Instance.HomeGateway == null)
                {
                    return DriverLayer.Control.Ins.GatewayId;
                }
                return Entity.DB_ResidenceData.Instance.HomeGateway.gatewayId;
            }
        }
        /// <summary>
        /// 住宅ID
        /// </summary>
        public static string HomeId
        {
            get
            {
                return Entity.DB_ResidenceData.Instance.CurrentRegion.id;
            }
        }
        /// <summary>
        /// 是否为其他主用户分享过来的住宅
        /// </summary>
        public static bool IsOthreShare
        {
            get
            {
                return Entity.DB_ResidenceData.Instance.CurrentRegion.isOtherShare;
            }
        }
        /// <summary>
        /// 获取设备列表
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew GetDeviceList(string spk)
        {
            var jObject = new JObject { };
            jObject.Add("homeId", HomeId);
            jObject.Add("spk", spk);
            //d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId);
            //d.Add("roomId", DB_ResidenceData.residenceData.residecenInfo.RegionID);//可控参数,当需要分页获取,怎么知道分页总数
            //d.Add("searchType", DB_ResidenceData.residenceData.residecenInfo.RegionID);
            //d.Add("pageSize", DB_ResidenceData.residenceData.residecenInfo.RegionID);
            //d.Add("pageNo", DB_ResidenceData.residenceData.residecenInfo.RegionID);
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.Api_Post_GetDevcieList);
            return responsePackNew;
        }
        /// <summary>
        /// 获取设备详情通过(spk,sid)
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew GetinfoBySid(Control control)
        {
            var jObject = new JObject { };
            jObject.Add("homeId", HomeId);
            jObject.Add("spk", control.spk);
            jObject.Add("sid", control.sid);
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.Api_Post_GetinfoBySid);
            return responsePackNew;
        }
        /// <summary>
        /// 获取遥控器列表
        /// </summary>
        public static ResponsePackNew ControlList(string deviceId)
        {
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", deviceId} };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_List);
            return responsePackNew;
        }
        /// <summary>
        /// 遥控器添加
        /// </summary>
        /// <returns></returns>
        /// <param name="control"></param>
        /// <returns></returns>
        public static ResponsePackNew Add(Control control)
        {
            var jObject = new JObject { }; 
            jObject.Add("homeId", HomeId);
            jObject.Add("deviceId", control.deviceId);
            jObject.Add("name", control.name);
            jObject.Add("spk", control.spk);
            jObject.Add("type", control.type);
            if (control.type=="library")
            {
                jObject.Add("groupId", control.groupId);
                var libraryjay = new JArray { };
                for (int i = 0; i < control.library.Count; i++)
                {
                    libraryjay.Add(control.library[i]);
                }
                jObject.Add("library", libraryjay);
            }
          
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_Add);
            return responsePackNew;
        }
        /// <summary>
        ///红外码库试码
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew CodeTest(Control control)
        {
            var jObject = new JObject { }; 
            jObject.Add("homeId", HomeId);
            jObject.Add("deviceId", control.deviceId);
            jObject.Add("spk", control.spk);
            if (control.spk== SPK.AcIr) {
                jObject.Add("groupId", control.groupId);
            }
            var libraryJay = new JArray { }; 
            for (int i = 0; i < control.library.Count; i++)
            {
                libraryJay.Add(control.library[i]);
            }
            var statusJay = new JArray { };
            for (int i = 0; i < control.status.Count; i++)
            {
                var statusJob = new JObject { };
                var job = control.status[i];
                statusJob.Add("key", job.key);
                statusJob.Add("value", job.value);
                statusJay.Add(statusJob);
            }
            jObject.Add("library", libraryJay);
            jObject.Add("status", statusJay);
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeTest);
            return responsePackNew;
        }
        /// <summary>
        /// <summary>
        /// 红外码学习
        /// </summary>
        /// <returns></returns>
        public static void CodeStudy(Control control, AttributesStatus buttonObj, Action<Cloud> action)
        {
            var job = new JObject { };
            job.Add("key", buttonObj.key);
            job.Add("data_type", "string");
            var valuejArray = new JArray { };
            valuejArray.Add(buttonObj.value);
            job.Add("value", valuejArray);
            var jArray = new JArray { };
            jArray.Add(job);
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", control.deviceId }, { "attributes", jArray } };
            Cloud cloud = null;
            new System.Threading.Thread(() =>
            {
 
                try
                {
                    //发送红外码学习命令
                    var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeStudy);
                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                    {
                        PirMethod method = new PirMethod();
                        PirMethod.buttondata = "";
                        cloud = method.MqttDate("按键", control.sid, 25);
                    }
                    else
                    {
                        PirMethod method = new PirMethod();
                        method.ErrorShow(responsePackNew, "");
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        action(cloud);
                    });
                }
 
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 自学按键删除
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew CodeRemove(AttributesStatus buttonObj,string deviceId)
        {
            var job = new JObject { };
            job.Add("key", buttonObj.key);
            job.Add("data_type", "string");
            var valuejArray = new JArray { };
            valuejArray.Add(buttonObj.value);
            job.Add("value", valuejArray);
            var jArray = new JArray { };
            jArray.Add(job);
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", deviceId }, { "attributes", jArray } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_CodeRemove);
            return responsePackNew;
        }
        /// <summary>
        /// 红外宝/遥控器删除
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew DeleteDevice(string deviceId)
        {
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", deviceId } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_DeviceDel);
            return responsePackNew;
        }
        /// <summary>
        /// 修改红外宝/设备名称
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew DeviceRename(string deviceId,string name)
        {
            var jObject = new JObject { { "homeId", HomeId }, { "deviceId", deviceId }, { "name", name} };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Ir_DeviceRename);
            return responsePackNew;
        }
        /// <summary>
        /// 查询红外设备类型列表/品牌列表/品牌红外码库列表
        /// </summary>
        /// <param name="frameLayout">加载log的父控件</param>
        /// <param name="action">回调函数</param>
        public static void GetDeviceTypesList(FrameLayout frameLayout, Action<ResponsePackNew> action, string id, string if_str)
        {
 
            DAL.Server.ResponsePackNew responsePackNew = null;
            Loading loading = new Loading();
            frameLayout.AddChidren(loading);
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    string url = "";
                    var jObject = new JObject { };
                    if (if_str == "设备类型列表")
                    {
                        url = "/smart-footstone/app/ir/device-type/list";
                    }
                    else if (if_str == "品牌列表")
                    {
                        url = "/smart-footstone/app/ir/brand/list";
                        jObject.Add("deviceTypeId", id);
                    }
                    else if (if_str == "品牌红外码库列表")
                    {
                        url = "/smart-footstone/app/ir/code/list";
                        jObject.Add("brandId", id);
                    }
                    responsePackNew = RequestServerhomeId(jObject, url,5);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        action(responsePackNew);
                    });
                }
            })
            { IsBackground = true }.Start();
 
        }
        /// <summary>
        ///请求服务器(与住宅有关:例如;homeId) 
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 20)
        {
            var requestJson = HttpUtil.GetSignRequestJson(o);
            return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
 
        }
        /// <summary>
        /// 请求服务器
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew RequestServer(object o, string api_Url)
        {
            var requestJson = HttpUtil.GetSignRequestJson(o);
            return HttpUtil.RequestHttpsPost(api_Url, requestJson);
 
        }
        /// <summary>
        /// 刷新Token
        /// </summary>
        public static void RefreshToken()
        {
            IMessageCommon.Current.StartRefreshToken();
        }
 
    }
 
}