@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,1524 @@
1
+ //
2
+ // QuecRNDeviceModule+Impl.m
3
+ //
4
+ // Auto-Created on 2022/09/07.
5
+ // Copyright © 2022年 quectel. All rights reserved.
6
+ //
7
+
8
+ #import "QuecRNDeviceModule+Impl.h"
9
+ #import "QuecRNDeviceModule+Ext.h"
10
+ #import <React/RCTBridge+Private.h>
11
+ #import <QuecOemConfig/QuecOemConfig.h>
12
+ #import <QuecDeviceKit/QuecDeviceKit.h>
13
+ #import <YYModel/YYModel.h>
14
+ #import <QuecUIKit/QuecUIKit.h>
15
+ #import <QuecFoundationKit/QuecFoundationKit.h>
16
+ #import <QuecLogKit/QuecLogKit.h>
17
+ #import <QuecBleChannelKit/QuecBleChannelKit.h>
18
+ #import <QuecIotChannelKit/QuecIotChannelKit.h>
19
+ #import <QuecWebSocketChannelKit/QuecWebSocketChannelKit.h>
20
+ #import <QuectelModuleService/QuectelModuleService.h>
21
+ #import <QuecModuleManager/QuecModuleManager.h>
22
+ #import <QuecConnectivityKit/QuecConnectivityKit.h>
23
+ #import <QuecOTAUpgradeKit/QuecOTAUpgradeKit.h>
24
+
25
+ @implementation QuecRNDeviceModule (Impl)
26
+
27
+ - (dispatch_queue_t)methodQueue {
28
+ return dispatch_get_main_queue();
29
+ }
30
+
31
+ - (void)panelContextDidLoad {
32
+ QuecRCTBridge *quecRCTBridge = (QuecRCTBridge*)self.bridge.parentBridge;
33
+ self.deviceModel = quecRCTBridge.quec_panelContext.deviceModel;
34
+ self.device = [QuecDeviceClient deviceWithId:self.deviceModel.deviceId];
35
+ [self.device setDelegate:self];
36
+ self.subDeviecDict = [QuecThreadSafeMutableDictionary dictionary];
37
+ [self.subDeviecDict quec_safeSetObject:self.device forKey:self.device.deviceId];
38
+ if (self.device) {
39
+ if (self.device.model.onlineChannelState == 0) {
40
+ [self.device connectWithMode:QuecIotChannelModeAuto];
41
+ }
42
+ }
43
+ }
44
+
45
+ + (BOOL)requiresMainQueueSetup {
46
+ return true;
47
+ }
48
+ //
49
+ - (void)invalidate {
50
+ [super invalidate];
51
+ [self clear_subscribe];
52
+ }
53
+
54
+ - (void)startObserving {
55
+ self.hasListeners = YES;
56
+ // Set up any upstream listeners or background tasks as necessary
57
+ }
58
+
59
+ // Will be called when this module's last listener is removed, or on dealloc.
60
+ - (void)stopObserving {
61
+ self.hasListeners = NO;
62
+ // Remove upstream listeners, stop unnecessary background tasks
63
+ }
64
+
65
+ - (instancetype)init {
66
+ self = [super init];
67
+ if (self) {
68
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
69
+ [center addObserver:self selector:@selector(quecWebSocketDidOpen:) name:@"QuecWebSocketDidLoginNotification" object:nil];
70
+ [center addObserver:self selector:@selector(quecWebSocketDidReceiveMessageWithDataModel:) name:@"QuecWebSocketReceiveMessageNotification" object:nil];
71
+ [center addObserver:self selector:@selector(quecWebSocketDidCloseWithCode:) name:@"QuecWebSocketDidCloseNotification" object:nil];
72
+ [center addObserver:self selector:@selector(quecWebSocketDidFailWithError:) name:@"QuecWebSocketDidFailNotification" object:nil];
73
+ [center addObserver:self selector:@selector(quecDeviceConnectDidSelected:) name:@"QuecDeviceConnectDidSelected" object:nil];
74
+ [center addObserver:self selector:@selector(quecDeviceStatusUpdate:) name:@"QuecWiFiSwitchSuccess" object:nil];
75
+ }
76
+ return self;
77
+ }
78
+
79
+ - (void)quecDeviceStatusUpdate:(NSNotification *)notification {
80
+ if (!self.hasListeners) {
81
+ return;
82
+ }
83
+ if ([self.subDeviecDict.allKeys containsObject:self.device.deviceId]) {
84
+ [self sendEvent_onDeviceStatusUpdate:[notification.object yy_modelToJSONObject]];
85
+ }
86
+ }
87
+
88
+ - (void)quecWebSocketDidOpen:(NSNotification *)notification {
89
+ if (!self.hasListeners) {
90
+ return;
91
+ }
92
+ [self sendEvent_onWebSocketDidOpen:nil];
93
+ }
94
+
95
+ - (void)quecWebSocketDidReceiveMessageWithDataModel:(NSNotification *)notification {
96
+ if (!self.hasListeners) {
97
+ return;
98
+ }
99
+ NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithDictionary:[notification.object yy_modelToJSONObject]];
100
+ if ([mDic[@"data"] isKindOfClass:NSString.class]) {
101
+ NSDictionary *data = [NSJSONSerialization JSONObjectWithData:[mDic[@"data"] dataUsingEncoding:NSUTF8StringEncoding]
102
+ options:NSJSONReadingMutableContainers
103
+ error:nil];
104
+ mDic[@"data"] = data;
105
+ }
106
+
107
+ if ([self isENDUSERUSERBINDMessage:mDic]) {
108
+ if (self.isUnbindingDevice) {
109
+ return;
110
+ }
111
+ QuecRNContext *rnContext = [QuecRNContext currentRNContext];
112
+ [rnContext.contextForViewController.view makeToast:@"quec_device_invalid_tip".quec_localized duration:2.0 position:QuecToastPositionCenter];
113
+
114
+ quec_delay_on_main(1, ^{
115
+ [quec_TopViewController() quec_goBackToFirstPage:true];
116
+ });
117
+ return;
118
+ }
119
+ [self sendEvent_onWebSocketDidReceiveMessage:[mDic copy]];
120
+ }
121
+
122
+ - (BOOL)isENDUSERUSERBINDMessage:(NSDictionary *)data {
123
+ if ([data[@"data"] isKindOfClass:NSDictionary.class]) {
124
+ if ([data[@"data"][@"type"] isKindOfClass:NSString.class] && [(NSString *)data[@"data"][@"type"] isEqualToString:@"ENDUSER"]) {
125
+ if ([data[@"data"][@"subtype"] isKindOfClass:NSString.class] && [(NSString *)data[@"data"][@"subtype"] isEqualToString:@"USER-BIND"]) {
126
+ QuecPanelContext *panelContext = [QuecPanelContext currentPanelContext];
127
+ if ([panelContext.deviceModel.deviceKey isEqualToString:data[@"data"][@"deviceKey"]] && [panelContext.deviceModel.productKey isEqualToString:data[@"data"][@"productKey"]]) {
128
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUnbindDeviceSuccessed" object:panelContext.deviceModel userInfo:nil];
129
+ return true; }
130
+ }
131
+ }
132
+ }
133
+ return false;
134
+ }
135
+
136
+ - (void)quecWebSocketDidCloseWithCode:(NSNotification *)notification {
137
+ if (!self.hasListeners) {
138
+ return;
139
+ }
140
+ if ([notification.object isKindOfClass:NSDictionary.class]) {
141
+ NSDictionary *dic = (NSDictionary*)notification.object;
142
+ NSDictionary *body = @{@"code":dic[@"code"]?:@0, @"message":dic[@"reason"]?:@"unknown"};
143
+ [self sendEvent_onWebSocketDidError:body];
144
+ }
145
+ }
146
+
147
+ - (void)quecWebSocketDidFailWithError:(NSNotification *)notification {
148
+ if (!self.hasListeners) {
149
+ return;
150
+ }
151
+ if ([notification.object isKindOfClass:NSError.class]) {
152
+ NSError *error = (NSError*)notification.object;
153
+ NSDictionary *body = @{@"code":[NSString stringWithFormat:@"%ld", error.code], @"message":error.localizedDescription};
154
+ [self sendEvent_onWebSocketDidError:body];
155
+ }
156
+ }
157
+
158
+ - (void)impl_isWebSocketLoginCallback:(RCTResponseSenderBlock)isLoginCallback {
159
+ !isLoginCallback ?: isLoginCallback(@[@([QuecWebSocketManager sharedInstance].webSocketDidOpen)]);
160
+ }
161
+
162
+
163
+ - (void)impl_subscribeDevicesWithList:(NSArray*)list {
164
+ if (list && list.count) {
165
+ QuecWebSocketDataModel *dataModel = [[QuecWebSocketDataModel alloc] init];
166
+ dataModel.cmd = QuecWebSocketCmdTypeSubscribe;
167
+ NSMutableArray *deviceList = @[].mutableCopy;
168
+ for (int i = 0; i < list.count; i ++) {
169
+ NSMutableDictionary *data = @{}.mutableCopy;
170
+ NSDictionary *dataDict = list[i];
171
+ NSString *deviceKey = dataDict[@"deviceKey"];
172
+ NSString *productKey = dataDict[@"productKey"];
173
+ NSArray *messageTypeArray = dataDict[@"messageType"];
174
+ if (deviceKey) {
175
+ [data setValue:deviceKey forKey:@"deviceKey"];
176
+ }
177
+ if (productKey) {
178
+ [data setValue:productKey forKey:@"productKey"];
179
+ }
180
+ if (messageTypeArray && messageTypeArray.count) {
181
+ [data setValue:messageTypeArray forKey:@"messageType"];
182
+ }
183
+ [deviceList addObject:data.copy];
184
+ }
185
+ dataModel.data = deviceList.copy;
186
+ [[QuecWebSocketManager sharedInstance] ws_sendDataModel:dataModel];
187
+ }
188
+ }
189
+
190
+ - (void)impl_unSubscribeDevicesWithList:(NSArray*)list {
191
+ if (list && list.count) {
192
+ self.hasUnsubscribed = false;
193
+ QuecWebSocketDataModel *dataModel = [[QuecWebSocketDataModel alloc] init];
194
+ dataModel.cmd = QuecWebSocketCmdTypeUnsubscribe;
195
+ NSMutableArray *deviceList = @[].mutableCopy;
196
+ for (int i = 0; i < list.count; i ++) {
197
+ NSMutableDictionary *data = @{}.mutableCopy;
198
+ QuecWebSocketActionModel *model = [QuecWebSocketActionModel yy_modelWithJSON:list[i]];
199
+ [data setValue:model.deviceKey forKey:@"deviceKey"];
200
+ [data setValue:model.productKey forKey:@"productKey"];
201
+ [deviceList addObject:data.copy];
202
+ }
203
+ dataModel.data = deviceList.copy;
204
+ [[QuecWebSocketManager sharedInstance] ws_sendDataModel:dataModel];
205
+ }
206
+ }
207
+
208
+ - (void)_unSubscribeDevice:(QuecDeviceModel *)deviceModel {
209
+ if (!deviceModel || ![deviceModel.productKey isKindOfClass:NSString.class] || ![deviceModel.deviceKey isKindOfClass:NSString.class]) {
210
+ return;
211
+ }
212
+ QuecWebSocketDataModel *dataModel = [[QuecWebSocketDataModel alloc] init];
213
+ dataModel.cmd = QuecWebSocketCmdTypeUnsubscribe;
214
+ NSMutableArray *deviceList = @[].mutableCopy;
215
+ NSMutableDictionary *data = @{}.mutableCopy;
216
+
217
+ [data setValue:deviceModel.deviceKey forKey:@"deviceKey"];
218
+ [data setValue:deviceModel.productKey forKey:@"productKey"];
219
+ [deviceList addObject:data.copy];
220
+ dataModel.data = deviceList.copy;
221
+ [[QuecWebSocketManager sharedInstance] ws_sendDataModel:dataModel];
222
+ }
223
+
224
+ - (void)impl_sendDataToDeviceByWebSocketWithDataDict:(NSDictionary*)params {
225
+ QuecWebSocketDataModel *deviceModel = [QuecWebSocketDataModel yy_modelWithJSON:params];
226
+ [[QuecWebSocketManager sharedInstance] ws_sendDataModel:deviceModel];
227
+ }
228
+
229
+ - (void)impl_getDeviceListWithPageNumber:(NSInteger)pageNumber pageSize:(NSInteger)pageSize resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
230
+
231
+ if (!QuecConnectivity.sharedInstance.isConnectedInternet) {
232
+ id<QuecDeviceListProtocol> protocol = quec_service(@protocol(QuecDeviceListProtocol));
233
+ if (protocol) {
234
+ NSArray *deviceList = [protocol getDeviceFormStoreListCache];
235
+
236
+ // 设备列表加入缓存队列
237
+ NSMutableArray *devicesList = [NSMutableArray array];
238
+ for (NSDictionary *device in deviceList) {
239
+ QuecDeviceModel *model = [QuecDeviceModel yy_modelWithJSON:device];
240
+ model.onlineChannelState = 0;
241
+ model.onlineStatus = 0;
242
+ [devicesList addObject:model];
243
+ }
244
+ if (devicesList.count > 0) {
245
+ [QuecIotCacheService.sharedInstance addDeviceModelList:devicesList];
246
+ for (QuecDeviceModel *deviceModel in devicesList) {
247
+ QuecDeviceClient *client = [QuecDeviceClient deviceWithId:deviceModel.deviceId];
248
+ [client connect];
249
+ QuecLogInfo(@"[iot][%@][rn] can't connected internet. connect auto", client.deviceId);
250
+ }
251
+ }
252
+ resolve(@{@"data": @{@"list":deviceList.yy_modelToJSONObject, @"total":@(deviceList.count)}});
253
+ }
254
+ return;
255
+ }
256
+ QuecDeviceListParamsModel *paramsModel = QuecDeviceListParamsModel.new;
257
+ paramsModel.pageSize = pageSize;
258
+ paramsModel.pageNumber = pageNumber;
259
+ [QuecDeviceService.sharedInstance getDeviceListWithParams:paramsModel success:^(NSArray<QuecDeviceModel *> *list, NSInteger total) {
260
+ id<QuecDeviceListProtocol> protocol = quec_service(@protocol(QuecDeviceListProtocol));
261
+ if (protocol) {
262
+ NSMutableArray *devicesList = [NSMutableArray array];
263
+ for (QuecDeviceModel *deviceModel in list) {
264
+ QuecDeviceClient *client = [QuecDeviceClient deviceWithId:deviceModel.deviceId];
265
+ deviceModel.onlineChannelState = client.connectedState;
266
+ deviceModel.onlineStatus = deviceModel.onlineStatus;
267
+ [devicesList addObject:deviceModel];
268
+ id<QuecDeviceOTAProtocol> protocol = quec_service(@protocol(QuecDeviceOTAProtocol));
269
+ if (protocol) {
270
+ [protocol addDeviceOTAStateWithDeviceModel:deviceModel];
271
+ }
272
+ }
273
+ if (devicesList.count > 0) {
274
+ [QuecIotCacheService.sharedInstance addDeviceModelList:devicesList];
275
+ [protocol storeDeviceListCache:devicesList.yy_modelToJSONObject];
276
+ }
277
+ for (QuecDeviceModel *deviceModel in devicesList) {
278
+ QuecDeviceClient *client = [QuecDeviceClient deviceWithId:deviceModel.deviceId];
279
+ [client connect];
280
+ QuecLogInfo(@"[iot][%@][rn] connect auto", client.deviceId);
281
+ }
282
+ }
283
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject, @"total":@(total)}});
284
+ } failure:^(NSError *error) {
285
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
286
+ }];
287
+ }
288
+
289
+ - (void)impl_getProductTSLWithProductKey:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
290
+ NSString *pk = params[@"productKey"];
291
+ NSString *dk = params[@"deviceKey"];
292
+ NSString *gatewayPk = params[@"gatewayPk"];
293
+ NSString *gatewayDk = params[@"gatewayDk"];
294
+ NSString *codeList = params[@"codeList"];
295
+ NSString *type = params[@"type"];
296
+ if (!pk.isValid || !dk.isValid) {
297
+ if (reject) {
298
+ quec_async_on_main(^{
299
+ NSError *error = [NSError errorWithDomain:@"com.iot.device" code:10000 userInfo:nil];
300
+ reject(@"10000", @"pk or dk error", error);
301
+ });
302
+ }
303
+ return;
304
+ }
305
+ [QuecDeviceService.sharedInstance getProductTslAndDeviceBusinessAttributesWithProductKey:pk
306
+ deviceKey:dk
307
+ gatewayPk:gatewayPk
308
+ gatewayDk:gatewayDk
309
+ codeList:codeList
310
+ type:type
311
+ filterType:0
312
+ success:^(NSArray<QuecProductTSLPropertyModel *> *list) {
313
+ if (resolve) {
314
+ quec_async_on_main(^{
315
+ resolve(@{@"data":list.yy_modelToJSONObject ?: @[]});
316
+ });
317
+ }
318
+ } failure:^(NSError *error) {
319
+ if (reject) {
320
+ quec_async_on_main(^{
321
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
322
+ });
323
+ }
324
+ }];
325
+ }
326
+
327
+ - (void)impl_getDeviceBusinessAttributesWithProductKey:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
328
+ [[QuecDeviceService sharedInstance] getDeviceBusinessAttributesWithProductKey:params[@"productKey"] deviceKey:params[@"deviceKey"] gatewayPk:params[@"gatewayPk"] gatewayDk:params[@"gatewayDk"] codeList:params[@"codeList"] type:params[@"type"] success:^(QuecProductTSLInfoModel *tslInfoModel) {
329
+
330
+ resolve(@{@"data": tslInfoModel.yy_modelToJSONObject});
331
+ } failure:^(NSError *error) {
332
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
333
+ }];
334
+ }
335
+
336
+ - (void)impl_updateDeviceNameByShareUserWithDeviceName:(NSString*)deviceName shareCode:(NSString*)shareCode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
337
+ [QuecDeviceShareService.sharedInstance updateDeviceNameByShareUserWithDeviceName:deviceName shareCode:shareCode success:^{
338
+ if (resolve) {
339
+ resolve(@{@"data": @{}});
340
+ }
341
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUpdateDeviceNameSuccessed" object:nil userInfo:@{@"shareCode":shareCode?:@"unknown"}];
342
+ } failure:^(NSError *error) {
343
+ if (reject) {
344
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
345
+ }
346
+ }];
347
+ }
348
+
349
+ - (void)impl_updateDeviceName:(NSString*)deviceName productKey:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
350
+ [[QuecDeviceService sharedInstance] updateDeviceName:deviceName productKey:productKey deviceKey:deviceKey success:^{
351
+ resolve(@{@"data": @{}});
352
+
353
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUpdateDeviceNameSuccessed" object:nil userInfo:@{@"productKey":productKey?:@"unknown", @"deviceKey":deviceKey?:@"unknown"}];
354
+ } failure:^(NSError *error) {
355
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
356
+ }];
357
+ }
358
+
359
+ - (void)impl_getGatewayDeviceChildListWithParams:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
360
+ [QuecDeviceGroupService.sharedInstance getGatewayDeviceChildListWithDeviceKey:params[@"deviceKey"]
361
+ productKey:params[@"productKey"]
362
+ childDk:@""
363
+ childPk:@""
364
+ pageNumber:[params[@"pageNumber"] integerValue]
365
+ pageSize:[params[@"pageSize"] integerValue]
366
+ success:^(NSArray<QuecDeviceModel *> * _Nonnull list, NSInteger total) {
367
+ if (resolve) {
368
+ // 网关子设备需要加入缓存,否则无法建立通道 (废弃 实现放入sdk层)
369
+ // [QuecIotCacheService.sharedInstance addDeviceModelList:list];
370
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject ? : @"null", @"total":@(total)}});
371
+ }
372
+ } failure:^(NSError *error) {
373
+ if (reject) {
374
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
375
+ }
376
+ }];
377
+ }
378
+
379
+
380
+ - (void)impl_unbindDeviceWithDeviceKey:(NSString*)deviceKey productKey:(NSString*)productKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
381
+ self.unbindingDevice = YES;
382
+ __weak __typeof(self)weakSelf = self;
383
+ [self.device remove:^{
384
+ resolve(@{@"data": @{}});
385
+ quec_delay_on_main(1.0f, ^{
386
+ [quec_TopViewController() quec_goBackToFirstPage:true];
387
+ weakSelf.unbindingDevice = NO;
388
+ });
389
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUnbindDeviceSuccessed" object:nil userInfo:@{@"productKey":productKey?:@"unknown", @"deviceKey":deviceKey?:@"unknown"}];
390
+
391
+ } failure:^(NSError * _Nonnull error) {
392
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
393
+ weakSelf.unbindingDevice = NO;
394
+ }];
395
+ }
396
+
397
+ - (void)impl_unShareDeviceByShareUserWithShareCode:(NSString*)shareCode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
398
+ self.unbindingDevice = YES;
399
+ __weak __typeof(self)weakSelf = self;
400
+ [self.device remove:^{
401
+ resolve(@{@"data": @{}});
402
+ quec_delay_on_main(1.0f, ^{
403
+ [quec_TopViewController() quec_goBackToFirstPage:true];
404
+ weakSelf.unbindingDevice = NO;
405
+ });
406
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUnbindDeviceSuccessed" object:nil userInfo:@{@"shareCode":shareCode?:@"unknown"}];
407
+ } failure:^(NSError * _Nonnull error) {
408
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
409
+ weakSelf.unbindingDevice = NO;
410
+ }];
411
+ }
412
+
413
+ - (void)impl_getPropertyChartListWithParams:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
414
+ NSInteger countType = 3;
415
+ NSInteger timeGranularity = 2;
416
+ if (params[@"countType"]) {
417
+ countType = [params[@"countType"] integerValue];
418
+ }
419
+ if (params[@"timeGranularity"]) {
420
+ timeGranularity = [params[@"timeGranularity"] integerValue];
421
+ }
422
+ [QuecDeviceStatisticsService.sharedInstance getPropertyChartListWithProductKey:params[@"productKey"]
423
+ deviceKey:params[@"deviceKey"]
424
+ startTimestamp:[params[@"startTimestamp"] integerValue]
425
+ endTimestamp:[params[@"endTimestamp"] integerValue]
426
+ attributeCode:params[@"attributeCode"]
427
+ gatewayDk:params[@"gatewayDk"]
428
+ gatewayPk:params[@"gatewayPk"]
429
+ countType:countType
430
+ timeGranularity:timeGranularity
431
+ success:^(NSArray<QuecPropertyChartListModel *> * _Nonnull dataArray) {
432
+ if (resolve) {
433
+ resolve(@{@"data": dataArray.yy_modelToJSONObject ? : @[]});
434
+ }
435
+ } failure:^(NSError *error) {
436
+ if (reject) {
437
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
438
+ }
439
+ }];
440
+ }
441
+
442
+ - (void)impl_getDeviceShareUserListWithDeviceKey:(NSString*)deviceKey productKey:(NSString*)productKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
443
+ [QuecDeviceShareService.sharedInstance getDeviceShareUserListWithDeviceKey:deviceKey productKey:productKey success:^(NSArray<QuecShareUserModel *> * _Nonnull list) {
444
+ if (resolve) {
445
+ resolve(@{@"data": list.yy_modelToJSONObject});
446
+ }
447
+ } failure:^(NSError *error) {
448
+ if (reject) {
449
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
450
+ }
451
+ }];
452
+ }
453
+
454
+ - (void)impl_setShareInfoByOwnerWithDeviceKey:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
455
+ [QuecDeviceShareService.sharedInstance setShareInfoByOwnerWithDeviceKey:params[@"deviceKey"]
456
+ productKey:params[@"productKey"]
457
+ acceptingExpireTime:[params[@"acceptingExpireTime"] integerValue]
458
+ coverMark:[params[@"coverMark"] integerValue]
459
+ isSharingAlwaysValid:[params[@"isSharingAlwaysValid"] boolValue]
460
+ sharingExpireTime:[params[@"sharingExpireTime"] integerValue] success:^(NSString * _Nonnull shareCode) {
461
+ if (resolve) {
462
+ resolve(@{@"data": shareCode});
463
+ }
464
+ } failure:^(NSError *error) {
465
+ if (reject) {
466
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
467
+ }
468
+ }];
469
+ }
470
+
471
+
472
+ - (void)impl_unShareDeviceByOwnerWithShareCode:(NSString*)shareCode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
473
+ [QuecDeviceShareService.sharedInstance unShareDeviceByOwnerWithShareCode:shareCode success:^{
474
+ if (resolve) {
475
+ resolve(@{@"data": @{}});
476
+ }
477
+ } failure:^(NSError *error) {
478
+ if (reject) {
479
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
480
+ }
481
+ }];
482
+ }
483
+
484
+ - (void)impl_getLocationHistoryWithParams:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
485
+ [QuecDeviceStatisticsService.sharedInstance getLocationHistoryWithProductKey:params[@"productKey"]
486
+ deviceKey:params[@"deviceKey"]
487
+ startTimestamp:[params[@"startTimestamp"] integerValue]
488
+ endTimestamp:[params[@"endTimestamp"] integerValue]
489
+ gatewayDk:params[@"gatewayDk"]
490
+ gatewayPk:params[@"gatewayPk"]
491
+ locateTypes:params[@"locateTypes"]
492
+ success:^(NSArray<QuecLocationHistoryModel *> * _Nonnull list) {
493
+ if (resolve) {
494
+ resolve(@{@"data": list.yy_modelToJSONObject ? : @[]});
495
+ }
496
+ } failure:^(NSError *error) {
497
+ if (reject) {
498
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
499
+ }
500
+ }];
501
+ }
502
+
503
+ - (void)impl_getDeviceInfoByDeviceKey:(NSString *)deviceKey
504
+ productKey:(NSString *)productKey
505
+ resolve:(RCTPromiseResolveBlock)resolve
506
+ reject:(RCTPromiseRejectBlock)reject{
507
+ [[QuecDeviceService sharedInstance] getDeviceInfoByDeviceKey:deviceKey productKey:productKey success:^(QuecDeviceModel *deviceModel) {
508
+ resolve(@{@"data": deviceModel.yy_modelToJSONObject});
509
+ } failure:^(NSError *error) {
510
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
511
+ }];
512
+ }
513
+
514
+ - (void)impl_getPropertyDataListWithParams:(NSDictionary*)params
515
+ resolve:(RCTPromiseResolveBlock)resolve
516
+ reject:(RCTPromiseRejectBlock)reject {
517
+ [QuecDeviceStatisticsService.sharedInstance getPropertyDataListWithProductKey:params[@"productKey"]
518
+ deviceKey:params[@"deviceKey"]
519
+ startTimestamp:[params[@"startTimestamp"] integerValue]
520
+ endTimestamp:[params[@"endTimestamp"] integerValue]
521
+ attributeCode:params[@"attributeCode"]
522
+ gatewayDk:params[@"gatewayDk"]
523
+ gatewayPk:params[@"gatewayPk"]
524
+ pageNumber:[params[@"pageNumber"] integerValue]
525
+ pageSize:[params[@"pageSize"] integerValue] success:^(NSArray<QuecPropertyDataListModel *> * _Nonnull list, NSInteger total) {
526
+ if (resolve) {
527
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject ? : @[], @"total":@(total)}});
528
+ }
529
+ } failure:^(NSError *error) {
530
+ if (reject) {
531
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
532
+ }
533
+ }];
534
+ }
535
+
536
+ - (void)impl_getPropertyStatisticsWithParams:(NSDictionary *)params
537
+ resolve:(RCTPromiseResolveBlock)resolve
538
+ reject:(RCTPromiseRejectBlock)reject {
539
+ NSInteger countType = 3;
540
+ if (params[@"countType"]) {
541
+ countType = [params[@"countType"] integerValue];
542
+ }
543
+ [QuecDeviceStatisticsService.sharedInstance getPropertyStatisticsPathWithProductKey:params[@"productKey"]
544
+ deviceKey:params[@"deviceKey"]
545
+ currentTimestamp:[params[@"currentTimestamp"] integerValue]
546
+ attributeCode:params[@"attributeCode"]
547
+ gatewayDk:params[@"gatewayDk"]
548
+ gatewayPk:params[@"gatewayPk"]
549
+ countType:countType
550
+ timeGranularities:params[@"timeGranularities"]
551
+ success:^(NSArray<QuecPropertyStatisticsModel *> * _Nonnull dataArray) {
552
+ if (resolve) {
553
+ resolve(@{@"data": dataArray.yy_modelToJSONObject ? : @[]});
554
+ }
555
+ } failure:^(NSError *error) {
556
+ if (reject) {
557
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
558
+ }
559
+ }];
560
+ }
561
+
562
+ - (void)impl_getDeviceInfoByShareCode:(NSString*)shareCode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
563
+ [QuecDeviceShareService.sharedInstance getDeviceInfoByShareCode:shareCode success:^(QuecDeviceModel * _Nonnull deviceModel) {
564
+ if (resolve) {
565
+ resolve(@{@"data": deviceModel.yy_modelToJSONObject ? : @{}});
566
+ }
567
+ } failure:^(NSError *error) {
568
+ if (reject) {
569
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
570
+ }
571
+ }];
572
+ }
573
+
574
+ - (void)impl_getDeviceListByDeviceName:(NSString*)deviceName pageNumber:(NSInteger)pageNumber pageSize:(NSInteger)pageSize resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
575
+ QuecDeviceListParamsModel *paramsModel = QuecDeviceListParamsModel.new;
576
+ paramsModel.pageSize = pageSize;
577
+ paramsModel.pageNumber = pageNumber;
578
+ paramsModel.deviceName = deviceName;
579
+ [QuecDeviceService.sharedInstance getDeviceListWithParams:paramsModel success:^(NSArray<QuecDeviceModel *> *list, NSInteger total) {
580
+ if (resolve) {
581
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject, @"total":@(total)}});
582
+ }
583
+ } failure:^(NSError *error) {
584
+ if (reject) {
585
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
586
+ }
587
+ }];
588
+ }
589
+
590
+ - (void)impl_bindDeviceBySerialNumber:(NSString*)serialNumber productKey:(NSString*)productKey deviceName:(NSString*)deviceName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
591
+ [QuecDeviceService.sharedInstance bindDeviceWithSerialNumber:serialNumber productKey:productKey deviceName:deviceName success:^(QuecDeviceBindSNModel *model) {
592
+ if (resolve) {
593
+ resolve(@{@"data": @{}});
594
+ }
595
+ } failure:^(NSError *error) {
596
+ if (reject) {
597
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
598
+ }
599
+ }];
600
+ }
601
+
602
+ - (void)impl_bindDeviceByAuthCode:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
603
+ [QuecDeviceService.sharedInstance bindWifiDeviceWithAuthCode:params[@"authCode"]
604
+ productKey:params[@"productKey"]
605
+ deviceKey:params[@"deviceKey"]
606
+ deviceName:params[@"deviceName"]
607
+ capabilitiesBitmask:0
608
+ success:^(QuecDeviceBindAuthCodeModel *model) {
609
+ if (resolve) {
610
+ resolve(@{@"data": @{}});
611
+ }
612
+ } failure:^(NSError *error) {
613
+ if (reject) {
614
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
615
+ }
616
+ }];
617
+ }
618
+
619
+ - (void)impl_bindDeviceByPSWAuthCode:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
620
+ // [[QuecDeviceService sharedInstance] bindDeviceByAuthCode:params[@"authCode"] productKey:params[@"productKey"] deviceKey:params[@"deviceKey"] password:params[@"password"] deviceName:params[@"deviceName"] success:^{
621
+ // resolve(@{@"data": @{}});
622
+ // } failure:^(NSError *error) {
623
+ // reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
624
+ // }];
625
+ }
626
+
627
+ - (void)impl_getFetchPlanWithProductKey:(NSString*)productKey deviceKey:(NSString*)deviceKey params:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
628
+ QuecDeviceOTAQueryModel *extraInfoModel = nil;
629
+ if (params) {
630
+ extraInfoModel = [QuecDeviceOTAQueryModel yy_modelWithJSON:params];
631
+ }
632
+ [[QuecHttpOTAService sharedInstance] getFetchPlanWithProductKey:productKey deviceKey:deviceKey extraInfo:extraInfoModel success:^(QuecDeviceOTAPlanModel *planModel) {
633
+
634
+ resolve(@{@"data": planModel.yy_modelToJSONObject});
635
+ } failure:^(NSError *error) {
636
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
637
+ }];
638
+ }
639
+
640
+ - (void)impl_reportDeviceUpgradeStatusWithProductKey:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
641
+ [[QuecHttpOTAService sharedInstance] reportDeviceUpgradeStatusWithProductKey:params[@"productKey"] deviceKey:params[@"deviceKey"] componentNo:params[@"componentNo"] reportStatus:[params[@"reportStatus"] integerValue] success:^{
642
+ resolve(@{@"data": @{}});
643
+ } failure:^(NSError *error) {
644
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
645
+ }];
646
+ }
647
+
648
+ - (void)impl_sendDataToDevicesByHttpWithData:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
649
+ NSArray *deviceList = params[@"deviceList"];
650
+ NSMutableArray *controls = @[].mutableCopy;
651
+ for (NSDictionary *dict in deviceList) {
652
+ QuecBatchControlDeviceModel *model = QuecBatchControlDeviceModel.new;
653
+ model.deviceKey = [dict quec_safeObjectForKey:@"deviceKey"];
654
+ model.productKey = [dict quec_safeObjectForKey:@"productKey"];
655
+ [controls quec_safeAddObject:model];
656
+ }
657
+ QuecBatchControlExtraModel *extraModel = QuecBatchControlExtraModel.new;
658
+ extraModel.dataFormat = [params[@"dataFormat"] integerValue];
659
+ [QuecDeviceControlService.sharedInstance sendDataToDevicesByHttpWithData:params[@"data"]
660
+ deviceList:controls
661
+ type:[params[@"type"] quec_int]
662
+ extraData:extraModel
663
+ success:^(QuecBatchControlModel * _Nonnull model) {
664
+ if (resolve) {
665
+ resolve(@{@"data": [model yy_modelToJSONObject]});
666
+ }
667
+ } failure:^(NSError *error) {
668
+ if (reject) {
669
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
670
+ }
671
+ }];
672
+ }
673
+
674
+ - (void)impl_addCornJob:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
675
+ QuecCornJobModel *cornJobModel = [QuecCornJobModel yy_modelWithDictionary:params];
676
+ [QuecDeviceService.sharedInstance addCornJobWithCornJobModel:cornJobModel success:^(NSString *ruleId) {
677
+ if (resolve) {
678
+ resolve(@{@"data": @{@"ruleId" : ruleId ?:@""}});
679
+ }
680
+ } failure:^(NSError *error) {
681
+ if (reject) {
682
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
683
+ }
684
+ }];
685
+ }
686
+
687
+ - (void)impl_setCronJob:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
688
+ QuecCornJobModel *cornJobModel = [QuecCornJobModel yy_modelWithDictionary:params];
689
+ [[QuecDeviceService sharedInstance] setCronJobWithCornJobModel:cornJobModel success:^(NSDictionary *data){
690
+ resolve(@{@"data": data});
691
+ } failure:^(NSError *error) {
692
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
693
+ }];
694
+ }
695
+
696
+ - (void)impl_getCronJobList:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
697
+ NSInteger page = 1;
698
+ NSInteger pageSize = 10;
699
+ if (params[@"page"]) {
700
+ page = [params[@"page"] integerValue];
701
+ }
702
+ if (params[@"pageSize"]) {
703
+ pageSize = [params[@"pageSize"] integerValue];
704
+ }
705
+
706
+ [[QuecDeviceService sharedInstance] getCronJobListWithDeviceKey:params[@"deviceKey"] productKey:params[@"productKey"] type:params[@"type"] pageNumber:page pageSize:pageSize success:^(NSArray<QuecCornJobModel *> *list, NSInteger total) {
707
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject, @"total":@(total)}});
708
+ } failure:^(NSError *error) {
709
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
710
+ }];
711
+ }
712
+
713
+ - (void)impl_getCronJobInfo:(NSString*)ruleId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
714
+ [[QuecDeviceService sharedInstance] getCronJobInfoWithRuleId:ruleId success:^(QuecCornJobModel *model) {
715
+ resolve(@{@"data": [model yy_modelToJSONObject]});
716
+ } failure:^(NSError *error) {
717
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
718
+ }];
719
+ }
720
+
721
+ - (void)impl_batchDeleteCronJob:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
722
+ [QuecDeviceService.sharedInstance batchDeleteCronJobWithParams:params success:^(QuecCornJobDeleteListModel *model) {
723
+ if (resolve) {
724
+ resolve(@{@"data": model.yy_modelToJSONObject ?: @{}});
725
+ }
726
+ } failure:^(NSError *error) {
727
+ if (reject) {
728
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
729
+ }
730
+ }];
731
+ }
732
+
733
+ - (void)impl_getProductCornJobLimit:(NSString*)productKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
734
+ [[QuecDeviceService sharedInstance] getProductCornJobLimitWithProductKey:productKey success:^(NSInteger limit) {
735
+ resolve(@{@"data": @(limit)});
736
+ } failure:^(NSError *error) {
737
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
738
+ }];
739
+
740
+ }
741
+
742
+ - (void)impl_getProductTSLWithCacheByProductKey:(NSDictionary*)param resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
743
+ [QuecDeviceService.sharedInstance getProductTSLWithProductKey:param[@"productKey"] ? : @"" success:^(QuecProductTSLModel *tslModel) {
744
+ if (resolve) {
745
+ resolve(@{@"data": tslModel.properties.yy_modelToJSONObject ? : @[]});
746
+ }
747
+ } failure:^(NSError *error) {
748
+ if (reject) {
749
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
750
+ }
751
+ }];
752
+ }
753
+
754
+ - (void)impl_openWebSocket {
755
+ if (![QuecWebSocketManager sharedInstance].isLogin) {
756
+ [[QuecWebSocketManager sharedInstance] open];
757
+ }
758
+
759
+ }
760
+
761
+ - (void)impl_closeWebSocket {
762
+ if ([[QuecWebSocketManager sharedInstance] isLogin]) {
763
+ [[QuecWebSocketManager sharedInstance] close];
764
+ }
765
+ }
766
+
767
+ - (void)impl_getTslAndAttrs:(NSDictionary*)params resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
768
+ NSString *pk = params[@"productKey"];
769
+ NSString *dk = params[@"deviceKey"];
770
+ NSString *gatewayPk = params[@"gatewayPk"];
771
+ NSString *gatewayDk = params[@"gatewayDk"];
772
+ NSString *codeList = params[@"codeList"];
773
+ NSString *type = params[@"type"];
774
+ NSInteger filterType = params[@"filterType"] ? [params[@"filterType"] quec_int] : 0;
775
+ if (!pk.isValid || !dk.isValid) {
776
+ if (reject) {
777
+ quec_async_on_main(^{
778
+ NSError *error = [NSError errorWithDomain:@"com.iot.device" code:10000 userInfo:nil];
779
+ reject(@"10000", @"pk or dk error", error);
780
+ });
781
+ }
782
+ return;
783
+ }
784
+ [QuecDeviceService.sharedInstance getProductTslAndDeviceBusinessAttributesWithProductKey:pk
785
+ deviceKey:dk
786
+ gatewayPk:gatewayPk
787
+ gatewayDk:gatewayDk
788
+ codeList:codeList
789
+ type:type
790
+ filterType:filterType
791
+ success:^(NSArray<QuecProductTSLPropertyModel *> *list) {
792
+ if (resolve) {
793
+ quec_async_on_main(^{
794
+ resolve(@{@"data":list.yy_modelToJSONObject ?: @[]});
795
+ });
796
+ }
797
+ } failure:^(NSError *error) {
798
+ if (reject) {
799
+ quec_async_on_main(^{
800
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
801
+ });
802
+ }
803
+ }];
804
+ }
805
+
806
+ - (void)impl_readDps:(NSArray*)dps resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
807
+ [self impl_readDpsWithMode:dps mode:QuecIotChannelModeAuto resolve:resolve reject:reject];
808
+ }
809
+
810
+ - (void)impl_writeDps:(NSArray*)dps resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
811
+ [self impl_writeDpsWithMode:dps mode:QuecIotChannelModeAuto resolve:resolve reject:reject];
812
+ }
813
+
814
+ - (void)impl_writeTransparent:(NSString*)data mode:(NSInteger)mode extraData:(NSDictionary*)extraData resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
815
+ if (![data isKindOfClass:NSString.class]) {
816
+ return;
817
+ }
818
+ NSData *sendData = [[NSData alloc] initWithBase64EncodedString:data options:0];
819
+ [self.device writeTransparent:sendData success:^{
820
+ if (resolve) {
821
+ quec_async_on_main(^{
822
+ resolve(@{});
823
+ });
824
+ }
825
+ } failure:^(NSError * _Nonnull error) {
826
+ if (reject && error) {
827
+ quec_async_on_main(^{
828
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
829
+ });
830
+ }
831
+ }];
832
+ }
833
+
834
+ - (void)impl_readDpsWithMode:(NSArray*)dps mode:(NSInteger)mode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
835
+ NSMutableArray *mDps = [NSMutableArray array];
836
+ for (NSDictionary *item in dps) {
837
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
838
+ if (dp.dataType != QuecIotDataPointDataTypeUnknown && dp.dataType != QuecIotDataPointDataTypeEVENT) {
839
+ [mDps addObject:dp];
840
+ }
841
+ }
842
+
843
+ [self.device readDps:mDps.copy mode:mode success:^{
844
+ if (resolve) {
845
+ quec_async_on_main(^{
846
+ resolve(@{});
847
+ });
848
+ }
849
+ } failure:^(NSError * _Nonnull error) {
850
+ if (reject && error) {
851
+ quec_async_on_main(^{
852
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
853
+ });
854
+ }
855
+ }];
856
+ }
857
+
858
+ - (void)impl_writeDpsWithMode:(NSArray*)dps mode:(NSInteger)mode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
859
+ NSMutableArray *mDps = [NSMutableArray array];
860
+ for (NSDictionary *item in dps) {
861
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
862
+ [mDps addObject:dp];
863
+ }
864
+ [self.device writeDps:mDps mode:mode success:^{
865
+ if (resolve) {
866
+ quec_async_on_main(^{
867
+ resolve(@{});
868
+ });
869
+ }
870
+ } failure:^(NSError * _Nonnull error) {
871
+ if (reject && error) {
872
+ quec_async_on_main(^{
873
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
874
+ });
875
+ }
876
+ }];
877
+ }
878
+
879
+ - (void)impl_getOnlineState:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
880
+ QuecLogInfo(@"[iot][%@][rn] impl_getOnlineState: verified:%@ connectedState: %ld", self.device.deviceId, self.device.model.verified, self.device.connectedState);
881
+ if (resolve) {
882
+ resolve(@{@"onlineState": @(self.device.connectedState)});
883
+ }
884
+ }
885
+
886
+ - (void)impl_connectChannel:(NSInteger)mode {
887
+ [self.device connectWithMode:mode];
888
+ }
889
+
890
+ - (void)impl_disconnectChannel:(NSInteger)type {
891
+ [self.device disconnectWithType:type];
892
+ }
893
+
894
+ - (void)impl_writeDpsWithExtraData:(NSArray *)dps extraData:(NSDictionary *)extraData resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
895
+ NSMutableArray *mDps = [NSMutableArray array];
896
+ for (NSDictionary *item in dps) {
897
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
898
+ [mDps addObject:dp];
899
+ }
900
+ QuecIotChannelExtraData *extraDataModel;
901
+ if (extraData && extraData.allKeys.count) {
902
+ extraDataModel = [[QuecIotChannelExtraData alloc] init];
903
+ if (extraData[@"cacheTime"]) {
904
+ NSNumber *cacheTimeNumber = (NSNumber *)extraData[@"cacheTime"];
905
+ extraDataModel.cacheTime = [cacheTimeNumber longValue];
906
+ }
907
+ if (extraData[@"msgId"]) {
908
+ NSNumber *msgIdNumber = (NSNumber *)extraData[@"msgId"];
909
+ extraDataModel.msgId = [msgIdNumber longLongValue];
910
+ }
911
+ }
912
+ [self.device writeDps:mDps extraData:extraDataModel success:^{
913
+ if (resolve) {
914
+ quec_async_on_main(^{
915
+ resolve(@{});
916
+ });
917
+ }
918
+ } failure:^(NSError * _Nonnull error) {
919
+ if (reject && error) {
920
+ quec_async_on_main(^{
921
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
922
+ });
923
+ }
924
+ }];
925
+
926
+ }
927
+
928
+ - (void)impl_writeDpsWithExtraDataAndMode:(NSArray *)dps extraData:(NSDictionary *)extraData mode:(NSInteger)mode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
929
+ NSMutableArray *mDps = [NSMutableArray array];
930
+ for (NSDictionary *item in dps) {
931
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
932
+ [mDps addObject:dp];
933
+ }
934
+ QuecIotChannelExtraData *extraDataModel;
935
+ if (extraData && extraData.allKeys.count) {
936
+ extraDataModel = [[QuecIotChannelExtraData alloc] init];
937
+ if (extraData[@"cacheTime"]) {
938
+ NSNumber *cacheTimeNumber = (NSNumber *)extraData[@"cacheTime"];
939
+ extraDataModel.cacheTime = [cacheTimeNumber longValue];
940
+ }
941
+ if (extraData[@"msgId"]) {
942
+ NSNumber *msgIdNumber = (NSNumber *)extraData[@"msgId"];
943
+ extraDataModel.msgId = [msgIdNumber longLongValue];
944
+ }
945
+ }
946
+ [self.device writeDps:mDps extraData:extraDataModel mode:mode success:^{
947
+ if (resolve) {
948
+ quec_async_on_main(^{
949
+ resolve(@{});
950
+ });
951
+ }
952
+ } failure:^(NSError * _Nonnull error) {
953
+ if (reject && error) {
954
+ quec_async_on_main(^{
955
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
956
+ });
957
+ }
958
+ }];
959
+ }
960
+
961
+ - (void)impl_getBleState:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
962
+ if(resolve) {
963
+ NSInteger state = 0;
964
+ switch ([QuecBleManager sharedInstance].state) {
965
+ case CBManagerStateUnauthorized: {
966
+ state = 1;
967
+ }
968
+ break;
969
+ case CBManagerStatePoweredOn: {
970
+ state = 2;
971
+ }
972
+ break;
973
+ default:
974
+ break;
975
+ }
976
+ resolve(@{@"state": @(state)});
977
+ }
978
+ }
979
+
980
+ - (void)impl_readDpsWithExtraData:(NSArray *)dps extraData:(NSDictionary *)extraData resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
981
+ [self impl_readDpsWithExtraDataAndMode:dps extraData:extraData mode:QuecIotChannelModeAuto resolve:resolve reject:reject];
982
+ }
983
+
984
+ - (void)impl_readDpsWithExtraDataAndMode:(NSArray *)dps extraData:(NSDictionary *)extraData mode:(NSInteger)mode resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
985
+ NSMutableArray *mDps = [NSMutableArray array];
986
+ for (NSDictionary *item in dps) {
987
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
988
+ [mDps addObject:dp];
989
+ }
990
+ QuecIotChannelExtraData *extraDataModel;
991
+ if (extraData && extraData.allKeys.count) {
992
+ extraDataModel = [[QuecIotChannelExtraData alloc] init];
993
+ if (extraData[@"cacheTime"]) {
994
+ NSNumber *cacheTimeNumber = (NSNumber *)extraData[@"cacheTime"];
995
+ extraDataModel.cacheTime = [cacheTimeNumber longValue];
996
+ }
997
+ if (extraData[@"msgId"]) {
998
+ NSNumber *msgIdNumber = (NSNumber *)extraData[@"msgId"];
999
+ extraDataModel.msgId = [msgIdNumber longLongValue];
1000
+ }
1001
+ }
1002
+ [self.device readDps:mDps.copy extraData:extraDataModel mode:mode success:^{
1003
+ if (resolve) {
1004
+ quec_async_on_main(^{
1005
+ resolve(@{});
1006
+ });
1007
+ }
1008
+ } failure:^(NSError * _Nonnull error) {
1009
+ if (reject && error) {
1010
+ quec_async_on_main(^{
1011
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
1012
+ });
1013
+ }
1014
+ }];
1015
+ }
1016
+
1017
+ - (void)impl_writeDpsByHttp:(NSArray*)dps deviceList:(NSArray*)deviceList type:(NSInteger)type extraData:(NSDictionary*)extraData resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1018
+ NSMutableArray *mDps = [NSMutableArray array];
1019
+ for (NSDictionary *item in dps) {
1020
+ QuecIotDataPoint *dp = [QuecIotDataPoint yy_modelWithJSON:item];
1021
+ [mDps addObject:dp];
1022
+ }
1023
+ NSMutableArray *devices = [NSMutableArray array];
1024
+ for (NSDictionary *dict in deviceList) {
1025
+ QuecBatchControlDeviceModel *model = QuecBatchControlDeviceModel.new;
1026
+ model.productKey = [dict quec_safeObjectForKey:@"productKey"];
1027
+ model.deviceKey = [dict quec_safeObjectForKey:@"deviceKey"];
1028
+ [devices quec_safeAddObject:model];
1029
+ }
1030
+ QuecBatchControlExtraModel *extraModel = [QuecBatchControlExtraModel yy_modelWithJSON:extraData];
1031
+ [QuecDeviceClient writeDpsByHttp:mDps
1032
+ deviceList:devices
1033
+ type:type
1034
+ extraData:extraModel
1035
+ success:^(QuecBatchControlModel * _Nonnull model) {
1036
+ if (resolve) {
1037
+ quec_async_on_main(^{
1038
+ resolve(model.yy_modelToJSONObject ?: @{});
1039
+ });
1040
+ }
1041
+ } failure:^(NSError *error) {
1042
+ quec_async_on_main(^{
1043
+ reject([[NSNumber numberWithInteger:error.code] stringValue], error.localizedDescription, error);
1044
+ });
1045
+ }];
1046
+ }
1047
+
1048
+ - (void)impl_getDeviceConnectingState:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1049
+ if (self.device) {
1050
+ NSUInteger connectingState = 0;
1051
+ connectingState = self.device.connectingState;
1052
+ resolve(@{@"connectingState": @(connectingState)});
1053
+ } else if (reject) {
1054
+ reject(@"something wrong", @"something wrong", nil);
1055
+ }
1056
+ }
1057
+
1058
+ - (void)impl_isWebSocketSubscribe:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1059
+ if (self.device && resolve) {
1060
+ // BOOL isWebSocketSubscribe = [self.device isWebSocketSubscribe];
1061
+ BOOL isWebSocketSubscribe = self.device.connectedState & QuecIotChannelStateMaskWS;
1062
+ resolve(@{@"subscribe": @(isWebSocketSubscribe)});
1063
+ } else if (reject) {
1064
+ reject(@"something wrong", @"something wrong", nil);
1065
+ }
1066
+ }
1067
+
1068
+ ///** 当前版本暂不提供该能力
1069
+ //订阅设备(非当前面板设备)
1070
+ //
1071
+ //@available 2.0.0
1072
+ //@param pk string 产品id
1073
+ //@param dk string 设备id
1074
+ //*/
1075
+ - (void)impl_subscribeDevice:(NSString*)pk dk:(NSString*)dk {
1076
+ NSString *deviceId = quec_deviceId(pk, dk);
1077
+ QuecLogInfo(@"[iot][%@][rn]subscribeDevice:%@", deviceId);
1078
+ if (![self.subDeviecDict.allKeys containsObject:deviceId]) {
1079
+ QuecDeviceClient *device = [QuecDeviceClient deviceWithId:deviceId];
1080
+ [device setDelegate:self];
1081
+ [self.subDeviecDict quec_safeSetObject:device forKey:deviceId];
1082
+ } else {
1083
+ QuecDeviceClient *device = [self.subDeviecDict quec_safeObjectForKey:deviceId];
1084
+ if (device.delegate != self) {
1085
+ device.delegate = self;
1086
+ }
1087
+ }
1088
+ }
1089
+ //
1090
+ ///**
1091
+ //取消订阅 (非当前面板设备)
1092
+ //
1093
+ //@available 2.0.0
1094
+ //@param pk string 产品id
1095
+ //@param dk string 设备id
1096
+ // */
1097
+ - (void)impl_unSubscribeDevice:(NSString*)pk dk:(NSString*)dk {
1098
+ NSString *deviceId = quec_deviceId(pk, dk);
1099
+ QuecLogInfo(@"[iot][%@][rn]unSubscribeDevice:%@", deviceId);
1100
+ if (![self.device.deviceId isEqualToString:deviceId]) {
1101
+ QuecDeviceClient *device = [self.subDeviecDict quec_safeObjectForKey:quec_deviceId(pk, dk)];
1102
+ device.delegate = nil;
1103
+ [self.subDeviecDict removeObjectForKey:quec_deviceId(pk, dk)];
1104
+
1105
+ } else {
1106
+ QuecLogInfo(@"[iot][%@][rn] unsupport unSubsceribe this Deivce :%@", deviceId);
1107
+ }
1108
+ }
1109
+
1110
+ - (void)clear_subscribe {
1111
+ [self.subDeviecDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, QuecDeviceClient * _Nonnull device, BOOL * _Nonnull stop) {
1112
+ device.delegate = nil;
1113
+ }];
1114
+ [self.subDeviecDict removeAllObjects];
1115
+ }
1116
+
1117
+ #pragma mark device delegate
1118
+ //- (void)deviceInfoUpdate:(QuecDevice *)device {
1119
+ // if (!self.hasListeners) {
1120
+ // return;
1121
+ // }
1122
+ //}
1123
+
1124
+ - (void)device:(QuecDeviceClient *)device onlineUpdate:(NSUInteger)onlineState {
1125
+ if (!self.hasListeners) {
1126
+ return;
1127
+ }
1128
+ if (self.isUnbindingDevice) {
1129
+ return;
1130
+ }
1131
+ QuecLogInfo(@"[iot][%@][rn]onlineState:%@", device.deviceId, @(onlineState));
1132
+ if ([self.subDeviecDict.allKeys containsObject:device.deviceId] && [device.model isKindOfClass:QuecDeviceModel.class]) {
1133
+ NSMutableDictionary *data = @{}.mutableCopy;
1134
+ [data quec_safeSetObject:@(onlineState) forKey:@"onlineState"];
1135
+ [data quec_safeSetObject:[device.model yy_modelToJSONString] ? : @"" forKey:@"device"];
1136
+ [self sendEvent_onDeviceOnlineState:data];
1137
+ }
1138
+ }
1139
+
1140
+ - (void)deviceRemoved:(QuecDeviceClient *)device {
1141
+ QuecLogInfo(@"[iot][%@][rn]deviceRemoved", device.deviceId);
1142
+ if ([device.deviceId isEqualToString:self.device.deviceId]) {
1143
+ // QuecRNContext *rnContext = [QuecRNContext currentRNContext];
1144
+ // [rnContext.contextForViewController.view makeToast:@"quec_device_invalid_tip".quec_localized duration:2.0 position:QuecToastPositionCenter];
1145
+ id<QuecHomePageModuleProtocol> protocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecHomePageModuleProtocol)];
1146
+ if (protocol) {
1147
+ [protocol quec_refreshHomePageDeviceList];
1148
+ }
1149
+
1150
+ /// 业务面板重置设备后配网异常退出拦截-并刷新业务面板首页
1151
+ id<QuecBusinessPanelProtocol> bussinesPanelprotocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecBusinessPanelProtocol)];
1152
+ if (bussinesPanelprotocol) {
1153
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUnbindDeviceSuccessed" object:self.deviceModel userInfo:self.deviceModel.yy_modelToJSONObject ? : @{}];
1154
+ }
1155
+ if ([NSStringFromClass(quec_TopViewController().class) containsString:@"BleListViewController"]) {
1156
+ return;
1157
+ }
1158
+ quec_delay_on_main(1, ^{
1159
+ [quec_TopViewController() quec_goBackToFirstPage:true];
1160
+ });
1161
+ }
1162
+ }
1163
+
1164
+ - (void)device:(QuecDeviceClient *)device dpsUpdate:(QuecIotDataPointsModel *)dps {
1165
+ if (!self.hasListeners) {
1166
+ return;
1167
+ }
1168
+ QuecLogInfo(@"[iot][rn]dps:%@", dps);
1169
+ if ([self.subDeviecDict.allKeys containsObject:device.deviceId]) {
1170
+ if (dps.action == QuecIotDataPointActionTransparent_Report) {
1171
+ NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithDictionary:[dps yy_modelToJSONObject]];
1172
+ [tempDict quec_safeSetObject:[dps.transparentData quec_base64String] forKey:@"transparent"];
1173
+ [self sendEvent_onDeviceDpsUpdate:tempDict.copy];
1174
+ }else{
1175
+ if (dps.action == QuecIotDataPointActionENDUSER_Device_Verifyed) {
1176
+ id<QuecBusinessPanelProtocol> businessprotocol = quec_service(@protocol(QuecBusinessPanelProtocol));
1177
+ if (businessprotocol && [businessprotocol respondsToSelector:@selector(updateDeviceInfoAfterVerifiedWithProductKey:devicekey:)]) {
1178
+ [businessprotocol updateDeviceInfoAfterVerifiedWithProductKey:dps.pk devicekey:dps.dk];
1179
+ }
1180
+ }
1181
+ [self sendEvent_onDeviceDpsUpdate:[dps yy_modelToJSONObject]];
1182
+ }
1183
+
1184
+
1185
+ }
1186
+ }
1187
+
1188
+ - (void)device:(QuecDeviceClient *)device connectingStateUpdate:(NSUInteger)connectingState {
1189
+ if (!self.hasListeners) {
1190
+ return;
1191
+ }
1192
+ QuecLogInfo(@"[iot][%@][rn]connectingStateUpdate:%@", device.deviceId, @(connectingState));
1193
+ if ([self.subDeviecDict.allKeys containsObject:device.deviceId] && [device.model isKindOfClass:QuecDeviceModel.class]) {
1194
+ NSMutableDictionary *data = @{}.mutableCopy;
1195
+ [data quec_safeSetObject:@(connectingState) forKey:@"connectingState"];
1196
+ [data quec_safeSetObject:[device.model yy_modelToJSONString] ? : @"" forKey:@"device"];
1197
+ [self sendEvent_onDeviceConnectingState:data];
1198
+ }
1199
+ }
1200
+
1201
+
1202
+ - (void)impl_getDeviceOnlineState:(NSString*)pk dk:(NSString*)dk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1203
+ NSString *deviceId = quec_deviceId(pk, dk);
1204
+ QuecDeviceClient *client = [QuecDeviceClient deviceWithId:deviceId];
1205
+ QuecLogInfo(@"[iot][%@][rn]impl_getDeviceOnlineState: %ld", deviceId, client.connectedState);
1206
+ resolve(@{@"onlineState": @(client.connectedState)});
1207
+ }
1208
+
1209
+
1210
+ - (void)impl_deviceAssociationWithList:(NSArray*)list master:(NSDictionary*)master fid:(NSString*)fid resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1211
+ NSMutableArray<QuecDeviceModel *> *deviceList = [NSMutableArray array];
1212
+ for (NSDictionary *deviceDic in list) {
1213
+ QuecDeviceModel *model = [QuecDeviceModel yy_modelWithDictionary:deviceDic];
1214
+ [deviceList addObject:model];
1215
+ }
1216
+
1217
+ QuecDeviceModel *masterDevice = [QuecDeviceModel yy_modelWithDictionary:master];
1218
+ [QuecDeviceAssociationService.sharedInstance deviceAssociationWithList:deviceList master:masterDevice success:^{
1219
+ if (resolve) {
1220
+ resolve(@{@"data": @(1)});
1221
+ }
1222
+ } failure:^(NSError *error) {
1223
+ if (reject) {
1224
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1225
+ }
1226
+ }];
1227
+ }
1228
+
1229
+
1230
+ - (void)impl_deviceAssociation:(NSDictionary*)master fid:(NSString*)fid codelist:(NSString*)codelist resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1231
+ QuecDeviceModel *masterDevice = [QuecDeviceModel yy_modelWithDictionary:master];
1232
+ [QuecDeviceAssociationService.sharedInstance getDeviceAssociationInfoWithMaster:masterDevice code:codelist success:^(QuecDeviceAssociationModel * _Nonnull model) {
1233
+ if (resolve) {
1234
+ resolve(@{@"data": model.yy_modelToJSONObject ?: @{}});
1235
+ }
1236
+ } failure:^(NSError *error) {
1237
+ if (reject) {
1238
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1239
+ }
1240
+ }];
1241
+ }
1242
+
1243
+
1244
+ - (void)impl_deviceDisassociation:(NSDictionary*)device fid:(NSString*)fid resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1245
+ QuecDeviceModel *theDevice = [QuecDeviceModel yy_modelWithDictionary:device];
1246
+ [QuecDeviceAssociationService.sharedInstance deviceDisassociationWithDevice:theDevice success:^{
1247
+ if (resolve) {
1248
+ resolve(@{@"data": @(1)});
1249
+ }
1250
+ } failure:^(NSError *error) {
1251
+ if (reject) {
1252
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1253
+ }
1254
+ }];
1255
+ }
1256
+
1257
+
1258
+ - (void)impl_deviceAssociationConfig:(NSString*)pk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1259
+ [QuecDeviceAssociationService.sharedInstance deviceAssociationConfigWithProductKey:pk success:^(QuecDeviceAssociationConfig * _Nonnull config) {
1260
+ if (resolve) {
1261
+ resolve(@{@"data": config.yy_modelToJSONObject ?: @{}});
1262
+ }
1263
+ } failure:^(NSError *error) {
1264
+ if (reject) {
1265
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1266
+ }
1267
+ }];
1268
+ }
1269
+
1270
+ - (void)quecDeviceConnectDidSelected:(NSNotification *)notification {
1271
+ if (!self.hasListeners) {
1272
+ return;
1273
+ }
1274
+ NSArray *devices = [notification.object yy_modelToJSONObject];
1275
+ [self sendEvent_deviceAssociationSelected:@{@"list": devices}];
1276
+ }
1277
+
1278
+ - (void)impl_setOfflineReminder:(NSInteger)enableOfflineReminder productKey:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1279
+ [[QuecDeviceService sharedInstance] setOfflineReminderWithProductKey:productKey deviceKey:deviceKey enableOfflineReminder:(int)enableOfflineReminder success:^{
1280
+ resolve(@{@"data": @{}});
1281
+ } failure:^(NSError *error) {
1282
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1283
+ }];
1284
+ }
1285
+
1286
+ - (void)impl_getOfflineReminderInfo:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1287
+ [[QuecDeviceService sharedInstance] getOfflineReminderWithProductKey:productKey deviceKey:deviceKey success:^(int enableOfflineReminder) {
1288
+ resolve(@{@"data": @(enableOfflineReminder)});
1289
+ } failure:^(NSError *error) {
1290
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1291
+ }];
1292
+ }
1293
+
1294
+ - (void)impl_checkDeviceUpdatePlan:(NSDictionary*)device resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1295
+ QuecDeviceModel *masterDevice = [QuecDeviceModel yy_modelWithDictionary:device];
1296
+ if (![masterDevice.productKey quec_isStringAndNotEmpty] || ![masterDevice.deviceKey quec_isStringAndNotEmpty]) {
1297
+ reject(@"-9999", @"There is no upgrade plan", nil);
1298
+ return;
1299
+ }
1300
+ id<QuecFamilyModuleProtocol> family = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecFamilyModuleProtocol)];
1301
+ if (family && [family quec_fetchFamilyRole] == 3) {
1302
+ reject(@"-9999", @"There is no upgrade plan", nil);
1303
+ return;
1304
+ }
1305
+ [QuecOTAManager.sharedInstance checkVersionWithProductKey:masterDevice.productKey deviceKey:masterDevice.deviceKey planBlock:^(QuecOtaPlanInfoModel * _Nonnull planInfo) {
1306
+ if ([planInfo isKindOfClass:QuecOtaPlanInfoModel.class]) {
1307
+ resolve(@{@"data": @(true)});
1308
+ }else{
1309
+ reject(@"-9999", @"There is no upgrade plan", nil);
1310
+ }
1311
+ }];
1312
+ }
1313
+
1314
+ - (void)impl_openDeviceOTAPage:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1315
+ id<QuecDeviceOTAProtocol> otaProtocol = quec_service(@protocol(QuecDeviceOTAProtocol));
1316
+ /// self.deviceModel.onlineStatus == 1 &&
1317
+ if (otaProtocol && [otaProtocol respondsToSelector:@selector(openDeviceOTAPageWithProductKey:deviceKey:backAction:)]) {
1318
+ [otaProtocol openDeviceOTAPageWithProductKey:productKey deviceKey:deviceKey backAction:^{
1319
+ resolve(@{@"data": @(1)});
1320
+ }];
1321
+ return;
1322
+ }
1323
+ }
1324
+
1325
+ - (void)impl_getTimeDifferenceWithGMT:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1326
+ NSString *timeZone = quec_TimeDifferenceWithGMT(quec_LocalTimeZoneName());
1327
+ resolve(@{@"data": timeZone});
1328
+ }
1329
+
1330
+ - (void)impl_getDeviceTimeZone:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1331
+ [QuecDeviceService.sharedInstance getDeviceTimeZoneWithProductKey:productKey deviceKey:deviceKey success:^(QuecDeviceTimeZoneModel *model) {
1332
+ if (resolve) {
1333
+ resolve(@{@"data": [model.timeZone isKindOfClass:NSString.class] ? model.timeZone : @""});
1334
+ }
1335
+ } failure:^(NSError *error) {
1336
+ if (reject) {
1337
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1338
+ }
1339
+ }];
1340
+ }
1341
+
1342
+ - (void)impl_setDeviceTimeZone:(NSString*)productKey deviceKey:(NSString*)deviceKey timezone:(NSString*)timezone resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1343
+ NSString *timeZoneId = quec_LocalTimeZoneName();
1344
+ [[QuecDeviceService sharedInstance] setDeviceTimeZoneWithProductKey:productKey deviceKey:deviceKey timeZone:timezone timeZoneId:timeZoneId success:^{
1345
+ resolve(@{@"data": @(1)});
1346
+ } failure:^(NSError *error) {
1347
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1348
+ }];
1349
+ }
1350
+
1351
+ - (void)impl_getDeviceStateInfo:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1352
+ __weak __typeof(self)weakSelf = self;
1353
+ [self.device readDeviceStatusWithResult:^(QuecIotDeviceStatusModel * _Nonnull statusModel) {
1354
+ NSLog(@"deviceStateInfo ===> %@", [statusModel yy_modelToJSONObject]);
1355
+ if (!weakSelf.hasListeners) {
1356
+ return;
1357
+ }
1358
+ if ([weakSelf.subDeviecDict.allKeys containsObject:weakSelf.device.deviceId]) {
1359
+ [weakSelf sendEvent_onDeviceStatusUpdate:[statusModel yy_modelToJSONObject]];
1360
+ }
1361
+
1362
+ } failure:^(NSError * _Nonnull error) {
1363
+ NSLog(@"deviceStateInfo error ===> %@", error.localizedDescription);
1364
+ }];
1365
+ }
1366
+
1367
+ - (void)impl_jumpDeviceWiFiListPage:(NSString*)productKey deviceKey:(NSString*)deviceKey oldSsid:(NSString*)oldSsid signal_strength:(NSString*)signal_strength supportOnlineWiFiScan:(BOOL)supportOnlineWiFiScan resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1368
+ id<QuecWiFiSwitchProtocol> protocol = quec_service(@protocol(QuecWiFiSwitchProtocol));
1369
+ if (!protocol) {
1370
+ return;
1371
+ }
1372
+ [protocol jumpWifiListWith:productKey deviceKey:deviceKey oldSsid:oldSsid signal_strength:signal_strength supportOnlineWiFiScan:supportOnlineWiFiScan];
1373
+ }
1374
+
1375
+ - (void)impl_getProductDescription:(NSString *)productKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1376
+ [QuecDeviceService.sharedInstance getProductDescriptionWithProductKey:productKey success:^(NSString *url) {
1377
+ if (resolve) {
1378
+ resolve(@{@"data": @{@"url" : url?:@""}});
1379
+ }
1380
+ } failure:^(NSError *error) {
1381
+ if (reject) {
1382
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1383
+ }
1384
+ }];
1385
+ }
1386
+
1387
+ - (void)impl_getFamilyDeviceList:(NSInteger)pageNumber pageSize:(NSInteger)pageSize resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1388
+ id<QuecFamilyModuleProtocol> protocol = quec_service(@protocol(QuecFamilyModuleProtocol));
1389
+ if (!protocol) {
1390
+ reject(@"-10009", @"QuecSmartHomeKit has be remove", nil);
1391
+ return;
1392
+ }
1393
+ [protocol getFamilyDeviceListWithPageNumber:pageNumber pageSize:pageSize success:^(NSArray<QuecDeviceModel *> * _Nonnull list, NSInteger total) {
1394
+ resolve(@{@"data": @{@"list":list.yy_modelToJSONObject, @"total":@(total)}});
1395
+ } failure:^(NSError * _Nonnull error) {
1396
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1397
+ }];
1398
+ }
1399
+
1400
+ - (void)impl_timeZoneSync:(NSString *)productKey deviceKey:(NSString *)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1401
+ [self.device timeZoneSync];
1402
+ }
1403
+
1404
+ - (void)impl_unbindlingPureBtDevice:(NSString *)productKey deviceKey:(NSString *)deviceKey isInit:(BOOL)isInit random:(NSString *)random pureBtResetCredentials:(NSString *)pureBtResetCredentials resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1405
+ self.unbindingDevice = YES;
1406
+ __weak __typeof(self)weakSelf = self;
1407
+ [self.device removeBtWithIsInit:isInit random:random resetCredentials:pureBtResetCredentials success:^{
1408
+ resolve(@{@"data": @{}});
1409
+ quec_delay_on_main(1.f, ^{
1410
+ weakSelf.unbindingDevice = NO;
1411
+ [quec_TopViewController() quec_goBackToFirstPage:true];
1412
+ });
1413
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"kQuecUnbindDeviceSuccessed" object:nil userInfo:@{@"productKey":productKey?:@"unknown", @"deviceKey":deviceKey?:@"unknown"}];
1414
+ } failure:^(NSError * _Nonnull error) {
1415
+ weakSelf.unbindingDevice = NO;
1416
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1417
+ }];
1418
+ }
1419
+
1420
+
1421
+ - (void)impl_getTsl:(NSString*)productKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1422
+ [QuecDeviceService.sharedInstance getProductTSLWithProductKey:productKey success:^(QuecProductTSLModel *tslModel) {
1423
+ if (resolve) {
1424
+ resolve(@{@"data": tslModel.properties.yy_modelToJSONObject ? : @[]});
1425
+ }
1426
+ } failure:^(NSError *error) {
1427
+ if (reject) {
1428
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1429
+ }
1430
+ }];
1431
+ }
1432
+
1433
+ - (void)impl_startVerifyDevice:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1434
+ id<QuecSmartConfigProtocol> protocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecSmartConfigProtocol)];
1435
+ if (protocol && [protocol respondsToSelector:@selector(quec_startVerifyWithDeviceModel:result:)]) {
1436
+ [protocol quec_startVerifyWithDeviceModel:self.deviceModel result:^(BOOL isVerify, NSError *error) {
1437
+ if (isVerify) {
1438
+ id<QuecHomePageModuleProtocol> homePageProtocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecHomePageModuleProtocol)];
1439
+ if (homePageProtocol) {
1440
+ quec_async_on_main(^{
1441
+ [homePageProtocol quec_refreshHomePageDeviceList];
1442
+ });
1443
+ }
1444
+ resolve(@{@"data": @(true)});
1445
+ }else{
1446
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1447
+ }
1448
+ }];
1449
+ }
1450
+ }
1451
+
1452
+ - (void)impl_startNetConfigDevice:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject{
1453
+ id<QuecSmartConfigProtocol> protocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecSmartConfigProtocol)];
1454
+ if (protocol && [protocol respondsToSelector:@selector(quec_startNetConfigWithDeviceModel:result:)]) {
1455
+ [protocol quec_startNetConfigWithDeviceModel:self.deviceModel result:^(BOOL isVerify, NSError *error) {
1456
+ if (isVerify) {
1457
+ id<QuecHomePageModuleProtocol> homePageProtocol = [[QuecModuleServiceManager oneInstance] serviceOfProtocol:@protocol(QuecHomePageModuleProtocol)];
1458
+ if (homePageProtocol) {
1459
+ quec_async_on_main(^{
1460
+ [homePageProtocol quec_refreshHomePageDeviceList];
1461
+ });
1462
+ }
1463
+ resolve(@(isVerify));
1464
+ }else{
1465
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1466
+ }
1467
+ }];
1468
+ }
1469
+ }
1470
+
1471
+ - (void)impl_getSharePermList:(NSArray*)shareCodeList resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1472
+
1473
+ [QuecDeviceShareService.sharedInstance getSharePermList:shareCodeList success:^(NSArray<QuecSharePermModel *> * _Nonnull permList) {
1474
+ if (resolve) {
1475
+ resolve(@{@"data": permList.yy_modelToJSONObject});
1476
+ }
1477
+ } failure:^(NSError *error) {
1478
+ if (reject) {
1479
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1480
+ }
1481
+ }];
1482
+
1483
+ }
1484
+
1485
+ - (void)impl_uploadDeviceHistoricalData:(NSString*)productKey deviceKey:(NSString*)deviceKey resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1486
+ [QuecDeviceDataUploadManager.sharedInstance uploadDeviceHistoricalDataWithPk:productKey dk:deviceKey callback:^(BOOL result, NSError * _Nonnull error) {
1487
+ if (result) {
1488
+ if (resolve) {
1489
+ resolve(@{@"data": @(YES)});
1490
+ }
1491
+ } else{
1492
+ if (reject) {
1493
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1494
+ }
1495
+ }
1496
+ }];
1497
+ }
1498
+
1499
+ - (void)impl_getVoiceSupport:(NSString *)productKey uid:(NSString *)uid account:(NSString *)account resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
1500
+
1501
+
1502
+ BOOL isSupportAlexa = QuecOemAppConfig.sharedInstance.business.isSupportAlexa ;
1503
+ BOOL isSupportGoogleAssistant = QuecOemAppConfig.sharedInstance.business.isSupportGoogleAssistant ;
1504
+ if (!isSupportAlexa && !isSupportGoogleAssistant) {
1505
+ if (resolve) {
1506
+ resolve(@{@"supportAlexa":@(NO), @"supportAssistant": @(NO)});
1507
+ }
1508
+ return;
1509
+ }
1510
+ [QuecDeviceService.sharedInstance getVoiceSupportWithProductKey:productKey uid:uid account:account success:^(BOOL isSupportAlexa, BOOL isSupportAssistant) {
1511
+
1512
+ if (resolve) {
1513
+ resolve(@{@"supportAlexa":@(isSupportAlexa), @"supportAssistant": @(isSupportAssistant)});
1514
+ }
1515
+
1516
+ } failure:^(NSError *error) {
1517
+
1518
+ if (reject) {
1519
+ reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
1520
+ }
1521
+ }];
1522
+ }
1523
+ @end
1524
+