CrabtreeOn,印度客户定制APP,迁移2.0平台版本
JLChen
2021-02-24 50b7b7a486f56fab27c83b59eb45673c6d9f0935
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
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Shared;
using Shared.SimpleControl.R;
 
namespace SmartHome
{
    public class Send
    {
        #region 计时器的命令方法
        /// <summary>
        /// 获取计时器列表
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew GetTimerList ()
        {
            var jObject = new JObject { }; 
            jObject.Add ("gatewayId", GatewayId);
            jObject.Add ("homeId", HomeId);
            jObject.Add ("pageSize", 1000);
            jObject.Add ("pageNo", 1);
 
            var responsePackNew = RequestServerhomeId (jObject, API.GetTimerList);
            return responsePackNew;
        }
        /// <summary>
        /// 添加计时器命令 
        /// </summary>
        /// <param name="timer"></param>
        /// <returns></returns>
        public static ResponsePackNew AddTimer (Timer timer) 
        {
            ResponsePackNew responsePackNew = null;
            try {
                var jArray = new JArray { };
                foreach (var dic in timer.whichDay) {
                    jArray.Add (dic);
                }
 
                var deviceDateJObject = new JObject { };
                deviceDateJObject.Add ("gatewayId", GatewayId);
                deviceDateJObject.Add ("homeId", HomeId);
                var funjArray = new JArray { };
                for (int i = 0; i < timer.controlData.actions.Count; i++) {
                    var fun = timer.controlData.actions [i];
                    var funJObject = new JObject { };
                    funJObject.Add ("deviceId", fun.deviceId);
                    funJObject.Add ("spk", fun.spk);
 
                    var attributesJArray = new JArray { };
                    for (int i1 = 0; i1 < fun.attributes.Count; i1++) {
                        var attributes = fun.attributes [i1];
                        var attributesJObject = new JObject { };
                        attributesJObject.Add ("key", attributes.key);
                        attributesJObject.Add ("value", attributes.value);
                        attributesJArray.Add (attributesJObject);
                    }
                    funJObject.Add ("attributes", attributesJArray);
 
                    var busJObject = new JObject { };
                    busJObject.Add ("addresses", fun.bus.addresses);
                    busJObject.Add ("loopId", fun.bus.loopId);
                    funJObject.Add ("bus", busJObject);
                    funjArray.Add (funJObject);
                }
                deviceDateJObject.Add ("actions", funjArray);
                
                var jObject = new JObject { };
                jObject.Add ("gatewayId", GatewayId); 
                jObject.Add ("homeId", HomeId);
                jObject.Add ("timerName", timer.timerName);
                jObject.Add ("isEnable", timer.isEnable);
                jObject.Add ("executeUtcTime", Method.GetUtcTime (timer.executeUtcTime));
                jObject.Add ("controlData", deviceDateJObject);
                jObject.Add ("timerType", timer.timerType.GetHashCode());
                jObject.Add ("whichDay", jArray);
                responsePackNew = RequestServerhomeId (jObject, API.AddTimer);
              
            } catch (Exception e) {
                var dd = e.Message;
            }
            return responsePackNew;
        }
        /// <summary>
        /// 编辑更新
        /// </summary>
        /// <param name="timer"></param>
        /// <returns></returns>
        public static ResponsePackNew UpdateTimer (Timer timer)
        {
            ResponsePackNew responsePackNew = null;
            try {
                var jArray = new JArray { };
                foreach (var dic in timer.whichDay) {
                    jArray.Add (dic);
                }
 
                var deviceDateJObject = new JObject { };
                deviceDateJObject.Add ("gatewayId", GatewayId);
                deviceDateJObject.Add ("homeId", HomeId);
                var funjArray = new JArray { };
                for (int i = 0; i < timer.controlData.actions.Count; i++) {
                    var fun = timer.controlData.actions [i];
                    var funJObject = new JObject { };
                    funJObject.Add ("deviceId", fun.deviceId);
                    funJObject.Add ("spk", fun.spk);
 
                    var attributesJArray = new JArray { };
                    for (int i1 = 0; i1 < fun.attributes.Count; i1++) {
                        var attributes = fun.attributes [i1];
                        var attributesJObject = new JObject { };
                        attributesJObject.Add ("key", attributes.key);
                        attributesJObject.Add ("value", attributes.value);
                        attributesJArray.Add (attributesJObject);
                    }
                    funJObject.Add ("attributes", attributesJArray);
 
                    var busJObject = new JObject { };
                    busJObject.Add ("addresses", fun.bus.addresses);
                    busJObject.Add ("loopId", fun.bus.loopId);
                    funJObject.Add ("bus", busJObject);
                    funjArray.Add (funJObject);
                }
                deviceDateJObject.Add ("actions", funjArray);
 
                var jObject = new JObject { };
                jObject.Add ("gatewayId", GatewayId);
                jObject.Add ("homeId", HomeId);
                jObject.Add ("id", timer.id);
                jObject.Add ("timerName", timer.timerName);
                jObject.Add ("isEnable", timer.isEnable);
                jObject.Add ("executeUtcTime", Method.GetUtcTime (timer.executeUtcTime));
                jObject.Add ("controlData", deviceDateJObject);
                jObject.Add ("timerType", timer.timerType.GetHashCode ());
                jObject.Add ("whichDay", jArray);
                responsePackNew = RequestServerhomeId (jObject, API.EditTimer);
 
            } catch (Exception e) {
                var dd = e.Message;
            }
            return responsePackNew;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew DelTimer (string id)
        {
            var jObject = new JObject { };
            jObject.Add ("id", Int64.Parse (id));
            jObject.Add ("gatewayId", GatewayId);
            jObject.Add ("homeId", HomeId);
            var responsePackNew = RequestServerhomeId (jObject, API.DeleteTimer);
            return responsePackNew;
        }
        /// <summary> 
        /// 开关
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew SwitchTimer (Timer timer)
        {
           
            var jObject = new JObject { };
            jObject.Add ("id", timer.id);
            jObject.Add ("gatewayId", GatewayId);
            jObject.Add ("homeId", HomeId);
            var responsePackNew = RequestServerhomeId (jObject, API.IsEnableTimer);
            return responsePackNew;
        }
        #endregion
        /// <summary>
        /// 网关ID
        /// </summary>
        public static string GatewayId {
            get {
                return UserConfig.Instance.HomeGateway.gatewayId;
            }
        }
        /// <summary>
        /// 住宅ID
        /// </summary>
        public static string HomeId {
            get {
                return UserConfig.Instance.CurrentRegion.Id;
            }
        }
      
        /// <summary>
        ///请求服务器(与住宅有关:例如;homeId) 
        /// </summary>
        /// <returns></returns>
        public static ResponsePackNew RequestServerhomeId (object o, string api_Url, int mTimeout = 3)
        {
            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);
 
        }
        
 
    }
}