@quec/rn-device-module 1.9.19 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/QuecRNDeviceModule.podspec +54 -0
  3. package/README.md +1535 -1043
  4. package/android/build.gradle +119 -0
  5. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  6. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  7. package/android/gradle.properties +23 -0
  8. package/android/gradlew +185 -0
  9. package/android/gradlew.bat +89 -0
  10. package/android/old-info.properties +2 -0
  11. package/android/proguard-rules.pro +21 -0
  12. package/android/publishInfo.properties +4 -0
  13. package/android/settings.gradle +3 -0
  14. package/android/src/main/AndroidManifest.xml +6 -0
  15. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/IQuecRNDeviceModuleSpec.java +1352 -0
  16. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/QuecRNDeviceModule.java +2423 -0
  17. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/QuecRNDeviceModulePackage.java +23 -0
  18. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/DataInfo.java +25 -0
  19. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/DataRes.java +31 -0
  20. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/DeviceDpsUpdateModel.java +18 -0
  21. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/ModelBridgeBasic.java +86 -0
  22. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/OtaUpgradePlanModel.java +292 -0
  23. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/ShareInfo.java +166 -0
  24. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/UserInfo.java +137 -0
  25. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/bean/WriteCmdWithId.java +10 -0
  26. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/AnalysisChannelDataUtils.java +82 -0
  27. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/DataConvertUtils.kt +130 -0
  28. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/ErrorCode.java +26 -0
  29. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/ErrorUtils.java +11 -0
  30. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/IpcUtil.java +75 -0
  31. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/NetUtils.java +85 -0
  32. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/OnConnectListener.java +22 -0
  33. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/ParamsValueUtils.java +79 -0
  34. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/QuecIotChannelMode.java +8 -0
  35. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/ReactNativeJson.java +199 -0
  36. package/android/src/main/java/com/quectel/smart/rnplugin/quecrndevicemodule/utils/ResponseUtils.java +156 -0
  37. package/android/src/main/res/values/strings.xml +4 -0
  38. package/android/src/main/res/values-en/strings.xml +4 -0
  39. package/android/src/main/res/values-zh/strings.xml +4 -0
  40. package/android/src/test/java/com/quectel/smart/template/ExampleUnitTest.java +17 -0
  41. package/build.gradle +1 -0
  42. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  43. package/gradle/wrapper/gradle-wrapper.properties +6 -0
  44. package/ios/Example/Podfile +17 -0
  45. package/ios/Example/QuecRNDeviceModule/AppDelegate.h +13 -0
  46. package/ios/Example/QuecRNDeviceModule/AppDelegate.m +46 -0
  47. package/ios/Example/QuecRNDeviceModule/Base.lproj/LaunchScreen.storyboard +31 -0
  48. package/ios/Example/QuecRNDeviceModule/Base.lproj/Main.storyboard +31 -0
  49. package/ios/Example/QuecRNDeviceModule/Images.xcassets/AppIcon.appiconset/Contents.json +98 -0
  50. package/ios/Example/QuecRNDeviceModule/QuecRNDeviceModule-Info.plist +40 -0
  51. package/ios/Example/QuecRNDeviceModule/QuecRNDeviceModule-Prefix.pch +16 -0
  52. package/ios/Example/QuecRNDeviceModule/ViewController.h +12 -0
  53. package/ios/Example/QuecRNDeviceModule/ViewController.m +29 -0
  54. package/ios/Example/QuecRNDeviceModule/en.lproj/InfoPlist.strings +2 -0
  55. package/ios/Example/QuecRNDeviceModule/main.m +15 -0
  56. package/ios/Example/QuecRNDeviceModule.xcodeproj/project.pbxproj +583 -0
  57. package/ios/Example/QuecRNDeviceModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  58. package/ios/Example/QuecRNDeviceModule.xcodeproj/xcshareddata/xcschemes/QuecRNDeviceModule-Example.xcscheme +101 -0
  59. package/ios/Example/QuecRNDeviceModule.xcworkspace/contents.xcworkspacedata +10 -0
  60. package/ios/Example/QuecRNDeviceModule.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  61. package/ios/LICENSE +4 -0
  62. package/ios/QuecRNDeviceModule/Assets/.gitkeep +0 -0
  63. package/ios/QuecRNDeviceModule/Classes/QuecRNDeviceModule+Ext.h +27 -0
  64. package/ios/QuecRNDeviceModule/Classes/QuecRNDeviceModule+Impl.h +1137 -0
  65. package/ios/QuecRNDeviceModule/Classes/QuecRNDeviceModule+Impl.m +1524 -0
  66. package/ios/QuecRNDeviceModule/Classes/QuecRNDeviceModule.h +157 -0
  67. package/ios/QuecRNDeviceModule/Classes/QuecRNDeviceModule.m +721 -0
  68. package/ios/README.md +20 -0
  69. package/{.prettierrc.js → js/.prettierrc.js} +11 -11
  70. package/js/README.md +1535 -0
  71. package/js/package.json +25 -0
  72. package/{src → js/src}/index.ts +12 -12
  73. package/{src → js/src}/module.ts +1332 -939
  74. package/{src → js/src}/viewCommon.ts +3 -3
  75. package/js/tsconfig.json +26 -0
  76. package/js/yarn.lock +4 -0
  77. package/package.json +10 -25
  78. package/plugin.ts +1180 -0
  79. package/settings.gradle +2 -0
  80. package/tsconfig.json +9 -0
@@ -0,0 +1,2423 @@
1
+ package com.quectel.smart.rnplugin.quecrndevicemodule;
2
+
3
+ import android.app.Activity;
4
+ import android.text.TextUtils;
5
+ import android.util.Base64;
6
+
7
+ import androidx.annotation.NonNull;
8
+
9
+ import com.facebook.react.bridge.Arguments;
10
+ import com.facebook.react.bridge.Callback;
11
+ import com.facebook.react.bridge.Promise;
12
+ import com.facebook.react.bridge.ReactApplicationContext;
13
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
14
+ import com.facebook.react.bridge.ReactMethod;
15
+ import com.facebook.react.bridge.ReadableArray;
16
+ import com.facebook.react.bridge.ReadableMap;
17
+ import com.facebook.react.bridge.ReadableType;
18
+ import com.facebook.react.bridge.WritableArray;
19
+ import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.module.annotations.ReactModule;
21
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
22
+ import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
23
+ import com.google.gson.Gson;
24
+ import com.google.gson.reflect.TypeToken;
25
+ import com.quectel.app.device.bean.BatchControlDevice;
26
+ import com.quectel.app.device.bean.BatchDeleteCloudTiming;
27
+ import com.quectel.app.device.bean.ChannelStateEvent;
28
+ import com.quectel.app.device.bean.CloudTimingList;
29
+ import com.quectel.app.device.bean.DpsHttpExtraDataBean;
30
+ import com.quectel.app.device.bean.ModelBasic;
31
+ import com.quectel.app.device.bean.QuecBatchControlDeviceModel;
32
+ import com.quectel.app.device.bean.QuecBatchControlExtraModel;
33
+ import com.quectel.app.device.bean.QuecCornJobModel;
34
+ import com.quectel.app.device.bean.QuecDeviceListParamsModel;
35
+ import com.quectel.app.device.bean.QuecProductTSLPropertyModel;
36
+ import com.quectel.app.device.bean.QuecVoiceSupport;
37
+ import com.quectel.app.device.bean.RefreshUnbindDeviceEvent;
38
+ import com.quectel.app.device.bean.TSLEvent;
39
+ import com.quectel.app.device.bean.TSLService;
40
+ import com.quectel.app.device.callback.IDeviceTSLCallBack;
41
+ import com.quectel.app.device.callback.IDeviceTSLModelCallback;
42
+ import com.quectel.app.device.deviceservice.IDevService;
43
+ import com.quectel.app.device.deviceservice.QuecDeviceAssociateService;
44
+ import com.quectel.app.device.deviceservice.QuecDeviceControlService;
45
+ import com.quectel.app.device.deviceservice.QuecDeviceGroupService;
46
+ import com.quectel.app.device.deviceservice.QuecDeviceService;
47
+ import com.quectel.app.device.deviceservice.QuecDeviceShareService;
48
+ import com.quectel.app.device.deviceservice.QuecDeviceStatisticsService;
49
+ import com.quectel.app.device.iot.IotChannelController;
50
+ import com.quectel.app.device.utils.CacheTSLModel;
51
+ import com.quectel.app.device.utils.DeviceServiceFactory;
52
+ import com.quectel.app.device.utils.JsonUtils;
53
+ import com.quectel.app.device.utils.ObjectModelParse;
54
+ import com.quectel.app.device.utils.WebSocketServiceLocater;
55
+ import com.quectel.app.quecnetwork.httpservice.IHttpCallBack;
56
+ import com.quectel.app.smart_home_sdk.bean.QuecFamilyDeviceListParamsModel;
57
+ import com.quectel.app.smart_home_sdk.service.QuecSmartHomeService;
58
+ import com.quectel.app.websocket.deviceservice.IWebSocketService;
59
+ import com.quectel.app.websocket.websocket.EventType;
60
+ import com.quectel.app.websocket.websocket.SocketEvent;
61
+ import com.quectel.app.websocket.websocket.SuccessEventContent;
62
+ import com.quectel.app.websocket.websocket.WsManager;
63
+ import com.quectel.basic.common.base.QuecBaseApp;
64
+ import com.quectel.basic.common.entity.QuecCallback;
65
+ import com.quectel.basic.common.entity.QuecDeviceModel;
66
+ import com.quectel.basic.common.entity.QuecError;
67
+ import com.quectel.basic.common.entity.QuecPageResponse;
68
+ import com.quectel.basic.common.entity.QuecResult;
69
+ import com.quectel.basic.common.entity.QuecSimpleCallBack;
70
+ import com.quectel.basic.common.event.QuecBaseEvent;
71
+ import com.quectel.basic.common.utils.QuecCacheDataUtils;
72
+ import com.quectel.basic.common.utils.QuecGsonUtil;
73
+ import com.quectel.basic.common.utils.QuecThreadUtil;
74
+ import com.quectel.basic.common.utils.QuecTimeZoneUtil;
75
+ import com.quectel.basic.common.utils.QuecToastUtil;
76
+ import com.quectel.basic.queclog.QLog;
77
+ import com.quectel.basic.quecmmkv.MmkvManager;
78
+ import com.quectel.basic.rn.QuecReadableMapUtil;
79
+ import com.quectel.business.device.list.api.QuecDeviceListServiceManager;
80
+ import com.quectel.business.device.list.api.RefreshDeviceListEvent;
81
+ import com.quectel.business.device.list.api.model.DeviceModel;
82
+ import com.quectel.business.device.panel.api.Constants;
83
+ import com.quectel.business.device.panel.api.QuecDevicePanelServiceManager;
84
+ import com.quectel.business.device.panel.api.events.QuecDeviceModelUpdateEvent;
85
+ import com.quectel.business.device.panel.api.events.QuecSelectedDeviceEvent;
86
+ import com.quectel.business.ota.upgrade.api.OtaUpgradeServiceManager;
87
+ import com.quectel.business.quecMain.api.QuecMainConstant;
88
+ import com.quectel.business.smart.config.api.SmartConfigServiceManager;
89
+ import com.quectel.business.wifiSwitch.module.api.QuecWifiSwitchUIServiceManager;
90
+ import com.quectel.sdk.iot.channel.kit.QuecDeviceDataUploadManager;
91
+ import com.quectel.sdk.iot.channel.kit.QuecIotChannelManager;
92
+ import com.quectel.oem.config.QuecOemAppConfig;
93
+ import com.quectel.sdk.iot.channel.kit.constaint.QuecIotChannelType;
94
+ import com.quectel.sdk.iot.channel.kit.constaint.QuecIotDataSendMode;
95
+ import com.quectel.sdk.iot.channel.kit.model.QuecIotChannelExtraData;
96
+ import com.quectel.sdk.iot.channel.kit.model.QuecIotDataPointsModel;
97
+ import com.quectel.sdk.iot.channel.kit.v2.QuecDeviceClient;
98
+ import com.quectel.sdk.iot.channel.kit.v2.QuecDeviceClientApi;
99
+ import com.quectel.sdk.mvvm.QuecBaseViewModel;
100
+ import com.quectel.sdk.ota.upgrade.entry.QuecOtaInfo;
101
+ import com.quectel.sdk.ota.upgrade.v2.QuecOtaManager;
102
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.AnalysisChannelDataUtils;
103
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.DataConvertUtils;
104
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.ErrorCode;
105
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.IpcUtil;
106
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.NetUtils;
107
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.ParamsValueUtils;
108
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.ReactNativeJson;
109
+ import com.quectel.smart.rnplugin.quecrndevicemodule.utils.ResponseUtils;
110
+
111
+ import org.greenrobot.eventbus.EventBus;
112
+ import org.greenrobot.eventbus.Subscribe;
113
+ import org.greenrobot.eventbus.ThreadMode;
114
+ import org.json.JSONArray;
115
+ import org.json.JSONException;
116
+ import org.json.JSONObject;
117
+
118
+ import java.util.ArrayList;
119
+ import java.util.Collections;
120
+ import java.util.HashSet;
121
+ import java.util.List;
122
+ import java.util.Set;
123
+ import java.util.concurrent.CountDownLatch;
124
+
125
+ /**
126
+ * @version: 1.0.0
127
+ * @owner: vic.huang@quectel.com
128
+ * @platform: all
129
+ * 设备桥组件
130
+ */
131
+ @ReactModule(name = "QuecRNDeviceModule")
132
+ public class QuecRNDeviceModule extends ReactContextBaseJavaModule implements IQuecRNDeviceModuleSpec {
133
+ private static final String NO_NETWORK_MSG = "";
134
+ private static final String TAG = "QuecRNDeviceModule";
135
+ private static final String PRODUCT_KEY_NAME = "productKey";
136
+ private static final String DEVICE_KEY_NAME = "deviceKey";
137
+ private final CountDownLatch latch = new CountDownLatch(1);
138
+ private final QuecBaseViewModel viewModel = new QuecBaseViewModel();
139
+ private final List<QuecDeviceModel> deviceModelList = new ArrayList<>();
140
+ /**
141
+ * 多设备关联项目 since 2.8.8
142
+ * 主设备已绑定的其他设备
143
+ */
144
+ private final Set<String> otherChannelIds = new HashSet<>();
145
+
146
+ private QuecDeviceModel deviceModel = null;
147
+ private volatile String channelId = "";
148
+ private QuecDeviceClientApi deviceClient = QuecDeviceClient.Companion.initWithDevice(new QuecDeviceModel("", ""));
149
+ private final QuecDeviceClientApi.Listener listener = new QuecDeviceClientApi.Listener() {
150
+
151
+ @Override
152
+ public void dpsUpdate(@NonNull QuecDeviceModel quecDeviceModel,
153
+ @NonNull QuecIotDataPointsModel quecIotDataPointsModel) {
154
+
155
+ }
156
+
157
+ @Override
158
+ public void deviceRemoved(@NonNull QuecDeviceModel quecDeviceModel) {
159
+
160
+ }
161
+
162
+ @Override
163
+ public void onlineUpdate(@NonNull QuecDeviceModel quecDeviceModel, int onlineState) {
164
+ QLog.i(TAG, "[" + Thread.currentThread().getName() + "] - [" + quecDeviceModel.getChannelId() + "] " +
165
+ "onlineUpdate: " + onlineState);
166
+ WritableMap writableMap = Arguments.createMap();
167
+ writableMap.putString("onlineState", onlineState + "");
168
+ try {
169
+ //多设备模式下需要返回device信息,否则不知道哪个设备的状态
170
+ DeviceModel deviceModel = new DeviceModel();
171
+ deviceModel.setProductKey(quecDeviceModel.getProductKey());
172
+ deviceModel.setDeviceKey(quecDeviceModel.getDeviceKey());
173
+ deviceModel.setOnlineStatus(onlineState);
174
+ JSONObject jsonObject = new JSONObject(QuecGsonUtil.INSTANCE.gsonString(deviceModel));
175
+ WritableMap device = ReactNativeJson.convertJsonToMap(jsonObject);
176
+ writableMap.putMap(Constants.DEVICE_PANEL_DEVICE_MODEL, device);
177
+ } catch (JSONException e) {
178
+ QLog.d(TAG, e.toString());
179
+ }
180
+ onDeviceOnlineState(writableMap);
181
+ }
182
+
183
+ @Override
184
+ public void deviceInfoUpdate(@NonNull QuecDeviceModel quecDeviceModel) {
185
+
186
+ }
187
+
188
+ @Override
189
+ public void connectingStateUpdate(@NonNull QuecDeviceModel quecDeviceModel, int connectingState) {
190
+ sendConnectingStateEvent(connectingState);
191
+ }
192
+ };
193
+
194
+ private final QuecCallback<QuecBaseEvent> deviceEventCallback = result -> onEvent(result.getData());
195
+
196
+ public QuecRNDeviceModule(ReactApplicationContext reactContext) {
197
+ super(reactContext);
198
+ if (!EventBus.getDefault().isRegistered(QuecRNDeviceModule.this)) {
199
+ EventBus.getDefault().register(QuecRNDeviceModule.this);
200
+ }
201
+
202
+ QuecDevicePanelServiceManager.getInstance().addDeviceInfoEventCallback(deviceEventCallback);
203
+ initData();
204
+ // initIotChannelEvent();
205
+ }
206
+
207
+ @Override
208
+ public void initialize() {
209
+ super.initialize();
210
+ QLog.d(TAG, "init");
211
+ latch.countDown(); // 标记初始化完成
212
+ }
213
+
214
+ /**
215
+ * 解析js层传递过来的数据 转换成 QuecIotDataPointsModel.DataModel
216
+ */
217
+ private List<QuecIotDataPointsModel.DataModel> getData(ReadableArray dps, Promise promise) {
218
+ List<QuecIotDataPointsModel.DataModel> list = new ArrayList<>();
219
+ try {
220
+ JSONArray array = ReactNativeJson.convertArrayToJson(dps);
221
+ if (array.length() == 0) {
222
+ return list;
223
+ }
224
+ for (int i = 0; i < array.length(); i++) {
225
+ QuecIotDataPointsModel.DataModel model = new QuecIotDataPointsModel.DataModel();
226
+ JSONObject jobj = array.getJSONObject(i);
227
+ if (jobj != null) {
228
+ model.setId(jobj.optInt("id"));
229
+ model.setDataType(jobj.optString("dataType"));
230
+ model.setCode(jobj.optString("code"));
231
+ if (model.getDataType().equals(QuecIotDataPointsModel.DataModel.QuecIotDataPointDataType.ARRAY_NUM)) {
232
+ //数组类型
233
+ model.setValue(handleArray(jobj));
234
+ } else if (model.getDataType().equals(QuecIotDataPointsModel.DataModel.QuecIotDataPointDataType.STRUCT_NUM)) {
235
+ //结构体类型
236
+ model.setValue(handleStruct(jobj));
237
+ } else {
238
+ //基本数据类型
239
+ model.setValue(jobj.optString("value"));
240
+ }
241
+ list.add(model);
242
+ }
243
+ }
244
+ } catch (JSONException e) {
245
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
246
+ QLog.e(TAG, e.toString());
247
+ }
248
+ return list;
249
+ }
250
+
251
+ /**
252
+ * 处理数据数据类型
253
+ */
254
+ private List<QuecIotDataPointsModel.DataModel> handleArray(JSONObject jobj) {
255
+ JSONArray jsonArray = jobj.optJSONArray("value");
256
+ List<QuecIotDataPointsModel.DataModel> childList = new ArrayList<>();
257
+ if (jsonArray != null && jsonArray.length() > 0) {
258
+ for (int j = 0; j < jsonArray.length(); j++) {
259
+ JSONObject jsonObject = (JSONObject) jsonArray.opt(j);
260
+ QuecIotDataPointsModel.DataModel model1 = new QuecIotDataPointsModel.DataModel();
261
+ if (jsonObject != null) {
262
+ model1.setId(jsonObject.optInt("id"));
263
+ model1.setDataType(jsonObject.optString("dataType"));
264
+ if (model1.getDataType().equals(QuecIotDataPointsModel.DataModel.QuecIotDataPointDataType.STRUCT_NUM)) {
265
+ //结构体类型
266
+ model1.setValue(handleStruct(jsonObject));
267
+ } else {
268
+ //基本数据类型
269
+ model1.setValue(jsonObject.optString("value"));
270
+ }
271
+ }
272
+ childList.add(model1);
273
+ }
274
+ }
275
+ return childList;
276
+ }
277
+
278
+ /**
279
+ * 处理结构体数据类型
280
+ */
281
+ private List<QuecIotDataPointsModel.DataModel> handleStruct(JSONObject jobj) {
282
+ //结构体类型
283
+ List<QuecIotDataPointsModel.DataModel> childList = new ArrayList<>();
284
+ JSONArray jsonArray = jobj.optJSONArray("value");
285
+ if (jsonArray != null && jsonArray.length() > 0) {
286
+ for (int j = 0; j < jsonArray.length(); j++) {
287
+ JSONObject jsonObject = (JSONObject) jsonArray.opt(j);
288
+ QuecIotDataPointsModel.DataModel model = new QuecIotDataPointsModel.DataModel();
289
+ if (jsonObject != null) {
290
+ //基本数据类型
291
+ model.setId(jsonObject.optInt("id"));
292
+ model.setCode(jsonObject.optString("code"));
293
+ model.setDataType(jsonObject.optString("dataType"));
294
+ model.setValue(jsonObject.optString("value"));
295
+ }
296
+ childList.add(model);
297
+ }
298
+ }
299
+ return childList;
300
+ }
301
+
302
+ @ReactMethod
303
+ @Override
304
+ public void isWebSocketSubscribe(Promise promise) {
305
+ boolean isSubscribe = IotChannelController.getInstance().isWebsocketSubscribe(deviceModel);
306
+ WritableMap map = Arguments.createMap();
307
+ map.putBoolean("subscribe", isSubscribe);
308
+ promise.resolve(map);
309
+ }
310
+
311
+ @ReactMethod
312
+ @Override
313
+ public void getDeviceConnectingState(Promise promise) {
314
+ int state = IotChannelController.getInstance().getDeviceConnectingState(deviceModel);
315
+ WritableMap map = Arguments.createMap();
316
+ map.putInt("connectingState", state);
317
+ promise.resolve(map);
318
+ }
319
+
320
+ /**
321
+ * writeDpsByHttp
322
+ *
323
+ * @param dps – dps [ {id:0, type:BOOL, value:false} ,{id:1, type:INT, value:2}]
324
+ * @param deviceList – deviceList 设备列表 [{"deviceKey":"", "productKey":""}]
325
+ * @param type - 类型 1:透传 2:属性 3:服务
326
+ * @param extraData – {
327
+ * dataFormat 数据类型 1:Hex 2:Text(当type为透传时,需要指定 dataFormat)
328
+ * cacheTime 缓存时间,单位为秒,缓存时间范围 1-7776000 秒,启用缓存时必须设置缓存时间
329
+ * isCache 是否启用缓存 1:启用 2:不启用,默认不启用
330
+ * isCover 是否覆盖之前发送的相同的命令 1:覆盖 2:不覆盖,默认不覆盖,启用缓存时此参数有效
331
+ * <p>
332
+ * 查看接口定义
333
+ * }
334
+ **/
335
+ @ReactMethod
336
+ @Override
337
+ public void writeDpsByHttp(ReadableArray dps, ReadableArray deviceList, int type, final ReadableMap extraData,
338
+ final Promise promise) {
339
+ List<QuecIotDataPointsModel.DataModel> list = getData(dps, promise);
340
+ List<QuecIotDataPointsModel.DataModel> dpsList = new ArrayList<>(list);
341
+ List<BatchControlDevice> devices = new ArrayList<>();
342
+ for (int i = 0; i < deviceList.size(); i++) {
343
+ BatchControlDevice device = new BatchControlDevice();
344
+ ReadableMap map = deviceList.getMap(i);
345
+ if (map.hasKey("deviceKey")) {
346
+ device.setDeviceKey(map.getString("deviceKey"));
347
+ } else {
348
+ promise.reject("fail", "deviceKey is null");
349
+ return;
350
+ }
351
+ if (map.hasKey("productKey")) {
352
+ device.setProductKey(map.getString("productKey"));
353
+ } else {
354
+ promise.reject("fail", "productKey is null");
355
+ return;
356
+ }
357
+ devices.add(device);
358
+ }
359
+ DpsHttpExtraDataBean extraDataBean = new DpsHttpExtraDataBean();
360
+ if (extraData.hasKey("dataFormat")) {
361
+ int dataFormat = extraData.getInt("dataFormat");
362
+ extraDataBean.setDataFormat(dataFormat);
363
+ }
364
+ if (extraData.hasKey("cacheTime")) {
365
+ int cacheTime = extraData.getInt("cacheTime");
366
+ extraDataBean.setCacheTime(cacheTime);
367
+ }
368
+ if (extraData.hasKey("isCache")) {
369
+ int isCache = extraData.getInt("isCache");
370
+ extraDataBean.setIsCache(isCache);
371
+ }
372
+ if (extraData.hasKey("isCover")) {
373
+ int dataFormat = extraData.getInt("isCover");
374
+ extraDataBean.setCover(dataFormat);
375
+ }
376
+ IotChannelController.getInstance().writeDpsByHttp(dpsList, devices, type, extraDataBean, quecResult -> {
377
+ if (quecResult.successCode()) {
378
+ String str = QuecGsonUtil.INSTANCE.gsonString(quecResult);
379
+ try {
380
+ JSONObject jsonObject = new JSONObject(str);
381
+ WritableMap map = ReactNativeJson.convertJsonToMap(jsonObject);
382
+ promise.resolve(map);
383
+ } catch (JSONException e) {
384
+ promise.reject("fail", new Throwable(e));
385
+ }
386
+ } else if (quecResult.getCode() == 0) {
387
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, quecResult.getMsg());
388
+ } else {
389
+ try {
390
+ String str = QuecGsonUtil.INSTANCE.gsonString(quecResult);
391
+ JSONObject jsonObject = new JSONObject(str);
392
+ WritableMap map = ReactNativeJson.convertJsonToMap(jsonObject);
393
+ promise.reject("fail", map);
394
+ } catch (JSONException e) {
395
+ promise.reject("fail", new Throwable(e));
396
+ }
397
+ }
398
+ });
399
+ }
400
+
401
+ @Override
402
+ public void readDpsWithExtraData(ReadableArray dps, ReadableMap extraData, final Promise promise) {
403
+ deviceClient.readDps(getData(dps, promise), getDefaultDataSendMode(), getExtraData(extraData),
404
+ getSimpleCallback(promise));
405
+ }
406
+
407
+ @Override
408
+ public void readDpsWithExtraDataAndMode(ReadableArray dps, ReadableMap extraData, int mode, final Promise promise) {
409
+ deviceClient.readDps(getData(dps, promise), getDataSendMode(mode), getExtraData(extraData),
410
+ getSimpleCallback(promise));
411
+ }
412
+
413
+ @ReactMethod
414
+ @Override
415
+ public void writeDpsWithExtraData(ReadableArray dps, ReadableMap extraData, final Promise promise) {
416
+ deviceClient.writeDps(getData(dps, promise), getDefaultDataSendMode(), getExtraData(extraData),
417
+ getSimpleCallback(promise));
418
+ }
419
+
420
+ @ReactMethod
421
+ @Override
422
+ public void writeDpsWithExtraDataAndMode(ReadableArray dps, ReadableMap extraData, int mode,
423
+ final Promise promise) {
424
+ deviceClient.writeDps(getData(dps, promise), getDataSendMode(mode), getExtraData(extraData),
425
+ getSimpleCallback(promise));
426
+ }
427
+
428
+ private QuecIotChannelExtraData getExtraData(ReadableMap extraData) {
429
+ if (null == extraData) return null;
430
+ QuecIotChannelExtraData data = new QuecIotChannelExtraData();
431
+ if (extraData.hasKey("msgId") && extraData.getType("msgId") == ReadableType.Number) {
432
+ int msgId = extraData.getInt("msgId");
433
+ data.setMsgId((long) msgId);
434
+ }
435
+ if (extraData.hasKey("cacheTime") && extraData.getType("cacheTime") == ReadableType.Number) {
436
+ int cacheTime = extraData.getInt("cacheTime");
437
+ data.setMsgId((long) cacheTime);
438
+ }
439
+ if (extraData.hasKey("isCover") && extraData.getType("isCover") == ReadableType.Boolean) {
440
+ boolean isCover = extraData.getBoolean("isCover");
441
+ data.setCover(isCover);
442
+ }
443
+ if (extraData.hasKey("isSendJson") && extraData.getType("isSendJson") == ReadableType.Boolean) {
444
+ boolean isSendJson = extraData.getBoolean("isSendJson");
445
+ data.setSendJson(isSendJson);
446
+ }
447
+ return data;
448
+ }
449
+
450
+ @Override
451
+ @ReactMethod
452
+ public void getBleState(Promise promise) {
453
+ WritableMap writableMap = Arguments.createMap();
454
+ int state = IotChannelController.getInstance().getBleState();
455
+ writableMap.putString("state", "" + state);
456
+ promise.resolve(writableMap);
457
+ }
458
+
459
+ @Override
460
+ @ReactMethod
461
+ public void getTslAndAttrs(ReadableMap params, final Promise promise) {
462
+ final String productKey = ParamsValueUtils.getString(params, "productKey", "");
463
+ final String deviceKey = ParamsValueUtils.getString(params, "deviceKey", "");
464
+ final String gatewayPk = ParamsValueUtils.getString(params, "gatewayPk", "");
465
+ final String gatewayDk = ParamsValueUtils.getString(params, "gatewayDk", "");
466
+ final int filterType = ParamsValueUtils.getInt(params, "filterType", 0);
467
+
468
+ QuecDeviceService.INSTANCE.getProductTslAndDeviceBusinessAttributes(productKey, deviceKey, gatewayPk,
469
+ gatewayDk, null, null, filterType, new IDeviceTSLModelCallback() {
470
+ @Override
471
+ public void onResultCallback(List<QuecProductTSLPropertyModel<?>> list) {
472
+ WritableMap writableMap = Arguments.createMap();
473
+ try {
474
+ if (list != null && !list.isEmpty()) {
475
+ String jsonBack = QuecGsonUtil.INSTANCE.gsonString(list);
476
+ int startIndex = 0;
477
+ int maxLength = 1000;
478
+ while (startIndex < jsonBack.length()) {
479
+ int endIndex = Math.min(startIndex + maxLength, jsonBack.length());
480
+ QLog.i(TAG, "原生->js 物模型分段打印==" + jsonBack.substring(startIndex, endIndex));
481
+ startIndex += maxLength;
482
+ }
483
+ }
484
+
485
+
486
+ JSONArray jsonArray = new JSONArray(QuecGsonUtil.INSTANCE.gsonString(list));
487
+ WritableArray writableArray = ReactNativeJson.convertJsonToArray(jsonArray);
488
+ writableMap.putArray("data", writableArray);
489
+ promise.resolve(writableMap);
490
+ } catch (JSONException e) {
491
+ QLog.e(TAG, "获取物模型失败-json解析异常");
492
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e.getLocalizedMessage());
493
+ QLog.e(TAG, e);
494
+ }
495
+ }
496
+
497
+ @Override
498
+ public void onFail(Throwable throwable) {
499
+ QLog.e(TAG, "获取物模型失败-异常: " + throwable);
500
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, throwable);
501
+ }
502
+ });
503
+ }
504
+
505
+ @Override
506
+ @ReactMethod
507
+ public void readDpsWithMode(ReadableArray dps, int mode, final Promise promise) {
508
+ deviceClient.readDps(getData(dps, promise), getDataSendMode(mode), getSimpleCallback(promise));
509
+ }
510
+
511
+ @Override
512
+ @ReactMethod
513
+ public void writeDpsWithMode(ReadableArray dps, int mode, final Promise promise) {
514
+ deviceClient.writeDps(getData(dps, promise), getDataSendMode(mode), getSimpleCallback(promise));
515
+ }
516
+
517
+ @Override
518
+ @ReactMethod
519
+ public void getOnlineState(Promise promise) {
520
+ WritableMap writableMap = Arguments.createMap();
521
+ int state = deviceClient.getConnectState();
522
+ QLog.d("QuecRNDeviceModule", "onlineState " + state);
523
+ writableMap.putString("onlineState", "" + state);
524
+ promise.resolve(writableMap);
525
+ }
526
+
527
+ @Override
528
+ @ReactMethod
529
+ public void readDps(ReadableArray dps, final Promise promise) {
530
+ deviceClient.readDps(getData(dps, promise), getSimpleCallback(promise));
531
+ }
532
+
533
+ @Override
534
+ @ReactMethod
535
+ public void writeDps(ReadableArray dps, final Promise promise) {
536
+ deviceClient.writeDps(getData(dps, promise), getSimpleCallback(promise));
537
+ }
538
+
539
+ @Override
540
+ @ReactMethod
541
+ public void writeTransparent(String data, int mode, ReadableMap extraData, Promise promise) {
542
+ byte[] sendData;
543
+ try {
544
+ sendData = Base64.decode(data, Base64.DEFAULT);
545
+ } catch (Exception e) {
546
+ QLog.e(TAG, e);
547
+ promise.reject("-1", e);
548
+ return;
549
+ }
550
+ deviceClient.writeTransparent(sendData, getSimpleCallback(promise));
551
+ }
552
+
553
+ @Override
554
+ @ReactMethod
555
+ public void connectChannel(int mode) {
556
+ deviceClient.connectWithMode(getDataSendMode(mode));
557
+
558
+ }
559
+
560
+ @Override
561
+ @ReactMethod
562
+ public void disconnectChannel(int type) {
563
+ switch (type) {
564
+ case 1:
565
+ deviceClient.disconnectWithType(QuecIotChannelType.QuecIotChannelTypeWifi);
566
+ break;
567
+ case 2:
568
+ deviceClient.disconnectWithType(QuecIotChannelType.QuecIotChannelTypeWS);
569
+ break;
570
+ case 3:
571
+ deviceClient.disconnectWithType(QuecIotChannelType.QuecIotChannelTypeBLE);
572
+ break;
573
+ case 4:
574
+ deviceClient.disconnectWithType(QuecIotChannelType.QuecIotChannelTypeMatter);
575
+ break;
576
+ default:
577
+ deviceClient.disconnectWithType(QuecIotChannelType.QuecIotChannelTypeUnknown);
578
+ break;
579
+ }
580
+ }
581
+
582
+ /**
583
+ * 获取websocket是否登录成功
584
+ *
585
+ * @param isLoginCallback Func 接受是否登录websocket回调 已登录成功 true 登录失败 false
586
+ * @available: 1.0.0
587
+ * @platform: all
588
+ */
589
+ @Override
590
+ @ReactMethod
591
+ public void isWebSocketLoginCallback(Callback isLoginCallback) {
592
+ boolean result = WebSocketServiceLocater.getService(IWebSocketService.class).isWebSocketLoginCallback();
593
+ isLoginCallback.invoke(result);
594
+ }
595
+
596
+ /**
597
+ * 订阅设备
598
+ *
599
+ * @param list 订阅设备列表,订阅结果QuecDeviceServiceWebSocketDelegate返回
600
+ * [
601
+ * {
602
+ * "deviceKey": "1234567890",
603
+ * "messageType": [
604
+ * "ONLINE"
605
+ * ],
606
+ * "productKey": "p12345"
607
+ * },
608
+ * {
609
+ * "deviceKey": "1234567890",
610
+ * "messageType": [
611
+ * "ONLINE",
612
+ * "STATUS"
613
+ * ],
614
+ * "productKey": "p12345"
615
+ * }
616
+ * ]
617
+ * @available: 1.0.0
618
+ * @platform: all
619
+ */
620
+ @Override
621
+ @ReactMethod
622
+ public void subscribeDevicesWithList(ReadableArray list) {
623
+ if (list != null && list.size() > 0) {
624
+ for (int i = 0; i < list.size(); i++) {
625
+ ReadableMap map = list.getMap(i);
626
+ String productKey = ParamsValueUtils.getString(map, "productKey", "");
627
+ String deviceKey = ParamsValueUtils.getString(map, "deviceKey", "");
628
+ WebSocketServiceLocater.getService(IWebSocketService.class).subscribeDevice(deviceKey, productKey);
629
+ }
630
+ }
631
+ }
632
+
633
+ /**
634
+ * 取消订阅设备
635
+ *
636
+ * @param list 取消订阅设备列表,取消订阅结果QuecDeviceServiceWebSocketDelegate返回
637
+ * [
638
+ * {
639
+ * "deviceKey": "1234567890",
640
+ * "productKey": "p12345"
641
+ * },
642
+ * {
643
+ * "deviceKey": "1234567890",
644
+ * "productKey": "p12345"
645
+ * }
646
+ * ]
647
+ * @available: 1.0.0
648
+ * @platform: all
649
+ */
650
+ @Override
651
+ @ReactMethod
652
+ public void unSubscribeDevicesWithList(ReadableArray list) {
653
+ if (list != null && list.size() > 0) {
654
+ for (int i = 0; i < list.size(); i++) {
655
+ ReadableMap map = list.getMap(i);
656
+ String productKey = ParamsValueUtils.getString(map, "productKey", "");
657
+ String deviceKey = ParamsValueUtils.getString(map, "deviceKey", "");
658
+ WebSocketServiceLocater.getService(IWebSocketService.class).unsubscribeDevice(deviceKey, productKey);
659
+ }
660
+ }
661
+ }
662
+
663
+ /**
664
+ * 获取设备业务属性值
665
+ *
666
+ * @param params 发送数据,需要在delegate的websocketDidOpen回调之后才能调用
667
+ * 透传
668
+ * {
669
+ * "cmd": "send",
670
+ * "data": {
671
+ * "cacheTime": 3600,
672
+ * "dataFormat": "Text",
673
+ * "deviceKey": "866123456789015",
674
+ * "isCache": true,
675
+ * "productKey": "p12345",
676
+ * "raw": "123456",
677
+ * "type": "RAW"
678
+ * }
679
+ * }
680
+ * 物模型
681
+ * {
682
+ * "cmd": "send",
683
+ * "data": {
684
+ * "deviceKey": "1234567890",
685
+ * "kv": "[{\"id\":5,\"name\":\"openapi\",\"type\":\"BOOL\",\"value\":\"true\"}]",
686
+ * "productKey": "p12345",
687
+ * "type": "WRITE-ATTR"
688
+ * }
689
+ * }
690
+ * @available: 1.0.0
691
+ * @platform: all
692
+ */
693
+ @Override
694
+ @ReactMethod
695
+ public void sendDataToDeviceByWebSocketWithDataDict(ReadableMap params) {
696
+ QLog.d(TAG, "sendDataToDeviceByWebSocketWithDataDict");
697
+ if (params.hasKey("data")) {
698
+
699
+ try {
700
+ String info = new JSONObject(params.toString()).optString("NativeMap");
701
+ if (!TextUtils.isEmpty(info)) {
702
+ WsManager.getInstance().sendMessage(info);
703
+ } else {
704
+ WsManager.getInstance().sendMessage(params.toString());
705
+ }
706
+ } catch (Exception e) {
707
+ QLog.e(TAG, e);
708
+ }
709
+ }
710
+ }
711
+
712
+ /**
713
+ * 获取设备列表
714
+ *
715
+ * @param pageNumber number 页码
716
+ * @param pageSize number 页大小
717
+ * @param promise promise 执行回调
718
+ * callback {"data": {"list" : [], "total" : 12}}
719
+ * @available: 1.0.0
720
+ * @platform: all
721
+ */
722
+ @Override
723
+ @ReactMethod
724
+ public void getDeviceListWithPageNumber(int pageNumber, int pageSize, final Promise promise) {
725
+ String uid = MmkvManager.getInstance().get(QuecMainConstant.MMKV_KEY_UID, "");
726
+ if (!NetUtils.isNetworkConnected(getReactApplicationContext())) {
727
+ String cachData = QuecCacheDataUtils.getUserDeviceListCacheData(uid);
728
+ if (!TextUtils.isEmpty(cachData)) {
729
+ List<DeviceModel> dataList = QuecGsonUtil.INSTANCE.gsonTolist(cachData, DeviceModel.class);
730
+ QuecPageResponse<DeviceModel> response = new QuecPageResponse<>();
731
+ response.setList(dataList);
732
+ response.setPageNum(pageNumber);
733
+ response.setPageSize(pageSize);
734
+ QuecResult<QuecPageResponse<DeviceModel>> result = new QuecResult<>(true, response,
735
+ QuecResult.SUCCESS_CODE);
736
+ String resultStr = QuecGsonUtil.INSTANCE.gsonString(result);
737
+ ResponseUtils.handlerResponse(promise, resultStr, viewModel);
738
+ }
739
+ return;
740
+ }
741
+
742
+ QuecDeviceListParamsModel paramsModel = new QuecDeviceListParamsModel();
743
+ paramsModel.setPageNumber(pageNumber);
744
+ paramsModel.setPageSize(pageSize);
745
+ QuecDeviceService.INSTANCE.getDeviceList(paramsModel, quecResult -> {
746
+ if (quecResult.isSuccess()) {
747
+ if (pageNumber <= 1) {
748
+ deviceModelList.clear();
749
+ }
750
+ if (quecResult.getData() != null) {
751
+ QuecPageResponse<QuecDeviceModel> response = quecResult.getData();
752
+ if (response.getList() != null && !response.getList().isEmpty()) {
753
+ if (response.getPageNum() <= 1) {
754
+ deviceModelList.clear();
755
+ }
756
+ deviceModelList.addAll(response.getList());
757
+ String json = QuecGsonUtil.INSTANCE.gsonString(deviceModelList);
758
+ QuecCacheDataUtils.saveUserDeviceListData(QuecBaseApp.getInstance(), uid, json);
759
+ checkDeviceList(response.getList());
760
+ }
761
+ }
762
+ }
763
+ ResponseUtils.handlerResponse(promise, quecResult, viewModel);
764
+ });
765
+ }
766
+
767
+ /**
768
+ * 获取设备业务物模型属性值
769
+ *
770
+ * @param params map
771
+ * productKey string 产品key
772
+ * deviceKey string 设备key
773
+ * codeList string 非必填 查询的属性标识符
774
+ * gatewayDk string 网关设备的 Device Key
775
+ * gatewayPk string 网关设备的 Product Key
776
+ * 和查询类型配合使用,如果查询多个属性,使用英文逗号分隔
777
+ * type string 非必填 查询类型
778
+ * 1 查询设备基础属性
779
+ * 2 查询物模型属性
780
+ * 3 查询定位信息
781
+ * 查询类型可以单选和多选,如果需要查询多个类型的属性值,使用英文逗号分隔
782
+ * @param promise promise 执行回调
783
+ * @available: 1.0.0
784
+ * @platform: all
785
+ */
786
+ @Override
787
+ @ReactMethod
788
+ public void getProductTSLWithProductKey(ReadableMap params, final Promise promise) {
789
+ if (processNoNetWork(promise)) {
790
+ return;
791
+ }
792
+ String productKey = ParamsValueUtils.getString(params, "productKey", "");
793
+ String deviceKey = ParamsValueUtils.getString(params, "deviceKey", "");
794
+ String codeStr = ParamsValueUtils.getString(params, "codeList", "");
795
+ String typeStr = ParamsValueUtils.getString(params, "type", "");
796
+ String gatewayPk = ParamsValueUtils.getString(params, "gatewayPk", "");
797
+ String gatewayDk = ParamsValueUtils.getString(params, "gatewayDk", "");
798
+
799
+ QuecDeviceService.INSTANCE.getProductTslAndDeviceBusinessAttributes(productKey, deviceKey, gatewayPk,
800
+ gatewayDk, codeStr, typeStr, new IDeviceTSLModelCallback() {
801
+ @Override
802
+ public void onResultCallback(List<QuecProductTSLPropertyModel<?>> list) {
803
+ WritableMap writableMap = Arguments.createMap();
804
+ try {
805
+ JSONArray jsonArray = new JSONArray(QuecGsonUtil.INSTANCE.gsonString(list));
806
+ WritableArray writableArray = ReactNativeJson.convertJsonToArray(jsonArray);
807
+ writableMap.putArray("data", writableArray);
808
+ promise.resolve(writableMap);
809
+ } catch (JSONException e) {
810
+ QLog.e(TAG, e);
811
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
812
+ }
813
+ }
814
+
815
+ @Override
816
+ public void onFail(Throwable throwable) {
817
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, throwable);
818
+ }
819
+ });
820
+ }
821
+
822
+ @Override
823
+ @ReactMethod
824
+ public void getDeviceBusinessAttributesWithProductKey(ReadableMap map, final Promise promise) {
825
+ if (processNoNetWork(promise)) {
826
+ return;
827
+ }
828
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
829
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
830
+ String codeList = ParamsValueUtils.getString(map, "codeList", "");
831
+ String type = ParamsValueUtils.getString(map, "type", "");
832
+ String gatewayPk = ParamsValueUtils.getString(map, "gatewayPk", "");
833
+ String gatewayDk = ParamsValueUtils.getString(map, "gatewayDk", "");
834
+
835
+ QuecDeviceService.INSTANCE.getDeviceBusinessAttributes(pk, dk, gatewayPk, gatewayDk, codeList, type,
836
+ getCallback(promise));
837
+ }
838
+
839
+ /**
840
+ * 更改分享设备名称
841
+ *
842
+ * @param deviceName string 设备名称
843
+ * @param shareCode string 分享码
844
+ * @param promise promise 执行回调
845
+ * @available: 1.0.0
846
+ * @platform: all
847
+ */
848
+ @Override
849
+ @ReactMethod
850
+ public void updateDeviceNameByShareUserWithDeviceName(String deviceName, String shareCode, final Promise promise) {
851
+ if (processNoNetWork(promise)) {
852
+ return;
853
+ }
854
+ QuecDeviceShareService.INSTANCE.updateDeviceNameByShareUser(deviceName, shareCode, result -> {
855
+ if (ResponseUtils.handlerResponse(promise, result, viewModel)) {
856
+ updateHomeList();
857
+ }
858
+ });
859
+ }
860
+
861
+ /**
862
+ * 更改分享设备名称
863
+ *
864
+ * @param deviceName string deviceName
865
+ * @param productKey string product key
866
+ * @param deviceKey string deviceKey
867
+ * @param promise promise 执行回调
868
+ * @available: 1.0.0
869
+ * @platform: all
870
+ */
871
+ @Override
872
+ @ReactMethod
873
+ public void updateDeviceName(String deviceName, String productKey, String deviceKey, final Promise promise) {
874
+ if (processNoNetWork(promise)) {
875
+ return;
876
+ }
877
+ QuecDeviceService.INSTANCE.updateDeviceName(deviceName, productKey, deviceKey, result -> {
878
+ if (ResponseUtils.handlerResponse(promise, result, viewModel)) {
879
+ updateHomeList();
880
+ }
881
+ });
882
+ }
883
+
884
+ /**
885
+ * 查询网关设备下子设备列表
886
+ *
887
+ * @param params deviceKey string 必传 网关设备deviceKey
888
+ * productKey string 必传 网关设备productKey
889
+ * pageNumber number 必传 页码
890
+ * pageSize number 必传 页大小
891
+ * @param promise promise 执行回调
892
+ * callback {"data": {"list" : [], "total" : 12}}
893
+ * @available: 1.0.0
894
+ * @platform: all
895
+ */
896
+ @Override
897
+ @ReactMethod
898
+ public void getGatewayDeviceChildListWithParams(ReadableMap params, final Promise promise) {
899
+ if (processNoNetWork(promise)) {
900
+ return;
901
+ }
902
+ String deviceKey = ParamsValueUtils.getString(params, "deviceKey", "");
903
+ String productKey = ParamsValueUtils.getString(params, "productKey", "");
904
+ int pageNumber = ParamsValueUtils.getInt(params, "pageNumber", -1);
905
+ int pageSize = ParamsValueUtils.getInt(params, "pageSize", -1);
906
+
907
+ QuecDeviceGroupService.INSTANCE.getGatewayDeviceChildList(deviceKey, productKey, pageNumber, pageSize,
908
+ getCallback(promise));
909
+ }
910
+
911
+ /**
912
+ * 设备解绑
913
+ *
914
+ * @param deviceKey string device key
915
+ * @param productKey string product key
916
+ * @param promise promise 执行回调
917
+ * @available: 1.0.0
918
+ * @platform: all
919
+ */
920
+ @Override
921
+ @ReactMethod
922
+ public void unbindDeviceWithDeviceKey(final String deviceKey, final String productKey, final Promise promise) {
923
+ if (processNoNetWork(promise)) {
924
+ return;
925
+ }
926
+ QuecDeviceService.INSTANCE.unbindDevice(deviceKey, productKey, false, null, null, result -> {
927
+ if (ResponseUtils.handlerResponse(promise, result, viewModel)) {
928
+ unbindDeviceAndUpDateHomeList(channelId);
929
+ //解绑设备后,ipc隐私协议要重置
930
+ IpcUtil.savePrivacyState(productKey, deviceKey, false);
931
+ //解绑设备后,ipc视频、截图文件清理
932
+ IpcUtil.clearIpcVideoPhotoMMKV(productKey, deviceKey);
933
+ }
934
+ });
935
+ }
936
+
937
+ /**
938
+ * 设备解绑
939
+ *
940
+ * @param shareCode string 分享码
941
+ * @param promise promise 执行回调
942
+ * @available: 1.0.0
943
+ * @platform: all
944
+ */
945
+ @Override
946
+ @ReactMethod
947
+ public void unShareDeviceByShareUserWithShareCode(String shareCode, final Promise promise) {
948
+ if (processNoNetWork(promise)) {
949
+ return;
950
+ }
951
+ QuecDeviceShareService.INSTANCE.unShareDeviceByShareUser(shareCode, result -> {
952
+ if (ResponseUtils.handlerResponse(promise, result, viewModel)) {
953
+ unbindDeviceAndUpDateHomeList(channelId);
954
+ }
955
+ });
956
+ }
957
+
958
+ @Override
959
+ @ReactMethod
960
+ public void unShareDeviceByShareUserWithShareCodeIpc(final String pk, final String dk, String shareCode,
961
+ final Promise promise) {
962
+ if (processNoNetWork(promise)) {
963
+ return;
964
+ }
965
+ QuecDeviceShareService.INSTANCE.unShareDeviceByShareUser(shareCode, result -> {
966
+ if (ResponseUtils.handlerResponse(promise, result, viewModel)) {
967
+ unbindDeviceAndUpDateHomeList(channelId);
968
+ //解绑设备后,ipc隐私协议同意要重置
969
+ IpcUtil.savePrivacyState(pk, dk, false);
970
+ //解绑设备后,ipc视频、截图文件清理
971
+ IpcUtil.clearIpcVideoPhotoMMKV(pk, dk);
972
+ }
973
+ });
974
+ }
975
+
976
+ @Override
977
+ @ReactMethod
978
+ public void subscribeDevice(String pk, String dk) {
979
+ String channelId = getChannelId(pk, dk);
980
+ QLog.d(TAG, "subscribeDevice:channelId=" + channelId);
981
+ otherChannelIds.add(channelId);
982
+ WebSocketServiceLocater.getService(IWebSocketService.class).subscribeDevice(dk, pk);
983
+ }
984
+
985
+ @Override
986
+ @ReactMethod
987
+ public void unSubscribeDevice(String pk, String dk) {
988
+ String channelId = getChannelId(pk, dk);
989
+ QLog.d(TAG, "unSubscribeDevice:channelId=" + channelId);
990
+ otherChannelIds.remove(channelId);
991
+ WebSocketServiceLocater.getService(IWebSocketService.class).unsubscribeDevice(dk, pk);
992
+ }
993
+
994
+ @Override
995
+ @ReactMethod
996
+ public void deviceAssociationWithList(ReadableArray list, ReadableMap master, String fid, Promise promise) {
997
+ if (processNoNetWork(promise)) {
998
+ return;
999
+ }
1000
+ ArrayList<QuecDeviceModel> slaveDTOS = new ArrayList<>();
1001
+ QuecDeviceModel masterDTO = new QuecDeviceModel();
1002
+ String pk = ParamsValueUtils.getString(master, PRODUCT_KEY_NAME, "");
1003
+ String dk = ParamsValueUtils.getString(master, DEVICE_KEY_NAME, "");
1004
+ masterDTO.setDeviceKey(dk);
1005
+ masterDTO.setProductKey(pk);
1006
+
1007
+ if (list != null && list.size() > 0) {
1008
+ try {
1009
+ JSONArray jsonArray = QuecReadableMapUtil.convertArrayToJson(list);
1010
+ for (int i = 0; i < jsonArray.length(); i++) {
1011
+ JSONObject jsonObject = jsonArray.optJSONObject(i);
1012
+ String slavePk = jsonObject.optString(PRODUCT_KEY_NAME, "");
1013
+ String slaveDk = jsonObject.optString(DEVICE_KEY_NAME, "");
1014
+ QuecDeviceModel slaveDTO = new QuecDeviceModel();
1015
+ slaveDTO.setProductKey(slavePk);
1016
+ slaveDTO.setDeviceKey(slaveDk);
1017
+ slaveDTOS.add(slaveDTO);
1018
+ }
1019
+ } catch (JSONException e) {
1020
+ QLog.e(TAG, e.toString());
1021
+ }
1022
+ }
1023
+
1024
+ QuecDeviceAssociateService.INSTANCE.deviceAssociation(slaveDTOS, masterDTO, getCallback(promise));
1025
+ }
1026
+
1027
+ @Override
1028
+ @ReactMethod
1029
+ public void deviceAssociation(ReadableMap master, String fid, String codeList, Promise promise) {
1030
+ if (processNoNetWork(promise)) {
1031
+ return;
1032
+ }
1033
+ String pk = ParamsValueUtils.getString(master, PRODUCT_KEY_NAME, "");
1034
+ String dk = ParamsValueUtils.getString(master, DEVICE_KEY_NAME, "");
1035
+
1036
+ QuecDeviceModel model = new QuecDeviceModel();
1037
+ model.setProductKey(pk);
1038
+ model.setDeviceKey(dk);
1039
+ QuecDeviceAssociateService.INSTANCE.getDeviceAssociationInfo(model, codeList, getCallback(promise));
1040
+ }
1041
+
1042
+ @Override
1043
+ @ReactMethod
1044
+ public void deviceDisassociation(ReadableMap device, String fid, Promise promise) {
1045
+ if (processNoNetWork(promise)) {
1046
+ return;
1047
+ }
1048
+ String pk = ParamsValueUtils.getString(device, PRODUCT_KEY_NAME, "");
1049
+ String dk = ParamsValueUtils.getString(device, DEVICE_KEY_NAME, "");
1050
+
1051
+ QuecDeviceModel bean = new QuecDeviceModel();
1052
+ bean.setProductKey(pk);
1053
+ bean.setDeviceKey(dk);
1054
+ bean.setFid(fid);
1055
+
1056
+ QuecDeviceAssociateService.INSTANCE.deviceDisassociation(bean, getCallback(promise));
1057
+ }
1058
+
1059
+ @Override
1060
+ @ReactMethod
1061
+ public void deviceAssociationConfig(String pk, Promise promise) {
1062
+ if (processNoNetWork(promise)) {
1063
+ return;
1064
+ }
1065
+
1066
+ QuecDeviceAssociateService.INSTANCE.deviceAssociationConfig(pk, getCallback(promise));
1067
+ }
1068
+
1069
+ @ReactMethod
1070
+ @Override
1071
+ public void getDeviceOnlineState(String pk, String dk, Promise promise) {
1072
+ WritableMap writableMap = Arguments.createMap();
1073
+ String channelId = pk + "_" + dk;
1074
+ int state = IotChannelController.getInstance().getOnlineState(channelId);
1075
+ QLog.d("QuecRNDeviceModule", "onlineState " + state);
1076
+ writableMap.putString("onlineState", "" + state);
1077
+ promise.resolve(writableMap);
1078
+ }
1079
+
1080
+ //获取设备属性图表列表
1081
+ @ReactMethod
1082
+ @Override
1083
+ public void getPropertyChartListWithParams(ReadableMap map, final Promise promise) {
1084
+ if (processNoNetWork(promise)) {
1085
+ return;
1086
+ }
1087
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1088
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1089
+ String attributeCode = ParamsValueUtils.getString(map, "attributeCode", "");
1090
+ int countType = ParamsValueUtils.getInt(map, "countType", -1);
1091
+ int timeGranularity = ParamsValueUtils.getInt(map, "timeGranularity", -1);
1092
+ double startTimestamp = ParamsValueUtils.getDouble(map, "startTimestamp", 0);
1093
+ double endTimestamp = ParamsValueUtils.getDouble(map, "endTimestamp", 0);
1094
+
1095
+ QuecDeviceStatisticsService.INSTANCE.getPropertyChartList(pk, dk, (long) startTimestamp, (long) endTimestamp,
1096
+ attributeCode, null, null, countType, timeGranularity, result -> {
1097
+ if (!result.isSuccess()) {
1098
+ ResponseUtils.handlerError(promise, result.getCode(), result.getMsg(), viewModel);
1099
+ return;
1100
+ }
1101
+
1102
+ try {
1103
+ WritableMap writableMap = Arguments.createMap();
1104
+ JSONObject obj =
1105
+ new JSONObject(QuecGsonUtil.INSTANCE.gsonString(new ResponseUtils.Content(result.getData())));
1106
+ JSONArray jarray = obj.getJSONArray("data");
1107
+ WritableArray wArray = Arguments.createArray();
1108
+ for (int i = 0; i < jarray.length(); i++) {
1109
+ JSONObject jobj = (JSONObject) jarray.get(i);
1110
+ WritableMap child = Arguments.createMap();
1111
+ String useCode = jobj.optString("propertyCode", "");
1112
+ if (TextUtils.isEmpty(useCode) || "null".equals(useCode)) {
1113
+ child.putNull("propertyCode");
1114
+ child.putNull("yaxisData");
1115
+ child.putNull("xaxisData");
1116
+ } else {
1117
+ JSONArray jarray11 = jobj.getJSONArray("yaxisData");
1118
+ JSONArray jarray22 = jobj.getJSONArray("xaxisData");
1119
+ WritableArray wArray11 = Arguments.createArray();
1120
+ WritableArray wArray22 = Arguments.createArray();
1121
+ for (int x = 0; x < jarray11.length(); x++) {
1122
+ double num = jarray11.getDouble(x);
1123
+ wArray11.pushDouble(num);
1124
+ }
1125
+ for (int y = 0; y < jarray22.length(); y++) {
1126
+ String date = jarray22.getString(y);
1127
+ wArray22.pushString(date);
1128
+ }
1129
+ child.putString("propertyCode", jobj.optString("propertyCode", ""));
1130
+ child.putArray("yaxisData", wArray11);
1131
+ child.putArray("xaxisData", wArray22);
1132
+ }
1133
+ wArray.pushMap(child);
1134
+ }
1135
+ writableMap.putArray("data", wArray);
1136
+ promise.resolve(writableMap);
1137
+ } catch (Exception e) {
1138
+ QLog.i(TAG, "---catch property catch property catch property---");
1139
+ QLog.e(TAG, e);
1140
+ WritableMap writableMap = Arguments.createMap();
1141
+ WritableArray wArray = Arguments.createArray();
1142
+ WritableMap child = Arguments.createMap();
1143
+ WritableArray wArray11 = Arguments.createArray();
1144
+ WritableArray wArray22 = Arguments.createArray();
1145
+ child.putArray("yaxisData", wArray11);
1146
+ child.putArray("xaxisData", wArray22);
1147
+ wArray.pushMap(child);
1148
+ writableMap.putArray("data", wArray);
1149
+ promise.resolve(writableMap);
1150
+ }
1151
+ });
1152
+ }
1153
+
1154
+ //分享人查询设备的被分享人列表
1155
+ @ReactMethod
1156
+ @Override
1157
+ public void getDeviceShareUserListWithDeviceKey(String dk, String pk, final Promise promise) {
1158
+ if (processNoNetWork(promise)) {
1159
+ return;
1160
+ }
1161
+ QuecDeviceShareService.INSTANCE.getDeviceShareUserList(dk, pk, getCallback(promise));
1162
+ }
1163
+
1164
+ //分享人设置分享信息
1165
+ @ReactMethod
1166
+ @Override
1167
+ public void setShareInfoByOwnerWithDeviceKey(ReadableMap map, final Promise promise) {
1168
+ if (processNoNetWork(promise)) {
1169
+ return;
1170
+ }
1171
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1172
+ Double acceptingExpireTime = ParamsValueUtils.getDouble(map, "acceptingExpireTime", 0.0);
1173
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1174
+ int coverMark = ParamsValueUtils.getInt(map, "coverMark", 0);
1175
+ long sharingExpireAt = 0L;
1176
+ QuecDeviceShareService.INSTANCE.setShareInfoByOwner(dk, pk, acceptingExpireTime.longValue(), coverMark, false
1177
+ , sharingExpireAt, getCallback(promise));
1178
+ }
1179
+
1180
+ //分享人取消分享
1181
+ @ReactMethod
1182
+ @Override
1183
+ public void unShareDeviceByOwnerWithShareCode(String shareCode, final Promise promise) {
1184
+ if (processNoNetWork(promise)) {
1185
+ return;
1186
+ }
1187
+ QuecDeviceShareService.INSTANCE.unShareDeviceByOwner(shareCode, getCallback(promise));
1188
+ }
1189
+
1190
+ //获取设备历史轨迹
1191
+ @ReactMethod
1192
+ @Override
1193
+ public void getLocationHistoryWithParams(ReadableMap map, final Promise promise) {
1194
+ if (processNoNetWork(promise)) {
1195
+ return;
1196
+ }
1197
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1198
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1199
+ double startTimestamp = ParamsValueUtils.getDouble(map, "startTimestamp", 0);
1200
+ double endTimestamp = ParamsValueUtils.getDouble(map, "endTimestamp", 0);
1201
+ String locateTypes = ParamsValueUtils.getString(map, "locateTypes", "");
1202
+
1203
+ QuecDeviceStatisticsService.INSTANCE.getLocationHistory(pk, dk, (long) startTimestamp, (long) endTimestamp,
1204
+ null, null, locateTypes, getCallback(promise));
1205
+ }
1206
+
1207
+ /**
1208
+ * WebSocket 已打开事件
1209
+ *
1210
+ * @param object 事件数据 data = {"code":"this is code", @"message":" this is reason"}
1211
+ * reminder.data = {}
1212
+ * @available: 1.0.0
1213
+ * @platform: all
1214
+ */
1215
+ @Override
1216
+ public void onWebSocketDidOpen(ReadableMap object) {
1217
+ ReactApplicationContext context = getReactApplicationContext();
1218
+ if (context != null && context.hasActiveCatalystInstance()) {
1219
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("onWebSocketDidOpen", object);
1220
+ }
1221
+ }
1222
+
1223
+ /**
1224
+ * WebSocket 错误事件
1225
+ *
1226
+ * @param object 事件数据 data = {"code":"this is code", @"message":" this is reason"}
1227
+ * @available: 1.0.0
1228
+ * @platform: all
1229
+ */
1230
+ @Override
1231
+ public void onWebSocketDidError(ReadableMap object) {
1232
+ ReactApplicationContext context = getReactApplicationContext();
1233
+ if (context != null && context.hasActiveCatalystInstance()) {
1234
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("onWebSocketDidError", object);
1235
+ }
1236
+ }
1237
+
1238
+ /**
1239
+ * WebSocket 消息事件
1240
+ *
1241
+ * @param object 事件数据
1242
+ * object.data = {
1243
+ * "cmd": "message",
1244
+ * "data": {
1245
+ * "createdAt": 1609316592000,
1246
+ * "data": {
1247
+ * "value": 1
1248
+ * },
1249
+ * "deviceKey": "866123456789015",
1250
+ * "productKey": "123456",
1251
+ * "ticket": "5f9924d171977c33bc5ad1b1",
1252
+ * "type": "ONLINE"
1253
+ * }
1254
+ * }
1255
+ * error
1256
+ * {
1257
+ * cmd = error;
1258
+ * data = {
1259
+ * code = 4010;
1260
+ * msg = "user not logged in";
1261
+ * reqMsg = "";
1262
+ * };
1263
+ * @available: 1.0.0
1264
+ * @platform: all
1265
+ */
1266
+ @Override
1267
+ public void onWebSocketDidReceiveMessage(ReadableMap object) {
1268
+ QLog.d(TAG, "onWebSocketDidReceiveMessage");
1269
+ ReactApplicationContext context = getReactApplicationContext();
1270
+ if (context != null && context.hasActiveCatalystInstance()) {
1271
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("onWebSocketDidReceiveMessage", object);
1272
+ }
1273
+ }
1274
+
1275
+ @Override
1276
+ public void deviceAssociationSelected(ReadableArray list) {
1277
+ WritableMap writableMap = Arguments.createMap();
1278
+ writableMap.putArray("list", list);
1279
+ ReactApplicationContext context = getReactApplicationContext();
1280
+ if (context != null && context.hasActiveCatalystInstance()) {
1281
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("deviceAssociationSelected", writableMap);
1282
+ }
1283
+ }
1284
+
1285
+ @Override
1286
+ public void onDeviceStatusUpdate(ReadableMap object) {
1287
+ try {
1288
+ latch.await(); // 等待初始化完成
1289
+ ReactApplicationContext context = getReactApplicationContext();
1290
+ if (context != null && context.hasActiveCatalystInstance()) {
1291
+ context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onDeviceStatusUpdate"
1292
+ , object);
1293
+ }
1294
+ } catch (InterruptedException e) {
1295
+ QLog.e(TAG, "onDeviceStatusUpdate error: " + e);
1296
+ }
1297
+ }
1298
+
1299
+ @NonNull
1300
+ @Override
1301
+ public String getName() {
1302
+ return "QuecRNDeviceModule";
1303
+ }
1304
+
1305
+ public void sendConnectingStateEvent(int state) {
1306
+ QLog.i(TAG, "onConnectingState " + state);
1307
+ WritableMap map = Arguments.createMap();
1308
+ map.putInt("connectingState", state);
1309
+ onDeviceConnectingState(map);
1310
+ }
1311
+
1312
+ private void initData() {
1313
+ QLog.i(TAG, "reactnativeModule init");
1314
+ String json = MmkvManager.getInstance().get(Constants.QUEC_DEVICE_MODEL, "");
1315
+
1316
+ if (TextUtils.isEmpty(json)) {
1317
+ return;
1318
+ }
1319
+ QuecDeviceModel model = new Gson().fromJson(json, QuecDeviceModel.class);
1320
+ updateDeviceModel(model);
1321
+ //如果设备未连接,自动连接
1322
+ if (deviceClient.getConnectState() == 0) {
1323
+ deviceClient.connect();
1324
+ }
1325
+ }
1326
+
1327
+ private void updateDeviceModel(QuecDeviceModel deviceModel) {
1328
+ QLog.d(TAG, "updateDeviceModel::" + QuecGsonUtil.INSTANCE.gsonString(deviceModel));
1329
+ if (deviceModel == null || TextUtils.isEmpty(deviceModel.getDeviceKey()) || TextUtils.isEmpty(deviceModel.getProductKey())) {
1330
+ return;
1331
+ }
1332
+ this.deviceModel = deviceModel;
1333
+ this.deviceClient.removeListener(listener);
1334
+ this.deviceClient = QuecDeviceClient.Companion.initWithDevice(deviceModel);
1335
+ this.deviceClient.addListener(listener);
1336
+
1337
+ channelId = deviceModel.getChannelId();
1338
+ QLog.i(TAG, "channelId===" + channelId);
1339
+ }
1340
+
1341
+ /**
1342
+ * 初始化 注册监听上行数据 事件
1343
+ */
1344
+ // private void initIotChannelEvent() {
1345
+ // IotChannelController.getInstance().setListener(listener);
1346
+ // }
1347
+ @Subscribe(threadMode = ThreadMode.MAIN)
1348
+ public void onEvent(Object main) {
1349
+ // QLog.d(TAG, "----------------------module js event--------------------");
1350
+ QLog.d(TAG, "onEvent::" + QuecGsonUtil.INSTANCE.gsonString(main));
1351
+ if (main instanceof SocketEvent) {
1352
+ SocketEvent socketEvent = (SocketEvent) main;
1353
+ String socketType = socketEvent.getType();
1354
+ switch (socketType) {
1355
+ case EventType.EVENT_TYPE_LOGIN_SUCCESS:
1356
+ //"data":{"code":1,"msg":"succ"}}
1357
+ QLog.i(TAG, "login success--:" + socketEvent.getData());
1358
+ try {
1359
+ JSONObject obj = new JSONObject(socketEvent.getData());
1360
+ WritableMap writableMap = Arguments.createMap();
1361
+ writableMap.putInt("code", obj.getInt("code"));
1362
+ writableMap.putString("msg", obj.getString("msg"));
1363
+ WritableMap child = Arguments.createMap();
1364
+ child.putMap("data", writableMap);
1365
+ onWebSocketDidOpen(child);
1366
+ } catch (Exception e) {
1367
+ QLog.e(TAG, e.toString());
1368
+ }
1369
+ break;
1370
+ case EventType.EVENT_TYPE_WEBSOCKET_ERROR:
1371
+ try {
1372
+ WritableMap writableMap = Arguments.createMap();
1373
+ writableMap.putString("code", socketEvent.getType());
1374
+ writableMap.putString("message", socketEvent.getData());
1375
+ WritableMap child = Arguments.createMap();
1376
+ child.putMap("data", writableMap);
1377
+ onWebSocketDidError(child);
1378
+ } catch (Exception e) {
1379
+ QLog.e(TAG, e.toString());
1380
+ }
1381
+ break;
1382
+ }
1383
+ } else if (main instanceof SuccessEventContent) {
1384
+ SuccessEventContent successEventContent = (SuccessEventContent) main;
1385
+ try {
1386
+ JSONObject obj = new JSONObject(successEventContent.getCmd_data());
1387
+ WritableMap writableMap = ResponseUtils.getMapForHandlerJSONObject(obj);
1388
+ String cmd = obj.getString("cmd");
1389
+ writableMap.putString("cmd", cmd);
1390
+ onWebSocketDidReceiveMessage(writableMap);
1391
+ } catch (Exception e) {
1392
+ QLog.e(TAG, e.toString());
1393
+ }
1394
+ } else if (main instanceof String) {
1395
+ if ("close_panel".equals(main)) {
1396
+ QLog.i("close device module");
1397
+ // EventBus.getDefault().unregister(this);
1398
+ }
1399
+ } else if (main instanceof QuecIotDataPointsModel) {
1400
+ QuecIotDataPointsModel model = (QuecIotDataPointsModel) main;
1401
+ String receiveChannelId = model.pk + "_" + model.dk;
1402
+ QLog.d(TAG, "receiveChannelId=" + receiveChannelId + ",channelId=" + channelId);
1403
+ if (TextUtils.isEmpty(receiveChannelId) || TextUtils.isEmpty(channelId)) return;
1404
+ if (channelId.equalsIgnoreCase(receiveChannelId) || otherChannelIds.contains(receiveChannelId)) {
1405
+ if (model.action == QuecIotDataPointsModel.QuecIotDataPointAction.QuecIotDataPointActionVerified) {
1406
+ dealWithVerified();
1407
+ }
1408
+ AnalysisChannelDataUtils.analysisChannelData(model, getReactApplicationContext());
1409
+ }
1410
+ } else if (main instanceof ChannelStateEvent) {
1411
+ int state = ((ChannelStateEvent) main).getOnLineState();
1412
+ String channelIdEve = ((ChannelStateEvent) main).getChannelId();
1413
+ if (TextUtils.isEmpty(channelIdEve) || TextUtils.isEmpty(channelId)) return;
1414
+ if (channelIdEve.equals(channelId) || otherChannelIds.contains(channelIdEve)) {
1415
+ QLog.i("设备桥接收到设备列表--发来通道状态更新eventbus");
1416
+ AnalysisChannelDataUtils.updateOnlineState(getReactApplicationContext(), state);
1417
+ }
1418
+ } else if (main instanceof QuecDeviceModelUpdateEvent) {//更新设备信息
1419
+ QuecDeviceModelUpdateEvent event = (QuecDeviceModelUpdateEvent) main;
1420
+ updateDeviceModel(event.getQuecDeviceModel());
1421
+ } else if (main instanceof QuecSelectedDeviceEvent) {
1422
+ String jsonStr = ((QuecSelectedDeviceEvent) main).getJsonDeviceListStr();
1423
+ if (!TextUtils.isEmpty(jsonStr)) {
1424
+ try {
1425
+ WritableArray writableArray = ResponseUtils.getWritableArray(jsonStr);
1426
+ deviceAssociationSelected(writableArray);
1427
+ } catch (JSONException e) {
1428
+ QLog.e(TAG, e.toString());
1429
+ }
1430
+ }
1431
+ }
1432
+ }
1433
+
1434
+ /**
1435
+ * 执行期间判断网络是否异常
1436
+ *
1437
+ * @return TRUE 异常 false 正常
1438
+ */
1439
+ private boolean processNoNetWork(Promise promise) {
1440
+ if (!NetUtils.isNetworkConnected(getReactApplicationContext())) {
1441
+ promise.reject(ErrorCode.ERROR_CODE_NETWORK_ABNORMAL,
1442
+ QuecBaseApp.getInstance().getString(com.quectel.ui.config.R.string.quec_error_code_default));
1443
+ return true;
1444
+ }
1445
+ return false;
1446
+ }
1447
+
1448
+ //通过pk,dk 获取设备详情
1449
+ @ReactMethod
1450
+ @Override
1451
+ public void getDeviceInfoByDeviceKey(String dk, String pk, final Promise promise) {
1452
+ if (processNoNetWork(promise)) {
1453
+ return;
1454
+ }
1455
+ QuecDeviceService.INSTANCE.getDeviceInfoByDeviceKey(dk, pk, result -> {
1456
+ if (result.isSuccess()) {
1457
+ checkDevice(result.getData());
1458
+ }
1459
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1460
+ });
1461
+ }
1462
+
1463
+ //获取设备属性数据列表
1464
+ @ReactMethod
1465
+ @Override
1466
+ public void getPropertyDataListWithParams(ReadableMap map, final Promise promise) {
1467
+ if (processNoNetWork(promise)) {
1468
+ return;
1469
+ }
1470
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1471
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1472
+ String attributeCode = ParamsValueUtils.getString(map, "attributeCode", "");
1473
+ double startTimestamp = ParamsValueUtils.getDouble(map, "startTimestamp", 0);
1474
+ double endTimestamp = ParamsValueUtils.getDouble(map, "endTimestamp", 0);
1475
+ int page = ParamsValueUtils.getInt(map, "pageNumber", -1);
1476
+ int pageSize = ParamsValueUtils.getInt(map, "pageSize", -1);
1477
+
1478
+ QuecDeviceStatisticsService.INSTANCE.getPropertyDataList(pk, dk, (long) startTimestamp, (long) endTimestamp,
1479
+ attributeCode, null, null, page, pageSize, getCallback(promise));
1480
+ }
1481
+
1482
+ //获取设备属性环比统计数据
1483
+ //callback {"data": []}
1484
+ @ReactMethod
1485
+ @Override
1486
+ public void getPropertyStatisticsWithParams(ReadableMap map, final Promise promise) {
1487
+ if (processNoNetWork(promise)) {
1488
+ return;
1489
+ }
1490
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1491
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1492
+ String attributeCode = ParamsValueUtils.getString(map, "attributeCode", "");
1493
+ int countType = ParamsValueUtils.getInt(map, "countType", -1);
1494
+ // int backNum = ParamsValueUtils.getInt(map, "backNum", -1);
1495
+ double currentTimestamp = ParamsValueUtils.getDouble(map, "currentTimestamp", 0);
1496
+ String gatewayDk = ParamsValueUtils.getString(map, "gatewayDk", "");
1497
+ String gatewayPk = ParamsValueUtils.getString(map, "gatewayPk", "");
1498
+ String timeGranularities = ParamsValueUtils.getString(map, "timeGranularities", "");
1499
+ // boolean isCompare = ParamsValueUtils.getBoolean(map,"isCompare",false);
1500
+
1501
+ QuecDeviceStatisticsService.INSTANCE.getPropertyStatisticsPath(pk, dk, (long) currentTimestamp, attributeCode
1502
+ , gatewayDk, gatewayPk, countType, timeGranularities, getCallback(promise));
1503
+ }
1504
+
1505
+ //通过shareCode 获取设备详情
1506
+ @ReactMethod
1507
+ @Override
1508
+ public void getDeviceInfoByShareCode(String shareCode, final Promise promise) {
1509
+ if (processNoNetWork(promise)) {
1510
+ return;
1511
+ }
1512
+ QuecDeviceShareService.INSTANCE.getDeviceInfoByShareCode(shareCode, result -> {
1513
+ if (result.isSuccess()) {
1514
+ checkDevice(result.getData());
1515
+ }
1516
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1517
+ });
1518
+ }
1519
+
1520
+ //根据设备名称查询设备
1521
+ @ReactMethod
1522
+ @Override
1523
+ public void getDeviceListByDeviceName(String deviceName, int pageNumber, int pageSize, final Promise promise) {
1524
+ if (processNoNetWork(promise)) {
1525
+ return;
1526
+ }
1527
+ QuecDeviceListParamsModel model = new QuecDeviceListParamsModel();
1528
+ model.setDeviceName(deviceName);
1529
+ QuecDeviceService.INSTANCE.getDeviceList(model, result -> {
1530
+ if (result.isSuccess()) {
1531
+ checkDeviceList(result.getData().getList());
1532
+ }
1533
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1534
+ });
1535
+ }
1536
+
1537
+ @ReactMethod
1538
+ @Override
1539
+ public void bindDeviceBySerialNumber(String sn, String pk, String deviceName, final Promise promise) {
1540
+ if (processNoNetWork(promise)) {
1541
+ return;
1542
+ }
1543
+ QuecDeviceService.INSTANCE.bindDeviceWithSerialNumber(sn, pk, deviceName, getCallback(promise));
1544
+ }
1545
+
1546
+ @ReactMethod
1547
+ @Override
1548
+ public void bindDeviceByAuthCode(ReadableMap map, final Promise promise) {
1549
+ if (processNoNetWork(promise)) {
1550
+ return;
1551
+ }
1552
+ String authCode = ParamsValueUtils.getString(map, "authCode", "");
1553
+ String pk = ParamsValueUtils.getString(map, "productKey", "");
1554
+ String dk = ParamsValueUtils.getString(map, "deviceKey", "");
1555
+ String deviceName = ParamsValueUtils.getString(map, "deviceName", "");
1556
+ QuecDeviceService.INSTANCE.bindWifiDeviceWithAuthCode(authCode, pk, dk, deviceName, 0, getCallback(promise));
1557
+ }
1558
+
1559
+ @ReactMethod
1560
+ @Override
1561
+ public void bindDeviceByPSWAuthCode(ReadableMap map, final Promise promise) {
1562
+ if (processNoNetWork(promise)) {
1563
+ return;
1564
+ }
1565
+ String authCode = ParamsValueUtils.getString(map, "authCode", "");
1566
+ String pk = ParamsValueUtils.getString(map, "pk", "");
1567
+ String dk = ParamsValueUtils.getString(map, "dk", "");
1568
+ String pwd = ParamsValueUtils.getString(map, "pwd", "");
1569
+ DeviceServiceFactory.getInstance().getService(IDevService.class).bindDeviceByBlueTooth(authCode, pk, dk, pwd,
1570
+ new IHttpCallBack() {
1571
+ @Override
1572
+ public void onSuccess(String result) {
1573
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1574
+ }
1575
+
1576
+ @Override
1577
+ public void onFail(Throwable e) {
1578
+ QLog.e(TAG, e);
1579
+ }
1580
+ });
1581
+ }
1582
+
1583
+ //查询设备升级计划
1584
+ @ReactMethod
1585
+ @Override
1586
+ public void getFetchPlanWithProductKey(String pk, String dk, ReadableMap map, final Promise promise) {
1587
+ if (processNoNetWork(promise)) {
1588
+ return;
1589
+ }
1590
+ DeviceServiceFactory.getInstance().getService(IDevService.class).queryFetchPlan(pk, dk, new IHttpCallBack() {
1591
+ @Override
1592
+ public void onSuccess(String result) {
1593
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1594
+ }
1595
+
1596
+ @Override
1597
+ public void onFail(Throwable e) {
1598
+ QLog.e(TAG, e);
1599
+ }
1600
+ });
1601
+ }
1602
+
1603
+ //上报升级状态
1604
+ @ReactMethod
1605
+ @Override
1606
+ public void reportDeviceUpgradeStatusWithProductKey(ReadableMap map, final Promise promise) {
1607
+ if (processNoNetWork(promise)) {
1608
+ return;
1609
+ }
1610
+ String productKey = ParamsValueUtils.getString(map, "productKey", "");
1611
+ String deviceKey = ParamsValueUtils.getString(map, "deviceKey", "");
1612
+ String componentNo = ParamsValueUtils.getString(map, "componentNo", "");
1613
+ int reportStatus = ParamsValueUtils.getInt(map, "reportStatus", -1);
1614
+ DeviceServiceFactory.getInstance().getService(IDevService.class).reportUpgradeStatus(productKey, deviceKey,
1615
+ componentNo, reportStatus, new IHttpCallBack() {
1616
+ @Override
1617
+ public void onSuccess(String result) {
1618
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1619
+ }
1620
+
1621
+ @Override
1622
+ public void onFail(Throwable e) {
1623
+ QLog.e(TAG, e);
1624
+ }
1625
+ });
1626
+ }
1627
+
1628
+ /**
1629
+ * 设备批量控制
1630
+ * data 遵循tsl格式的json string [{"id":62,"value":99,"type":"INT","name":"温度(temp)"},{"id":63,"value":"true",
1631
+ * "type":"BOOL","name":"开关机状态(powerstate)"}]
1632
+ * deviceList 设备列表 [{"deviceKey":"", "productKey":""}]
1633
+ * type number 类型 1:透传 2:属性 3:服务
1634
+ * dataFormat number 数据类型 1:Hex 2:Text(当type为透传时,需要指定 dataFormat)
1635
+ * cacheTime number 非必传 缓存时间,单位为秒,缓存时间范围 1-7776000 秒,启用缓存时必须设置缓存时间
1636
+ * isCache number 非必传 是否启用缓存 1:启用 2:不启用,默认不启用
1637
+ * isCover number 非必传 是否覆盖之前发送的相同的命令 1:覆盖 2:不覆盖,默认不覆盖,启用缓存时此参数有效
1638
+ */
1639
+ @ReactMethod
1640
+ @Override
1641
+ public void sendDataToDevicesByHttpWithData(ReadableMap map, final Promise promise) {
1642
+ if (processNoNetWork(promise)) {
1643
+ return;
1644
+ }
1645
+ String data = ParamsValueUtils.getString(map, "data", "");
1646
+ ReadableArray deviceList = map.getArray("deviceList");
1647
+ int cacheTime = ParamsValueUtils.getInt(map, "cacheTime", -1);
1648
+ int isCache = ParamsValueUtils.getInt(map, "isCache", -1);
1649
+ int isCover = ParamsValueUtils.getInt(map, "isCover", -1);
1650
+ int dataFormat = ParamsValueUtils.getInt(map, "dataFormat", -1);
1651
+ int type = ParamsValueUtils.getInt(map, "type", -1);
1652
+ List<QuecBatchControlDeviceModel> list = new ArrayList<>();
1653
+ if (deviceList != null && deviceList.size() > 0) {
1654
+ for (int i = 0; i < deviceList.size(); i++) {
1655
+ ReadableMap mapa = deviceList.getMap(i);
1656
+ String productKey = ParamsValueUtils.getString(mapa, "productKey", "");
1657
+ String deviceKey = ParamsValueUtils.getString(mapa, "deviceKey", "");
1658
+ QuecBatchControlDeviceModel adp = new QuecBatchControlDeviceModel(productKey, deviceKey, "", "");
1659
+ list.add(adp);
1660
+ }
1661
+ }
1662
+ QuecDeviceControlService.INSTANCE.sendDataToDevicesByHttp(data, list, type,
1663
+ new QuecBatchControlExtraModel(cacheTime, dataFormat, isCache, isCover, -1), getCallback(promise));
1664
+ }
1665
+
1666
+ /**
1667
+ * 添加云端定时
1668
+ *
1669
+ * @param map 云端定时参数
1670
+ * @param promise 请求回调
1671
+ */
1672
+ @ReactMethod
1673
+ @Override
1674
+ public void addCornJob(ReadableMap map, final Promise promise) {
1675
+ if (processNoNetWork(promise)) {
1676
+ return;
1677
+ }
1678
+ try {
1679
+ JSONObject params = ReactNativeJson.convertMapToJson(map);
1680
+ QuecCornJobModel timing = JsonUtils.fromJsonString(params.toString(), (new TypeToken<QuecCornJobModel>() {
1681
+ }).getType());
1682
+ QuecDeviceService.INSTANCE.addCornJob(timing, result -> {
1683
+ if (result.isSuccess()) {
1684
+ WritableMap resultMap = Arguments.createMap();
1685
+ WritableMap rulerMap = Arguments.createMap();
1686
+ rulerMap.putString("ruleId", result.getData());
1687
+ resultMap.putMap("data", rulerMap);
1688
+ promise.resolve(resultMap);
1689
+ } else {
1690
+ ResponseUtils.handlerError(promise, result.getCode(), result.getMsg(), viewModel);
1691
+ }
1692
+ });
1693
+ } catch (JSONException e) {
1694
+ QLog.e(TAG, "addCornJob error: " + e);
1695
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
1696
+ }
1697
+ }
1698
+
1699
+ /**
1700
+ * 编辑云端定时
1701
+ *
1702
+ * @param map 云端定时参数
1703
+ * @param promise 请求回调
1704
+ */
1705
+ @ReactMethod
1706
+ @Override
1707
+ public void setCronJob(ReadableMap map, final Promise promise) {
1708
+ if (processNoNetWork(promise)) {
1709
+ return;
1710
+ }
1711
+ try {
1712
+ JSONObject params = ReactNativeJson.convertMapToJson(map);
1713
+ QuecCornJobModel timing = JsonUtils.fromJsonString(params.toString(), (new TypeToken<QuecCornJobModel>() {
1714
+ }).getType());
1715
+ QuecDeviceService.INSTANCE.setCronJob(timing, getCallback(promise));
1716
+ } catch (JSONException e) {
1717
+ QLog.e(TAG, "setCronJob error: " + e);
1718
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
1719
+ }
1720
+ }
1721
+
1722
+ /**
1723
+ * 查询设备下定时任务列表
1724
+ *
1725
+ * @param map 云端定时参数
1726
+ * @param promise 请求回调
1727
+ */
1728
+ @ReactMethod
1729
+ @Override
1730
+ public void getCronJobList(ReadableMap map, final Promise promise) {
1731
+ if (processNoNetWork(promise)) {
1732
+ return;
1733
+ }
1734
+ try {
1735
+ JSONObject params = ReactNativeJson.convertMapToJson(map);
1736
+ CloudTimingList timingList = JsonUtils.fromJsonString(params.toString(), (new TypeToken<CloudTimingList>() {
1737
+ }).getType());
1738
+ QuecDeviceService.INSTANCE.getCronJobList(timingList.getDeviceKey(), timingList.getProductKey(),
1739
+ timingList.getType(), timingList.getPage(), timingList.getPageSize(), getCallback(promise));
1740
+ } catch (JSONException e) {
1741
+ QLog.e(TAG, "getCronJobList error: " + e);
1742
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
1743
+ }
1744
+ }
1745
+
1746
+ /**
1747
+ * 查询定时任务详情
1748
+ *
1749
+ * @param ruleId 规则引擎 ID
1750
+ * @param promise 请求回调
1751
+ */
1752
+ @ReactMethod
1753
+ @Override
1754
+ public void getCronJobInfo(String ruleId, final Promise promise) {
1755
+ if (processNoNetWork(promise)) {
1756
+ return;
1757
+ }
1758
+ QuecDeviceService.INSTANCE.getCronJobInfo(ruleId, getCallback(promise));
1759
+ }
1760
+
1761
+ /**
1762
+ * 批量删除定时任务
1763
+ *
1764
+ * @param map 删除云端定时参数
1765
+ * @param promise 请求回调
1766
+ */
1767
+ @ReactMethod
1768
+ @Override
1769
+ public void batchDeleteCronJob(ReadableMap map, final Promise promise) {
1770
+ if (processNoNetWork(promise)) {
1771
+ return;
1772
+ }
1773
+ try {
1774
+ JSONObject params = ReactNativeJson.convertMapToJson(map);
1775
+ QLog.i(TAG, "params: " + params);
1776
+ BatchDeleteCloudTiming deleteCloudTiming = JsonUtils.fromJsonString(params.toString(),
1777
+ (new TypeToken<BatchDeleteCloudTiming>() {
1778
+ }).getType());
1779
+ QLog.i(TAG, "deleteCloudTiming: " + deleteCloudTiming.toString());
1780
+ QuecDeviceService.INSTANCE.batchDeleteCornJob(deleteCloudTiming.getRuleIdList(), getCallback(promise));
1781
+ } catch (JSONException e) {
1782
+ QLog.e(TAG, "batchDeleteCronJob error: " + e);
1783
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e);
1784
+ }
1785
+ }
1786
+
1787
+ /**
1788
+ * 查询产品下设备可以添加的最大定时任务数量
1789
+ *
1790
+ * @param productKey 产品PK
1791
+ * @param promise 请求回调
1792
+ */
1793
+ @ReactMethod
1794
+ @Override
1795
+ public void getProductCornJobLimit(String productKey, final Promise promise) {
1796
+ if (processNoNetWork(promise)) {
1797
+ return;
1798
+ }
1799
+ QuecDeviceService.INSTANCE.getProductCornJobLimit(productKey, getCallback(promise));
1800
+ }
1801
+
1802
+ @ReactMethod
1803
+ @Override
1804
+ public void openWebSocket() {
1805
+ if (!EventBus.getDefault().isRegistered(QuecRNDeviceModule.this)) {
1806
+ EventBus.getDefault().register(QuecRNDeviceModule.this);
1807
+ }
1808
+ WebSocketServiceLocater.getService(IWebSocketService.class).login();
1809
+ }
1810
+
1811
+ @ReactMethod
1812
+ @Override
1813
+ public void closeWebSocket() {
1814
+ if (EventBus.getDefault().isRegistered(QuecRNDeviceModule.this)) {
1815
+ EventBus.getDefault().unregister(QuecRNDeviceModule.this);
1816
+ }
1817
+ WebSocketServiceLocater.getService(IWebSocketService.class).disconnect();
1818
+ }
1819
+
1820
+ @ReactMethod
1821
+ @Override
1822
+ public void getProductTSLWithCacheByProductKey(ReadableMap param, final Promise promise) {
1823
+ String pk = ParamsValueUtils.getString(param, "productKey", "");
1824
+ DeviceServiceFactory.getInstance().getService(IDevService.class).getProductTSLWithCache(pk,
1825
+ new IDeviceTSLCallBack() {
1826
+ @Override
1827
+ public void onSuccess(List<ModelBasic> list, List<TSLEvent> list1, List<TSLService> list2) {
1828
+ // WritableArray modelBasicList = Arguments.createArray();
1829
+ // WritableMap result = Arguments.createMap();
1830
+ // result.putArray("data", modelBasicList);
1831
+ // promise.resolve(result);
1832
+ // String json = QuecGsonUtil.INSTANCE.gsonString(list);
1833
+ List<ModelBasic<?>> covertList = new ArrayList<>();
1834
+ for (ModelBasic data : list) {
1835
+ covertList.add(data);
1836
+ }
1837
+ WritableArray array = DataConvertUtils.getRNArrayByModelBasicList(covertList);
1838
+ WritableMap result = Arguments.createMap();
1839
+ result.putArray("data", array);
1840
+ promise.resolve(result);
1841
+ }
1842
+
1843
+ @Override
1844
+ public void onFail(Throwable throwable) {
1845
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, throwable);
1846
+ }
1847
+ });
1848
+ }
1849
+
1850
+ @Override
1851
+ public void onDeviceConnectingState(ReadableMap object) {
1852
+ waitInit(result -> {
1853
+ ReactApplicationContext context = getReactApplicationContext();
1854
+ if (context != null && context.hasActiveCatalystInstance()) {
1855
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("onDeviceConnectingState", object);
1856
+ }
1857
+ });
1858
+ }
1859
+
1860
+ @Override
1861
+ public void onDeviceOnlineState(ReadableMap object) {
1862
+ waitInit(result -> {
1863
+ QLog.i(TAG,
1864
+ "[" + Thread.currentThread().getName() + "] - send online state: " + object.getMap(Constants.DEVICE_PANEL_DEVICE_MODEL).getInt("onlineStatus"));
1865
+ ReactApplicationContext context = getReactApplicationContext();
1866
+ if (context != null && context.hasActiveCatalystInstance()) {
1867
+ context.getJSModule(RCTDeviceEventEmitter.class).emit("onDeviceOnlineState", object);
1868
+ }
1869
+ });
1870
+ }
1871
+
1872
+ @Override
1873
+ public void onDeviceDpsUpdate(ReadableMap object) {
1874
+ }
1875
+
1876
+ @Override
1877
+ public void onDeviceInfoUpdate(ReadableMap object) {
1878
+ }
1879
+
1880
+ //刷新首页列表信息
1881
+ private void updateHomeList() {
1882
+ //通知首页进行数据刷新
1883
+ EventBus.getDefault().post(new RefreshDeviceListEvent());
1884
+ }
1885
+
1886
+ //刷新首页列表信息
1887
+ private void unbindDeviceAndUpDateHomeList(String channelId) {
1888
+ //通知首页解绑设备并进行数据刷新
1889
+ EventBus.getDefault().post(new RefreshUnbindDeviceEvent(channelId));
1890
+ }
1891
+
1892
+ @Override
1893
+ public void invalidate() {
1894
+ super.invalidate();
1895
+ QLog.i("QuecRNDeviceModule invalidate");
1896
+ if (EventBus.getDefault().isRegistered(QuecRNDeviceModule.this)) {
1897
+ EventBus.getDefault().unregister(QuecRNDeviceModule.this);
1898
+ }
1899
+ deviceClient.removeListener(listener);
1900
+ QuecDevicePanelServiceManager.getInstance().removeDeviceInfoEventCallback(deviceEventCallback);
1901
+ }
1902
+
1903
+ @ReactMethod
1904
+ @Override
1905
+ public void listDeviceEvent(ReadableMap map, final Promise promise) {
1906
+ if (processNoNetWork(promise)) {
1907
+ return;
1908
+ }
1909
+
1910
+ ReadableArray codeArray = map.getArray("codeList");
1911
+ String productKey = ParamsValueUtils.getString(map, "productKey", "");
1912
+ String deviceKey = ParamsValueUtils.getString(map, "deviceKey", "");
1913
+ long startTime = Long.parseLong(ParamsValueUtils.getString(map, "startTime", "0"));
1914
+ long endTime = Long.parseLong(ParamsValueUtils.getString(map, "endTime", "0"));
1915
+ int page = ParamsValueUtils.getInt(map, "pageNumber", 1);
1916
+ int pageSize = ParamsValueUtils.getInt(map, "pageSize", 10);
1917
+ List<String> codeList = new ArrayList<>();
1918
+ if (codeArray != null && codeArray.size() > 0) {
1919
+ for (int i = 0; i < codeArray.size(); i++) {
1920
+ String code = codeArray.getString(i);
1921
+ codeList.add(code);
1922
+ }
1923
+ }
1924
+
1925
+ DeviceServiceFactory.getInstance().getService(IDevService.class).listDeviceEvent(codeList, productKey,
1926
+ deviceKey, startTime, endTime, page, pageSize, new IHttpCallBack() {
1927
+ @Override
1928
+ public void onSuccess(String result) {
1929
+ ResponseUtils.handlerResponse(promise, result, viewModel);
1930
+ }
1931
+
1932
+ @Override
1933
+ public void onFail(Throwable e) {
1934
+ QLog.e(TAG, e.toString());
1935
+ }
1936
+ });
1937
+ }
1938
+
1939
+ private String getChannelId(String pk, String dk) {
1940
+ return pk + "_" + dk;
1941
+ }
1942
+
1943
+ /**
1944
+ * 设置离线提醒开关
1945
+ *
1946
+ * @param enableOfflineReminder 开关
1947
+ * @param productKey product key
1948
+ * @param deviceKey device key
1949
+ * @param promise 返回值
1950
+ */
1951
+ @ReactMethod
1952
+ @Override
1953
+ public void setOfflineReminder(int enableOfflineReminder, String productKey, String deviceKey, Promise promise) {
1954
+ QuecDeviceService.INSTANCE.setOfflineReminder(productKey, deviceKey, enableOfflineReminder,
1955
+ getCallback(promise));
1956
+ }
1957
+
1958
+ /**
1959
+ * 离线提醒开关查询
1960
+ *
1961
+ * @param productKey product key
1962
+ * @param deviceKey device key
1963
+ * @param promise 返回值
1964
+ */
1965
+ @ReactMethod
1966
+ @Override
1967
+ public void getOfflineReminderInfo(String productKey, String deviceKey, Promise promise) {
1968
+ QuecDeviceService.INSTANCE.getOfflineReminder(productKey, deviceKey, getCallback(promise));
1969
+ }
1970
+
1971
+ @ReactMethod
1972
+ @Override
1973
+ public void checkDeviceUpdatePlan(ReadableMap device, Promise promise) {
1974
+ String productKey = device.getString("productKey");
1975
+ String deviceKey = device.getString("deviceKey");
1976
+ if (productKey == null || deviceKey == null) {
1977
+ promise.reject("-9998", "productKey or deviceKey is null");
1978
+ return;
1979
+ }
1980
+ QuecOtaManager.INSTANCE.checkVersion(productKey, deviceKey, result -> {
1981
+ if (result.isSuccess()) {
1982
+ if (result.getData() != null) {
1983
+ WritableMap writableMap = Arguments.createMap();
1984
+ writableMap.putBoolean("data", true);
1985
+ promise.resolve(writableMap);
1986
+ } else {
1987
+ promise.reject("-9999", "There is no upgrade plan");
1988
+ }
1989
+ } else {
1990
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, new QuecError(result.getCode(), result.getMsg(),
1991
+ result.getSubCode()));
1992
+ }
1993
+ });
1994
+ }
1995
+
1996
+ @ReactMethod
1997
+ @Override
1998
+ public void openDeviceOTAPage(String productKey, String deviceKey, Promise promise) {
1999
+ if (processNoNetWork(promise)) {
2000
+ QuecToastUtil.showS(com.quectel.ui.config.R.string.quec_error_code_default);
2001
+ return;
2002
+ }
2003
+ QuecOtaManager.INSTANCE.checkVersion(productKey, deviceKey, result -> {
2004
+ if (result.isSuccess()) {
2005
+ if (result.getData() != null) {
2006
+ QuecOtaInfo model = result.getData();
2007
+ // 2跳转升级计划页面
2008
+ int deviceStatus = model.getDeviceStatus();
2009
+ long planId = model.getPlanId();
2010
+ Activity context = getCurrentActivity();
2011
+ if (context != null && !context.isFinishing()) {
2012
+ OtaUpgradeServiceManager.INSTANCE.jumpSingleDevice(getCurrentActivity(), deviceKey,
2013
+ productKey, deviceStatus, true, planId);
2014
+ }
2015
+ } else {
2016
+ // QuecToastUtil.showS(R.string.quec_error_code_5557);
2017
+ Activity context = getCurrentActivity();
2018
+ if (context != null && !context.isFinishing()) {
2019
+ OtaUpgradeServiceManager.INSTANCE.jumpSingleDeviceVersion(context, deviceKey, productKey);
2020
+ }
2021
+ }
2022
+ } else {
2023
+ checkResult(result);
2024
+ QuecToastUtil.showS(result.getMsg());
2025
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, new QuecError(result.getCode(), result.getMsg(),
2026
+ result.getSubCode()));
2027
+ }
2028
+ });
2029
+ }
2030
+
2031
+ @ReactMethod
2032
+ @Override
2033
+ public void getTimeDifferenceWithGMT(Promise promise) {
2034
+ String timeZoneName = QuecTimeZoneUtil.getCurrentTimeZone(); //获取名字,如“GMT+08:00”
2035
+ WritableMap writableMap = Arguments.createMap();
2036
+ writableMap.putString("data", timeZoneName);
2037
+ promise.resolve(writableMap);
2038
+
2039
+ }
2040
+
2041
+ @ReactMethod
2042
+ @Override
2043
+ public void getDeviceTimeZone(String pk, String dk, Promise promise) {
2044
+ QuecDeviceService.INSTANCE.getDeviceTimeZone(pk, dk, getCallback(promise));
2045
+ }
2046
+
2047
+ @ReactMethod
2048
+ @Override
2049
+ public void setDeviceTimeZone(String pk, String dk, String timezone, Promise promise) {
2050
+ String timeZoneName = QuecTimeZoneUtil.getCurrentTimeZone(); //获取名字,如“GMT+08:00”
2051
+ String timeZoneId = QuecTimeZoneUtil.getCurrentTimeZoneId();
2052
+ QuecDeviceService.INSTANCE.setDeviceTimeZone(pk, dk, timeZoneName, timeZoneId, getCallback(promise));
2053
+ }
2054
+
2055
+ @ReactMethod
2056
+ @Override
2057
+ public void getDeviceStateInfo(String productKey, String deviceKey, Promise promise) {
2058
+ deviceClient.readDeviceStatusWithResult(result -> {
2059
+ if (result.isSuccess()) {
2060
+ QLog.i("设备返回的设备状态信息=" + QuecGsonUtil.INSTANCE.gsonString(result.getData()));
2061
+ try {
2062
+ JSONObject obj = new JSONObject(QuecGsonUtil.INSTANCE.gsonString(result.getData()));
2063
+ WritableMap writableMap = ReactNativeJson.convertJsonToMap(obj);
2064
+ onDeviceStatusUpdate(writableMap);
2065
+ } catch (JSONException e) {
2066
+ QLog.e(TAG, e);
2067
+ }
2068
+ } else {
2069
+ promise.reject("-9999", "获取设备状态失败");
2070
+ }
2071
+ });
2072
+ }
2073
+
2074
+
2075
+ @ReactMethod
2076
+ @Override
2077
+ public void jumpDeviceWiFiListPage(String productKey, String deviceKey, String oldSsid, String signal_strength,
2078
+ boolean supportOnlineWiFiScan, Promise promise) {
2079
+ Activity context = getCurrentActivity();
2080
+ QuecWifiSwitchUIServiceManager.getInstance().jumpToWifiList(context, productKey, deviceKey, oldSsid,
2081
+ signal_strength, supportOnlineWiFiScan);
2082
+ IotChannelController.getInstance().setWifiChangeListener((channelId, bean) -> {
2083
+ try {
2084
+ JSONObject obj = new JSONObject(QuecGsonUtil.INSTANCE.gsonString(bean));
2085
+ WritableMap writableMap = ReactNativeJson.convertJsonToMap(obj);
2086
+ onDeviceStatusUpdate(writableMap);
2087
+ } catch (JSONException e) {
2088
+ QLog.e(TAG, e);
2089
+ }
2090
+ });
2091
+ // QuecToastUtil.showS("跳转设备wifi列表");
2092
+ }
2093
+
2094
+
2095
+ @ReactMethod
2096
+ @Override
2097
+ public void getProductDescription(String productKey, Promise promise) {
2098
+ if (processNoNetWork(promise)) {
2099
+ return;
2100
+ }
2101
+ QuecDeviceService.INSTANCE.getProductDescription(productKey, result -> {
2102
+ if (result.isSuccess()) {
2103
+ WritableMap writableMap = Arguments.createMap();
2104
+ WritableMap dataMap = Arguments.createMap();
2105
+ dataMap.putString("url", result.getData());
2106
+ writableMap.putMap("data", dataMap);
2107
+
2108
+ promise.resolve(writableMap);
2109
+ } else {
2110
+ ResponseUtils.handlerResponse(promise, result, viewModel);
2111
+ }
2112
+ });
2113
+ }
2114
+
2115
+ @ReactMethod
2116
+ @Override
2117
+ public void getFamilyDeviceList(int pageNumber, int pageSize, Promise promise) {
2118
+ String fid = MmkvManager.getInstance().get("familyId", "");
2119
+ QuecSmartHomeService.INSTANCE.getFamilyDeviceList(new QuecFamilyDeviceListParamsModel(fid, true, "",
2120
+ pageNumber, pageSize, false, false, null, null), result -> {
2121
+ if (result.isSuccess()) {
2122
+ checkDeviceList(result.getData().getList());
2123
+ }
2124
+ ResponseUtils.handlerResponse(promise, result, viewModel);
2125
+ });
2126
+ }
2127
+
2128
+ @Override
2129
+ @ReactMethod
2130
+ public void timeZoneSync(String productKey, String deviceKey, Promise promise) {
2131
+ if (deviceClient.getConnectState() > 0) {
2132
+ deviceClient.timeZoneSync();
2133
+ QLog.i(TAG, "时间同步成功");
2134
+ WritableMap writableMap = Arguments.createMap();
2135
+ promise.resolve(writableMap);
2136
+ } else {
2137
+ QLog.e("时间同步失败");
2138
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, "时间同步失败:");
2139
+ }
2140
+ }
2141
+
2142
+ @Override
2143
+ @ReactMethod
2144
+ public void unbindlingPureBtDevice(String productKey, String deviceKey, boolean isInit, String random,
2145
+ String pureBtResetCredentials, Promise promise) {
2146
+ DeviceModel deviceModel = new DeviceModel();
2147
+ deviceModel.setProductKey(productKey);
2148
+ deviceModel.setDeviceKey(deviceKey);
2149
+ QuecDeviceListServiceManager.getInstance().unBindDevice(Collections.singletonList(deviceModel), isInit,
2150
+ result -> {
2151
+ if (result.isSuccess()) {
2152
+ QLog.i(TAG, "解绑设备成功");
2153
+ WritableMap writableMap = Arguments.createMap();
2154
+ promise.resolve(writableMap);
2155
+ } else {
2156
+ promise.reject(ErrorCode.ERROR_CODE_REQUEST_FAIL, result.getMsg());
2157
+ QLog.e(TAG, "解绑设备失败: " + result.getMsg());
2158
+ }
2159
+ });
2160
+ }
2161
+
2162
+ @ReactMethod
2163
+ @Override
2164
+ public void getTsl(String productKey, Promise promise) {
2165
+ IDevService devService = DeviceServiceFactory.getInstance().getService(IDevService.class);
2166
+ devService.queryProductTSLWithCache(QuecBaseApp.getInstance(), productKey, new IHttpCallBack() {
2167
+ @Override
2168
+ public void onSuccess(String result) {
2169
+ try {
2170
+ JSONObject jsonObject = new JSONObject(result);
2171
+ int code = jsonObject.optInt("code");
2172
+ String msg = jsonObject.optString("msg");
2173
+ if (code != 200) {
2174
+ QLog.e("获取物模型失败-json解析异常");
2175
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, msg);
2176
+ return;
2177
+ }
2178
+
2179
+ WritableMap writableMap = Arguments.createMap();
2180
+ JSONObject obj = jsonObject.optJSONObject("data");
2181
+ if (obj == null || obj.length() == 0) {
2182
+ writableMap.putArray("data", Arguments.createArray());
2183
+ QLog.e("获取物模型成功--空数据 data");
2184
+ promise.resolve(writableMap);
2185
+ return;
2186
+ }
2187
+
2188
+ CacheTSLModel.saveModelsToMap(productKey);
2189
+ JSONArray jsonArrayProperties = obj.optJSONArray("properties");
2190
+ List<ModelBasic> list = ObjectModelParse.buildModelListContent(jsonArrayProperties);
2191
+
2192
+ try {
2193
+ JSONArray jsonArray = new JSONArray(QuecGsonUtil.INSTANCE.gsonString(list));
2194
+ WritableArray writableArray = ReactNativeJson.convertJsonToArray(jsonArray);
2195
+ writableMap.putArray("data", writableArray);
2196
+ QLog.e("获取物模型成功--空数据 data: " + writableMap);
2197
+ promise.resolve(writableMap);
2198
+ } catch (JSONException e) {
2199
+ QLog.e("获取物模型失败-json解析异常");
2200
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e.getLocalizedMessage());
2201
+ QLog.e(TAG, e);
2202
+ }
2203
+
2204
+
2205
+ } catch (Exception e) {
2206
+ QLog.e("获取物模型失败-json解析异常");
2207
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e.getLocalizedMessage());
2208
+ QLog.e(TAG, e);
2209
+ }
2210
+
2211
+ }
2212
+
2213
+ @Override
2214
+ public void onFail(Throwable e) {
2215
+ QLog.e("获取物模型失败-接口异常");
2216
+ promise.reject(ErrorCode.ERROR_CODE_JSON_EXCEPTION, e.getLocalizedMessage());
2217
+ QLog.e(TAG, e);
2218
+ }
2219
+ });
2220
+ }
2221
+
2222
+ @ReactMethod
2223
+ @Override
2224
+ public void startVerifyDevice(String productKey, String deviceKey, Promise promise) {
2225
+ Activity activity = getCurrentActivity();
2226
+ if (activity != null) {
2227
+ SmartConfigServiceManager.getInstance().verifySingleDeviceStart(activity, productKey, deviceKey, result -> {
2228
+ if (result.isSuccess()) {
2229
+ promise.resolve(0);
2230
+ } else {
2231
+ promise.reject(result.getCode() + "", result.getMsg());
2232
+ }
2233
+ });
2234
+ } else {
2235
+ QLog.i(TAG, "startVerifyDevice fail, activity is null");
2236
+ }
2237
+ }
2238
+
2239
+ @ReactMethod
2240
+ @Override
2241
+ public void startNetConfigDevice(String productKey, String deviceKey, Promise promise) {
2242
+ Activity activity = getCurrentActivity();
2243
+ if (activity != null) {
2244
+ SmartConfigServiceManager.getInstance().netConfigSingleDeviceStart(activity, productKey, deviceKey,
2245
+ result -> {
2246
+ if (result.isSuccess()) {
2247
+ promise.resolve(0);
2248
+ } else {
2249
+ promise.reject(result.getCode() + "", result.getMsg());
2250
+ }
2251
+ });
2252
+ } else {
2253
+ QLog.i(TAG, "startVerifyDevice fail, activity is null");
2254
+ }
2255
+ }
2256
+
2257
+ @ReactMethod
2258
+ @Override
2259
+ public void getSharePermList(ReadableArray shareCodeList, Promise promise) {
2260
+ ArrayList<String> list = new ArrayList<>();
2261
+ for (int i = 0; i < shareCodeList.size(); i++) {
2262
+ list.add(shareCodeList.getString(i));
2263
+ }
2264
+ QuecDeviceShareService.INSTANCE.getSharePermList(list, getCallback(promise));
2265
+ }
2266
+
2267
+ @ReactMethod
2268
+ @Override
2269
+ public void uploadDeviceHistoricalData(String productKey, String deviceKey, Promise promise) {
2270
+ QuecDeviceDataUploadManager.INSTANCE.uploadDeviceHistoricalData(productKey, deviceKey, getSimpleCallback(promise));
2271
+ }
2272
+
2273
+ @ReactMethod
2274
+ @Override
2275
+ public void getVoiceSupport(String productKey, String uid, String account, Promise promise) {
2276
+ final boolean isSupportAlexa = QuecOemAppConfig.INSTANCE.getBusiness().isSupportAlexa();
2277
+ final boolean isSupportGoogleAssistant = QuecOemAppConfig.INSTANCE.getBusiness().isSupportGoogleAssistant();
2278
+ if (!isSupportAlexa && !isSupportGoogleAssistant) {
2279
+ WritableMap map = Arguments.createMap();
2280
+ map.putBoolean("supportAlexa", false);
2281
+ map.putBoolean("supportAssistant", false);
2282
+ promise.resolve(map);
2283
+ return;
2284
+ }
2285
+ QuecDeviceService.INSTANCE.getVoiceSupport(productKey, uid, account, new QuecCallback<QuecVoiceSupport>() {
2286
+ @Override
2287
+ public void onResult(@NonNull QuecResult<QuecVoiceSupport> result) {
2288
+ if (!result.isSuccess()) {
2289
+ promise.reject(String.valueOf(result.getCode()), result.getMsg());
2290
+ return;
2291
+ }
2292
+
2293
+ QuecVoiceSupport data = result.getData();
2294
+ final boolean productSupportAlexa = data != null && data.getProductSupportAlexa();
2295
+ final boolean productSupportAssistant = data != null && data.getProductSupportAssistant();
2296
+
2297
+ WritableMap map = Arguments.createMap();
2298
+ map.putBoolean("supportAlexa", productSupportAlexa && isSupportAlexa);
2299
+ map.putBoolean("supportAssistant", productSupportAssistant && isSupportGoogleAssistant);
2300
+ promise.resolve(map);
2301
+ }
2302
+ });
2303
+ }
2304
+
2305
+ private QuecIotDataSendMode getDefaultDataSendMode() {
2306
+ return QuecIotDataSendMode.QuecIotDataSendModeAuto;
2307
+ }
2308
+
2309
+ private QuecIotDataSendMode getDataSendMode(int mode) {
2310
+ QuecIotDataSendMode sendMode;
2311
+ switch (mode) {
2312
+ case 1:
2313
+ sendMode = QuecIotDataSendMode.QuecIotDataSendModeWS;
2314
+ break;
2315
+ case 2:
2316
+ sendMode = QuecIotDataSendMode.QuecIotDataSendModeWifi;
2317
+ break;
2318
+ case 3:
2319
+ sendMode = QuecIotDataSendMode.QuecIotDataSendModeBLE;
2320
+ break;
2321
+ default:
2322
+ sendMode = QuecIotDataSendMode.QuecIotDataSendModeAuto;
2323
+ break;
2324
+ }
2325
+
2326
+ return sendMode;
2327
+ }
2328
+
2329
+ private void checkResult(QuecResult<?> result) {
2330
+ if (result == null) {
2331
+ return;
2332
+ }
2333
+ if (TextUtils.isEmpty(result.getMsg()) || result.getMsg().contains("Unable to resolve host")) {
2334
+ result.setMsg(QuecBaseApp.getInstance().getString(com.quectel.ui.config.R.string.quec_error_code_default));
2335
+ }
2336
+ }
2337
+
2338
+ private Throwable checkError(Throwable throwable) {
2339
+ if (TextUtils.isEmpty(throwable.getMessage()) || throwable.getMessage().contains("Unable to resolve host")) {
2340
+ return new Error(QuecBaseApp.getInstance().getString(com.quectel.ui.config.R.string.quec_error_code_default));
2341
+ }
2342
+ return throwable;
2343
+ }
2344
+
2345
+ private QuecSimpleCallBack getSimpleCallback(Promise promise) {
2346
+ return result -> {
2347
+ if (result.isSuccess()) {
2348
+ promise.resolve(Arguments.createMap());
2349
+ } else {
2350
+ promise.reject(result.getCode() + "", result.getMsg());
2351
+ }
2352
+ };
2353
+ }
2354
+
2355
+ private <T> QuecCallback<T> getCallback(Promise promise) {
2356
+ return result -> ResponseUtils.handlerResponse(promise, result, viewModel);
2357
+ }
2358
+
2359
+ private void checkDeviceList(List<QuecDeviceModel> list) {
2360
+ QLog.i(TAG, "checkDeviceList");
2361
+ if (deviceModel != null && list != null) {
2362
+ for (QuecDeviceModel model : list) {
2363
+ checkDevice(model);
2364
+ }
2365
+ }
2366
+ }
2367
+
2368
+ private void checkDevice(QuecDeviceModel model) {
2369
+ if (model == null) {
2370
+ return;
2371
+ }
2372
+ QuecDeviceClientApi client = QuecDeviceClient.Companion.initWithId(model.getChannelId());
2373
+ if (client != null) {
2374
+ client.updateDeviceInfo(model);
2375
+ }
2376
+
2377
+ if (deviceModel != null && deviceModel.getChannelId().equals(model.getChannelId())) {
2378
+ QLog.i(TAG, "update current deviceModel");
2379
+ deviceModel = model;
2380
+ //更新当前设备的缓存
2381
+ String deviceStr = QuecGsonUtil.INSTANCE.gsonString(model);
2382
+ MmkvManager.getInstance().put(Constants.QUEC_DEVICE_MODEL, deviceStr);
2383
+ QuecDevicePanelServiceManager.getInstance().setCurrentDeviceInfo(deviceStr);
2384
+ }
2385
+ }
2386
+
2387
+ private void waitInit(QuecSimpleCallBack callBack) {
2388
+ if (latch.getCount() <= 0) {
2389
+ QuecThreadUtil.RunMainThread(() -> callBack.onResult(new QuecResult<>(true, 0)));
2390
+ } else {
2391
+ //需等待
2392
+ QuecThreadUtil.RunSubThread(() -> {
2393
+ try {
2394
+ latch.await(); // 等待初始化完成
2395
+ QuecThreadUtil.RunMainThread(() -> callBack.onResult(new QuecResult<>(true, 0)));
2396
+ } catch (Exception e) {
2397
+ QLog.e(TAG, "waitInit error: " + e);
2398
+ }
2399
+ });
2400
+ }
2401
+ }
2402
+
2403
+ private void dealWithVerified() {
2404
+ QLog.i(TAG, "dealWithVerified");
2405
+ deviceModel = deviceClient.getModel();
2406
+
2407
+ //更新设备持久化信息
2408
+ String deviceInfoKey = "quecDeviceModel";
2409
+ String json = MmkvManager.getInstance().get(deviceInfoKey, "");
2410
+ if (!TextUtils.isEmpty(json)) {
2411
+ try {
2412
+ Gson gson = new Gson();
2413
+ QuecDeviceModel quecDeviceModel = gson.fromJson(json, QuecDeviceModel.class);
2414
+ if (channelId.equals(quecDeviceModel.getChannelId())) {
2415
+ QLog.i(TAG, "update quecDeviceModel");
2416
+ MmkvManager.getInstance().put(deviceInfoKey, gson.toJson(deviceClient.getModel()));
2417
+ }
2418
+ } catch (Exception e) {
2419
+ QLog.e(TAG, e);
2420
+ }
2421
+ }
2422
+ }
2423
+ }