@quec/panel-device-kit 1.0.4

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 (77) hide show
  1. package/README.md +253 -0
  2. package/dist/index.cjs +1426 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +1352 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/src/API/TimeApi.d.ts +1 -0
  9. package/dist/src/API/TimeApi.d.ts.map +1 -0
  10. package/dist/src/API/associationApi.d.ts +1 -0
  11. package/dist/src/API/associationApi.d.ts.map +1 -0
  12. package/dist/src/API/deviceApi.d.ts +62 -0
  13. package/dist/src/API/deviceApi.d.ts.map +1 -0
  14. package/dist/src/API/index.d.ts +7 -0
  15. package/dist/src/API/index.d.ts.map +1 -0
  16. package/dist/src/API/offlineReminder.d.ts +29 -0
  17. package/dist/src/API/offlineReminder.d.ts.map +1 -0
  18. package/dist/src/API/otaPlan.d.ts +26 -0
  19. package/dist/src/API/otaPlan.d.ts.map +1 -0
  20. package/dist/src/API/productManual.d.ts +11 -0
  21. package/dist/src/API/productManual.d.ts.map +1 -0
  22. package/dist/src/API/timeZone.d.ts +54 -0
  23. package/dist/src/API/timeZone.d.ts.map +1 -0
  24. package/dist/src/API/unbindDevice.d.ts +51 -0
  25. package/dist/src/API/unbindDevice.d.ts.map +1 -0
  26. package/dist/src/DeviceKitParamsManager.d.ts +43 -0
  27. package/dist/src/DeviceKitParamsManager.d.ts.map +1 -0
  28. package/dist/src/SDK/getDeviceOnlineState.d.ts +9 -0
  29. package/dist/src/SDK/getDeviceOnlineState.d.ts.map +1 -0
  30. package/dist/src/SDK/getPropertyDataListWithParams.d.ts +11 -0
  31. package/dist/src/SDK/getPropertyDataListWithParams.d.ts.map +1 -0
  32. package/dist/src/SDK/subscriDevice.d.ts +9 -0
  33. package/dist/src/SDK/subscriDevice.d.ts.map +1 -0
  34. package/dist/src/config/DeviceConfig.d.ts +44 -0
  35. package/dist/src/config/DeviceConfig.d.ts.map +1 -0
  36. package/dist/src/device-list-utils.d.ts +28 -0
  37. package/dist/src/device-list-utils.d.ts.map +1 -0
  38. package/dist/src/deviceListStore.d.ts +135 -0
  39. package/dist/src/deviceListStore.d.ts.map +1 -0
  40. package/dist/src/deviceStore.d.ts +312 -0
  41. package/dist/src/deviceStore.d.ts.map +1 -0
  42. package/dist/src/i18n/i18n.d.ts +2 -0
  43. package/dist/src/i18n/i18n.d.ts.map +1 -0
  44. package/dist/src/i18n/locales/zh.d.ts +7 -0
  45. package/dist/src/i18n/locales/zh.d.ts.map +1 -0
  46. package/dist/src/initDeviceListUpdate.d.ts +27 -0
  47. package/dist/src/initDeviceListUpdate.d.ts.map +1 -0
  48. package/dist/src/initDeviceOnlineEvent.d.ts +24 -0
  49. package/dist/src/initDeviceOnlineEvent.d.ts.map +1 -0
  50. package/dist/src/initDeviceRefreshEvent.d.ts +15 -0
  51. package/dist/src/initDeviceRefreshEvent.d.ts.map +1 -0
  52. package/dist/src/types/Error.d.ts +12 -0
  53. package/dist/src/types/Error.d.ts.map +1 -0
  54. package/dist/src/types/common.type.d.ts +2 -0
  55. package/dist/src/types/common.type.d.ts.map +1 -0
  56. package/dist/src/types/deviceModel.d.ts +84 -0
  57. package/dist/src/types/deviceModel.d.ts.map +1 -0
  58. package/dist/src/types/dps.type.d.ts +125 -0
  59. package/dist/src/types/dps.type.d.ts.map +1 -0
  60. package/dist/src/types/familyModel.d.ts +5 -0
  61. package/dist/src/types/familyModel.d.ts.map +1 -0
  62. package/dist/src/types/index.d.ts +4 -0
  63. package/dist/src/types/index.d.ts.map +1 -0
  64. package/dist/src/types/propsModel.d.ts +27 -0
  65. package/dist/src/types/propsModel.d.ts.map +1 -0
  66. package/dist/src/utils/empty.d.ts +2 -0
  67. package/dist/src/utils/empty.d.ts.map +1 -0
  68. package/dist/src/utils/numberUtils.d.ts +9 -0
  69. package/dist/src/utils/numberUtils.d.ts.map +1 -0
  70. package/dist/src/utils/stringUtils.d.ts +3 -0
  71. package/dist/src/utils/stringUtils.d.ts.map +1 -0
  72. package/dist/src/utils/to.d.ts +8 -0
  73. package/dist/src/utils/to.d.ts.map +1 -0
  74. package/dist/tsconfig.tsbuildinfo +1 -0
  75. package/dist/tsup.config.d.ts +3 -0
  76. package/dist/tsup.config.d.ts.map +1 -0
  77. package/package.json +60 -0
package/dist/index.js ADDED
@@ -0,0 +1,1352 @@
1
+ import QuecRNLogModule from '@quec/rn-log-module/src/module';
2
+ import QuecRNDeviceModule5 from '@quec/rn-device-module/src/module';
3
+ import camelCase from 'lodash.camelcase';
4
+ import { create } from 'zustand';
5
+ import { useEffect, useState } from 'react';
6
+ import { NativeEventEmitter, NativeModules } from 'react-native';
7
+
8
+ // src/config/DeviceConfig.ts
9
+ var NOT_CONNECTING = 0;
10
+ var DEVICE_TYPE_BIND = 1;
11
+ var DEVICE_TYPE_SHARE = 2;
12
+ var DEVICE_ACCESS_TYPE_DIRECTLY = 0;
13
+ var DEVICE_ACCESS_TYPE_GATEWAY = 1;
14
+ var DEVICE_ACCESS_TYPE_GATEWAY_CHILD = 2;
15
+ var DEVICE_NAME_MAX_LENGTH = 14;
16
+ var onlineStatus = /* @__PURE__ */ ((onlineStatus2) => {
17
+ onlineStatus2[onlineStatus2["ALL_OFFLINE"] = 0] = "ALL_OFFLINE";
18
+ onlineStatus2[onlineStatus2["WS_ONLINE"] = 1] = "WS_ONLINE";
19
+ onlineStatus2[onlineStatus2["WIFI_ONLINE"] = 2] = "WIFI_ONLINE";
20
+ onlineStatus2[onlineStatus2["WS_WIFI_ONLINE"] = 3] = "WS_WIFI_ONLINE";
21
+ onlineStatus2[onlineStatus2["BLE_ONLINE"] = 4] = "BLE_ONLINE";
22
+ onlineStatus2[onlineStatus2["WS_BLE_ONLINE"] = 5] = "WS_BLE_ONLINE";
23
+ onlineStatus2[onlineStatus2["WIFI_BLE_ONLINE"] = 6] = "WIFI_BLE_ONLINE";
24
+ onlineStatus2[onlineStatus2["ALL_ONLINE"] = 7] = "ALL_ONLINE";
25
+ return onlineStatus2;
26
+ })(onlineStatus || {});
27
+ var LOADING_SEND_TIMEOUT = 6e4;
28
+ var BASE_TAG = "\u{1F4AB} Quec_Device_Kit ";
29
+ var _DeviceKitParamsManager = class _DeviceKitParamsManager {
30
+ /** 是否使用内部管理器 */
31
+ static setTSLStore() {
32
+ }
33
+ /** 注册回调 */
34
+ registerCallbacks({
35
+ loadingCallback,
36
+ loadingDismissCallback,
37
+ tipCallback
38
+ }) {
39
+ if (loadingCallback) _DeviceKitParamsManager.loadingCallback = loadingCallback;
40
+ if (loadingDismissCallback)
41
+ _DeviceKitParamsManager.loadingDismissCallback = loadingDismissCallback;
42
+ if (tipCallback) _DeviceKitParamsManager.tipCallback = tipCallback;
43
+ }
44
+ /** 触发 Loading */
45
+ loading() {
46
+ _DeviceKitParamsManager.loadingCallback?.();
47
+ }
48
+ /** 关闭 Loading */
49
+ loadingDismiss() {
50
+ _DeviceKitParamsManager.loadingDismissCallback?.();
51
+ }
52
+ /** 触发提示 */
53
+ tip(message) {
54
+ _DeviceKitParamsManager.tipCallback?.(message);
55
+ }
56
+ setAutoConnectCurrentDevice(autoConnectCurrentDevice) {
57
+ _DeviceKitParamsManager.autoConnectCurrentDevice = autoConnectCurrentDevice;
58
+ }
59
+ getAutoConnectCurrentDevice() {
60
+ return _DeviceKitParamsManager.autoConnectCurrentDevice === true;
61
+ }
62
+ /** 设置外部日志模块 */
63
+ static setLogger(logModule) {
64
+ this.logModule = logModule;
65
+ }
66
+ /** 自动关闭所有 console 输出(仅限生产环境) */
67
+ static autoDisableLog() {
68
+ const isProduction = !__DEV__;
69
+ if (isProduction) {
70
+ const noop = () => {
71
+ };
72
+ console.log = noop;
73
+ console.info = noop;
74
+ console.warn = noop;
75
+ console.error = noop;
76
+ console.debug = noop;
77
+ console.trace = noop;
78
+ }
79
+ }
80
+ /** 通用日志方法 */
81
+ log(level, tag, message) {
82
+ if (typeof message === "object") {
83
+ message = JSON.stringify(message);
84
+ }
85
+ if (_DeviceKitParamsManager.logModule) {
86
+ _DeviceKitParamsManager.logModule[level](BASE_TAG + tag, "" + message);
87
+ }
88
+ console.log(`${BASE_TAG}${tag} ${level} ==> ${"" + message}`);
89
+ }
90
+ /** info日志方法 */
91
+ info(tag, message) {
92
+ this.log("i", tag, message);
93
+ }
94
+ /** err日志方法 */
95
+ error(tag, message) {
96
+ this.log("e", tag, message);
97
+ }
98
+ };
99
+ _DeviceKitParamsManager.useInternalStore = true;
100
+ // 是否使用内部 store,默认 true
101
+ _DeviceKitParamsManager.loadingCallback = null;
102
+ _DeviceKitParamsManager.loadingDismissCallback = null;
103
+ _DeviceKitParamsManager.tipCallback = null;
104
+ _DeviceKitParamsManager.logModule = QuecRNLogModule;
105
+ var DeviceKitParamsManager = _DeviceKitParamsManager;
106
+ var deviceKitParamsManager = new DeviceKitParamsManager();
107
+
108
+ // src/utils/to.ts
109
+ async function to(promise, errorExt) {
110
+ return promise.then((data) => [null, data]).catch((err) => {
111
+ if (errorExt) {
112
+ const parsedError = Object.assign({}, err, errorExt);
113
+ return [parsedError, void 0];
114
+ }
115
+ return [err, void 0];
116
+ });
117
+ }
118
+ var to_default = to;
119
+
120
+ // src/SDK/getDeviceOnlineState.ts
121
+ var getDeviceOnline = async ({
122
+ pk,
123
+ dk
124
+ }) => {
125
+ const [err, res] = await to_default(
126
+ QuecRNDeviceModule5.getDeviceOnlineState(pk, dk)
127
+ );
128
+ if (err) {
129
+ deviceKitParamsManager.error(
130
+ "\u274C \u2754 getDeviceOnlineState \u83B7\u53D6\u8BBE\u5907\u72B6\u6001\u5931\u8D25",
131
+ "error ==> " + err
132
+ );
133
+ return false;
134
+ }
135
+ if (res) {
136
+ deviceKitParamsManager.info(
137
+ " \u2705 \u2754 getDeviceOnlineState \u83B7\u53D6\u8BBE\u5907\u72B6\u6001\u6210\u529F",
138
+ "res ==> " + pk + "_" + dk + JSON.stringify(res)
139
+ );
140
+ if (Number(res.onlineState) !== 0) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ };
146
+ var getPropertyDataListWithParams = async (params) => {
147
+ const { productKey, deviceKey, codeList } = params;
148
+ deviceKitParamsManager.info(
149
+ "getPropertyDataListWithParams",
150
+ "===\u83B7\u53D6\u8BBE\u5907\u5C5E\u6027\u4FE1\u606F:" + productKey + "_" + deviceKey
151
+ );
152
+ const [err, res] = await to_default(
153
+ QuecRNDeviceModule5.getDeviceBusinessAttributesWithProductKey({
154
+ ...params,
155
+ codeList: codeList.join(","),
156
+ type: "2"
157
+ })
158
+ );
159
+ if (err) {
160
+ deviceKitParamsManager.error("getDeviceList", "error ==> " + err);
161
+ deviceKitParamsManager.loadingDismiss();
162
+ if (err.code && err.code.length > 0) {
163
+ deviceKitParamsManager.tip(err.message);
164
+ }
165
+ return;
166
+ }
167
+ if (res && res.data && Array.isArray(res.data?.customizeTslInfo) && res.data?.customizeTslInfo?.length > 0) {
168
+ deviceKitParamsManager.info(
169
+ "\u83B7\u53D6\u8BBE\u5907\u5C5E\u6027\u4FE1\u606F",
170
+ productKey + "_" + deviceKey + "===>" + JSON.stringify(res)
171
+ );
172
+ let propertyValueArr = {};
173
+ codeList.forEach((code) => {
174
+ const findRes = res.data.customizeTslInfo?.find(
175
+ (item) => item.resourceCode === code
176
+ );
177
+ propertyValueArr[code] = findRes?.resourceValce;
178
+ propertyValueArr[code + "Id"] = findRes?.abId;
179
+ });
180
+ return propertyValueArr;
181
+ }
182
+ };
183
+
184
+ // src/utils/stringUtils.ts
185
+ var strToObj = (str) => {
186
+ if (typeof str === "object" && str !== null) {
187
+ return str;
188
+ }
189
+ if (typeof str === "string" && str.trim() !== "") {
190
+ try {
191
+ const res = JSON.parse(str);
192
+ if (typeof res === "object" && res !== null) {
193
+ return res;
194
+ }
195
+ } catch (error) {
196
+ deviceKitParamsManager.error("strToObj", error);
197
+ }
198
+ }
199
+ return {};
200
+ };
201
+ var getCircularReplacer = () => {
202
+ const seen = /* @__PURE__ */ new WeakSet();
203
+ return (_key, value) => {
204
+ if (typeof value === "object" && value !== null) {
205
+ if (seen.has(value)) {
206
+ return "[Circular]";
207
+ }
208
+ seen.add(value);
209
+ }
210
+ return value;
211
+ };
212
+ };
213
+ var objToStr = (obj) => {
214
+ if (obj instanceof Error) {
215
+ return obj.stack || obj.message || "Unknown Error";
216
+ }
217
+ if (typeof obj === "object") {
218
+ try {
219
+ return JSON.stringify(obj, getCircularReplacer(), 2);
220
+ } catch (e) {
221
+ return "[Cannot stringify object]";
222
+ }
223
+ }
224
+ if (typeof obj === "undefined") {
225
+ return "undefined";
226
+ }
227
+ if (obj === null) {
228
+ return "null";
229
+ }
230
+ return String(obj);
231
+ };
232
+
233
+ // src/SDK/subscriDevice.ts
234
+ var subscribeDevice = (pk, dk) => {
235
+ try {
236
+ QuecRNDeviceModule5.subscribeDevice(pk, dk);
237
+ deviceKitParamsManager.info(
238
+ "\u2705 \u{1F91D} subscribeDevice \u6210\u529F\u8BA2\u9605\u8BBE\u5907",
239
+ "pk_dk===>" + pk + "_" + dk
240
+ );
241
+ } catch (error) {
242
+ deviceKitParamsManager.error(
243
+ "\u274C \u{1F91D} subscribeDevice \u8BA2\u9605\u8BBE\u5907\u5931\u8D25",
244
+ "pk_dk===>" + pk + "_" + dk + " ===> \u5931\u8D25\u539F\u56E0\uFF1A" + objToStr(error)
245
+ );
246
+ }
247
+ };
248
+
249
+ // src/deviceListStore.ts
250
+ var DEFAULT_PAGE_NUM = 1;
251
+ var DEFAULT_PAGE_SIZE = 15;
252
+ var initialState = {
253
+ deviceList: [],
254
+ total: null,
255
+ networkError: false,
256
+ listIsEmpty: false,
257
+ deviceListPlus: [],
258
+ //提供给自己想要简化device的数据的开发
259
+ subscribeDevicesList: [],
260
+ pageNum: DEFAULT_PAGE_NUM,
261
+ pageSize: DEFAULT_PAGE_SIZE,
262
+ canLoadMore: false
263
+ };
264
+ var deviceListStore = null;
265
+ var createDeviceListStore = (params) => {
266
+ const {
267
+ pageSize = DEFAULT_PAGE_SIZE,
268
+ processDeviceList,
269
+ isSubScribeAllDevice = false,
270
+ subscribeCodeList
271
+ } = params || {};
272
+ if (pageSize <= 1 || !Number.isInteger(pageSize)) {
273
+ throw new Error("\u274C pageSize\u8981\u6C42\u662F\u6B63\u6574\u6570\u4E14\u5927\u4E8E\u7B49\u4E8E1");
274
+ } else {
275
+ DEFAULT_PAGE_SIZE = pageSize;
276
+ }
277
+ if (!deviceListStore) {
278
+ deviceListStore = create((set, get) => ({
279
+ ...initialState,
280
+ // 刷新设备列表
281
+ refreshDeviceList(successCallback, failCallback) {
282
+ let deviceList = [];
283
+ set({
284
+ deviceList,
285
+ pageNum: 1,
286
+ canLoadMore: false
287
+ });
288
+ get().getDeviceList(
289
+ 1,
290
+ get().pageSize,
291
+ (list, canLoadMore) => {
292
+ successCallback && successCallback(list);
293
+ },
294
+ failCallback
295
+ );
296
+ },
297
+ // 加载更多设备列表
298
+ loadMoreDeviceList(successCallback, failCallback) {
299
+ if (get().canLoadMore) {
300
+ get().getDeviceList(
301
+ get().pageNum,
302
+ get().pageSize,
303
+ (list, canLoadMore) => {
304
+ successCallback && successCallback(list);
305
+ },
306
+ failCallback
307
+ );
308
+ }
309
+ },
310
+ // 请求设备列表
311
+ async getDeviceList(pageNum, paseSize, successCallback, failCallback) {
312
+ deviceKitParamsManager.loading();
313
+ const [err, res] = await to_default(
314
+ QuecRNDeviceModule5.getDeviceListWithPageNumber(pageNum, paseSize)
315
+ );
316
+ if (err) {
317
+ deviceKitParamsManager.error("\u274C getDeviceList", "\u83B7\u53D6\u8BBE\u5907\u5217\u8868error ==> " + err);
318
+ deviceKitParamsManager.loadingDismiss();
319
+ if (err.code && err.code.length > 0) {
320
+ deviceKitParamsManager.tip(err.message);
321
+ }
322
+ set({
323
+ networkError: true
324
+ });
325
+ failCallback && failCallback(err);
326
+ return;
327
+ }
328
+ let returnSuccessDeviceList = [];
329
+ if (res && res.data && res.data.list && Array.isArray(res.data?.list)) {
330
+ deviceKitParamsManager.info("getDeviceList", "res ==> " + objToStr(res));
331
+ const { data } = res;
332
+ const { list } = data;
333
+ set({ total: data.total });
334
+ if (pageNum === 1) {
335
+ await get().updateDeviceList(list);
336
+ returnSuccessDeviceList = list;
337
+ successCallback && successCallback(returnSuccessDeviceList, data.total > list.length);
338
+ if (deviceKitParamsManager.getAutoConnectCurrentDevice() && list.length > 0) {
339
+ deviceKitParamsManager.info("getDeviceList", "auto connect device");
340
+ QuecRNDeviceModule5.connectChannel(0);
341
+ }
342
+ set({
343
+ canLoadMore: data.total > list.length,
344
+ pageNum: data.total > list.length ? pageNum + 1 : 1
345
+ });
346
+ } else {
347
+ const nextListRes = list;
348
+ const preDevicesList = [...get().deviceList, ...nextListRes];
349
+ await get().updateDeviceList(preDevicesList);
350
+ returnSuccessDeviceList = list;
351
+ successCallback && successCallback(returnSuccessDeviceList, data.total > preDevicesList.length);
352
+ set({
353
+ canLoadMore: data.total > preDevicesList.length,
354
+ pageNum: data.total > preDevicesList.length ? pageNum + 1 : pageNum
355
+ });
356
+ }
357
+ } else {
358
+ deviceKitParamsManager.error("getDeviceList", "no res ==> " + objToStr(res));
359
+ failCallback && failCallback(null);
360
+ }
361
+ deviceKitParamsManager.loadingDismiss();
362
+ },
363
+ // 更新设备列表
364
+ async updateDeviceList(deviceList) {
365
+ set({
366
+ listIsEmpty: Array.isArray(deviceList) && deviceList.length === 0,
367
+ deviceList,
368
+ networkError: deviceList === void 0
369
+ });
370
+ if (!!processDeviceList && processDeviceList instanceof Function) {
371
+ await get().updateDeviceListPlus(deviceList);
372
+ }
373
+ },
374
+ // 处理更新的设备列表数据使其符合自己使用的习惯
375
+ async updateDeviceListPlus(devicesArr) {
376
+ const deviceListPlus = devicesArr.filter(
377
+ (item) => item.deviceKey !== void 0 && item.productKey !== void 0 && item.deviceKey !== null && item.productKey !== null
378
+ ).map((item) => processDeviceList(item));
379
+ if (!isSubScribeAllDevice) {
380
+ set({
381
+ deviceListPlus
382
+ });
383
+ return;
384
+ }
385
+ for (let i = 0; i < deviceListPlus.length; i++) {
386
+ const item = deviceListPlus[i];
387
+ get().addSubscribeDeviceList(item.productKey, item.deviceKey);
388
+ const isOnline = await getDeviceOnline({
389
+ pk: item.productKey,
390
+ dk: item.deviceKey
391
+ });
392
+ item.isOnline = isOnline;
393
+ if (!(subscribeCodeList && subscribeCodeList?.length > 0)) {
394
+ return;
395
+ }
396
+ const propertyData = await getPropertyDataListWithParams({
397
+ productKey: item.productKey,
398
+ deviceKey: item.deviceKey,
399
+ codeList: subscribeCodeList
400
+ });
401
+ for (let index = 0; index < subscribeCodeList.length; index++) {
402
+ const subscribeModelCode = subscribeCodeList[index];
403
+ if (propertyData && propertyData[subscribeModelCode]) {
404
+ deviceListPlus[i].subscribeModel[camelCase(subscribeModelCode)] = Number(
405
+ propertyData[subscribeModelCode]
406
+ );
407
+ deviceListPlus[i].subscribeModel[camelCase(subscribeModelCode) + "Id"] = Number(
408
+ propertyData[subscribeModelCode + "Id"]
409
+ );
410
+ }
411
+ }
412
+ }
413
+ set({
414
+ deviceListPlus
415
+ });
416
+ },
417
+ /**
418
+ * 更新列表中单个设备的在离线状态
419
+ * @param event
420
+ */
421
+ updateDeviceOnlineState(event) {
422
+ const deviceListPlus = [...get().deviceListPlus];
423
+ const eventDevice = typeof event?.device === "object" ? event?.device : JSON.parse(event?.device ?? "{}");
424
+ deviceListPlus.forEach((item) => {
425
+ if (item.deviceKey === eventDevice?.deviceKey && item.productKey === eventDevice?.productKey && event?.onlineState !== void 0 && !Number.isNaN(Number(event.onlineState))) {
426
+ item.isOnline = Number(event.onlineState) !== 0;
427
+ item.onlineState = Number(event.onlineState);
428
+ }
429
+ });
430
+ set({
431
+ deviceListPlus
432
+ });
433
+ },
434
+ /**
435
+ * 更新列表中单个设备的物模型
436
+ * @param deviceListPlus
437
+ */
438
+ updateDeviceDPSData(event) {
439
+ if (!isSubScribeAllDevice || !subscribeCodeList || subscribeCodeList?.length <= 0) {
440
+ return;
441
+ }
442
+ const { dps, dk, pk } = event;
443
+ if (dps === void 0 || dps === null || dk === void 0 || dk === null || pk === void 0 || pk === null) {
444
+ return;
445
+ } else {
446
+ const deviceListPlus = [...get().deviceListPlus];
447
+ deviceListPlus.forEach((device) => {
448
+ if (device.deviceKey === event.dk && device.productKey === event.pk) {
449
+ dps.map((item) => {
450
+ Object.entries(device.subscribeModel).forEach(([key, value]) => {
451
+ if (key.endsWith("Id")) {
452
+ const modelId = value;
453
+ if (modelId === item.id) {
454
+ device.subscribeModel[key] = item.value;
455
+ }
456
+ }
457
+ });
458
+ });
459
+ }
460
+ });
461
+ set({
462
+ deviceListPlus
463
+ });
464
+ }
465
+ },
466
+ /**
467
+ * 增加已订阅设备列表并订阅设备
468
+ * @param deviceList
469
+ */
470
+ addSubscribeDeviceList(pk, dk) {
471
+ const subscribeDevicesListCopy = [...get().subscribeDevicesList];
472
+ if (subscribeDevicesListCopy.find((item) => {
473
+ item.dk === dk && item.pk === pk;
474
+ }) === void 0) {
475
+ subscribeDevicesListCopy.push({ pk, dk });
476
+ subscribeDevice(pk, dk);
477
+ }
478
+ set({
479
+ subscribeDevicesList: subscribeDevicesListCopy
480
+ });
481
+ }
482
+ }));
483
+ }
484
+ return deviceListStore;
485
+ };
486
+ var getDeviceListStore = () => {
487
+ if (!deviceListStore) {
488
+ throw new Error("\u2757\u8BF7\u5148\u8C03\u7528 createDeviceListStore() \u521D\u59CB\u5316 Store");
489
+ }
490
+ return deviceListStore;
491
+ };
492
+ var getDeviceListStoreWithoutError = () => {
493
+ if (!deviceListStore) {
494
+ return null;
495
+ }
496
+ return deviceListStore;
497
+ };
498
+ var selectFromStore = (selector) => {
499
+ const store = getDeviceListStore();
500
+ return store(selector);
501
+ };
502
+ var useDeviceListStoreState = () => {
503
+ return selectFromStore((state) => state);
504
+ };
505
+ var useDeviceList = () => {
506
+ return selectFromStore((state) => state.deviceList);
507
+ };
508
+ var useDeviceListLoadMore = () => {
509
+ return selectFromStore((state) => state.loadMoreDeviceList);
510
+ };
511
+ var useDeviceListRefresh = () => {
512
+ return selectFromStore((state) => state.refreshDeviceList);
513
+ };
514
+ var getDeviceOnlineState = async ({
515
+ productKey,
516
+ deviceKey
517
+ }) => {
518
+ try {
519
+ const { onlineState } = await QuecRNDeviceModule5.getDeviceOnlineState(productKey, deviceKey);
520
+ deviceKitParamsManager.info(
521
+ "\u{1F50E}QuecRNDeviceModule.getDeviceOnlineState....",
522
+ "\u83B7\u53D6\u8BBE\u5907\u72B6\u6001 ===> onlineState:" + onlineState
523
+ );
524
+ return onlineState;
525
+ } catch (error) {
526
+ deviceKitParamsManager.error(
527
+ "\u274CQuecRNDeviceModule.getDeviceOnlineState(\u83B7\u53D6\u8BBE\u5907\u72B6\u6001\u5931\u8D25)",
528
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
529
+ );
530
+ return null;
531
+ }
532
+ };
533
+ var getDeviceConnectingState = async () => {
534
+ try {
535
+ const result = await QuecRNDeviceModule5.getDeviceConnectingState();
536
+ deviceKitParamsManager.info(
537
+ "\u{1F4F6} QuecRNDeviceModule.getDeviceConnectingState",
538
+ `\u5F53\u524D\u8FDE\u63A5\u72B6\u6001\uFF1A${result?.connectingState}`
539
+ );
540
+ return result?.connectingState;
541
+ } catch (error) {
542
+ deviceKitParamsManager.error(
543
+ "\u274C QuecRNDeviceModule.getDeviceConnectingState(\u83B7\u53D6\u8FDE\u63A5\u72B6\u6001\u5931\u8D25)",
544
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
545
+ );
546
+ throw null;
547
+ }
548
+ };
549
+ var disconnectChannel = (type) => {
550
+ try {
551
+ QuecRNDeviceModule5.disconnectChannel(type);
552
+ deviceKitParamsManager.info(
553
+ "\u{1F502} QuecRNDeviceModule.disconnectChannel",
554
+ `\u65AD\u5F00\u8BBE\u5907\u8FDE\u63A5\u901A\u9053\u6210\u529F\uFF0C\u901A\u9053\u7C7B\u578B\uFF1A${type}`
555
+ );
556
+ } catch (error) {
557
+ deviceKitParamsManager.error(
558
+ "\u274C QuecRNDeviceModule.disconnectChannel(\u65AD\u5F00\u8BBE\u5907\u8FDE\u63A5\u901A\u9053\u5931\u8D25)",
559
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
560
+ );
561
+ }
562
+ };
563
+ var connectChannel = (mode) => {
564
+ try {
565
+ QuecRNDeviceModule5.connectChannel(mode);
566
+ deviceKitParamsManager.info(
567
+ "\u{1F502} QuecRNDeviceModule.connectChannel",
568
+ `\u5EFA\u7ACB\u8BBE\u5907\u8FDE\u63A5\u901A\u9053\u6210\u529F\uFF0C\u901A\u9053\u7C7B\u578B\uFF1A${mode}`
569
+ );
570
+ } catch (error) {
571
+ deviceKitParamsManager.error(
572
+ "\u274C QuecRNDeviceModule.connectChannel(\u5EFA\u7ACB\u8BBE\u5907\u8FDE\u63A5\u901A\u9053\u5931\u8D25)",
573
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
574
+ );
575
+ }
576
+ };
577
+ var getProductDescription = async (productKey) => {
578
+ try {
579
+ const { data } = await QuecRNDeviceModule5.getProductDescription(productKey);
580
+ deviceKitParamsManager.info(
581
+ "\u{1F4D8} QuecRNDeviceModule.getProductDescription",
582
+ `\u8BF4\u660E\u4E66\u5730\u5740\uFF1A${objToStr(data)}`
583
+ );
584
+ if (data?.url === void 0 || data?.url === "") {
585
+ return null;
586
+ }
587
+ return data.url;
588
+ } catch (error) {
589
+ deviceKitParamsManager.error(
590
+ "\u274C QuecRNDeviceModule.getProductDescription(\u83B7\u53D6\u8BF4\u660E\u4E66\u5931\u8D25)",
591
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
592
+ );
593
+ return null;
594
+ }
595
+ };
596
+
597
+ // src/types/Error.ts
598
+ function createCustomError(name, defaultCode) {
599
+ return class CustomError extends Error {
600
+ constructor(code, message) {
601
+ super(message);
602
+ this.name = name;
603
+ this.code = code;
604
+ Object.setPrototypeOf(this, new.target.prototype);
605
+ }
606
+ };
607
+ }
608
+ var GetDeviceInfoError = createCustomError(
609
+ "\u{1F4FA} GetDeviceInfoError");
610
+
611
+ // src/utils/empty.ts
612
+ var EmptyARR = [null, void 0, ""];
613
+ var isEmpty = (value) => {
614
+ return EmptyARR.some((empty) => {
615
+ if (typeof empty === "object" && empty !== null) {
616
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0;
617
+ }
618
+ return value === empty;
619
+ });
620
+ };
621
+
622
+ // src/utils/numberUtils.ts
623
+ var handlerNumberVal = (val, final) => {
624
+ let nextNumber = Number(val);
625
+ nextNumber = Number.isNaN(nextNumber) ? final : nextNumber;
626
+ return nextNumber;
627
+ };
628
+ var trueNumber = (val, final = 0) => {
629
+ return handlerNumberVal(val, final);
630
+ };
631
+
632
+ // src/deviceStore.ts
633
+ var initialState2 = {
634
+ device: null,
635
+ props: null,
636
+ isOnlyBle: false,
637
+ productUrl: null,
638
+ family: null,
639
+ area: null,
640
+ deviceIsEmpty: false,
641
+ deviceSate: 1,
642
+ connectingState: 0,
643
+ online: true,
644
+ wsOnline: true,
645
+ lanOnline: false,
646
+ bleOnline: false
647
+ };
648
+ var deviceStore = null;
649
+ var createDeviceStore = ({
650
+ offlineTip,
651
+ onlineTip
652
+ }) => {
653
+ if (!deviceStore) {
654
+ deviceStore = create((set, get) => ({
655
+ ...initialState2,
656
+ useSetProps: (propsSource) => {
657
+ if (isEmpty(propsSource)) {
658
+ deviceKitParamsManager.error(
659
+ "\u274C\u5904\u7406props\u5931\u8D25",
660
+ "\u5F53\u524Dprops\u6CA1\u6709\u521D\u59CB\u5316\uFF0Capp\u4F20\u5165\u7684\u4FE1\u606F\u4E3A\u7A7A props ==>" + objToStr(propsSource)
661
+ );
662
+ return null;
663
+ } else {
664
+ deviceKitParamsManager.info(" \u{1F680}\u5904\u7406props \u25B6 ", propsSource);
665
+ }
666
+ let props = typeof propsSource === "string" || typeof propsSource === "object" ? strToObj(propsSource) : null;
667
+ set({
668
+ props
669
+ });
670
+ if (props?.area) {
671
+ set({
672
+ area: props.area
673
+ });
674
+ }
675
+ if (props?.endUserId) {
676
+ set({
677
+ endUserId: props.endUserId
678
+ });
679
+ }
680
+ if (props?.userAccount) {
681
+ set({
682
+ userAccount: props.userAccount
683
+ });
684
+ }
685
+ if (props?.familyModeEnabled && props?.familyRole) {
686
+ set({
687
+ family: {
688
+ familyModeEnabled: props?.familyModeEnabled,
689
+ familyRole: props?.familyRole
690
+ }
691
+ });
692
+ }
693
+ let deviceSource = props?.device;
694
+ let device = deviceSource === void 0 ? null : strToObj(deviceSource);
695
+ if (isEmpty(device)) {
696
+ deviceKitParamsManager.error(
697
+ "\u274C\u5904\u7406device\u5931\u8D25",
698
+ "\u5F53\u524Ddevice\u6CA1\u6709\u521D\u59CB\u5316\uFF0C\u8BBE\u5907\u4FE1\u606F\u4E3A\u7A7A device ==>" + objToStr(device)
699
+ );
700
+ set({ deviceIsEmpty: true });
701
+ return props;
702
+ } else {
703
+ set({ deviceIsEmpty: false });
704
+ deviceKitParamsManager.info(" \u{1F680}\u5904\u7406device \u25B6 ", device);
705
+ get().getProductManual(device.productKey);
706
+ }
707
+ set({
708
+ device,
709
+ isOnlyBle: (device?.capabilitiesBitmask && 4) === 4 && device?.verified === "0" || device?.capabilitiesBitmask === 4
710
+ });
711
+ return props;
712
+ },
713
+ updateDevice: (device) => {
714
+ if (isEmpty(device)) {
715
+ deviceKitParamsManager.error(
716
+ "\u274C\u5904\u7406device\u5931\u8D25",
717
+ "device\u4E3A\u7A7A newDevice ==>" + objToStr(device)
718
+ );
719
+ set({ deviceIsEmpty: true });
720
+ return;
721
+ }
722
+ set({ deviceIsEmpty: false });
723
+ const newDevice = typeof device === "string" ? strToObj(device) : device;
724
+ deviceKitParamsManager.info("\u2705 \u65B0\u7684device \u25B6 ", newDevice);
725
+ set({
726
+ device: newDevice
727
+ });
728
+ get().getProductManual(newDevice.productKey);
729
+ get().getDeviceState();
730
+ },
731
+ updateDeviceName: (newName) => {
732
+ if (isEmpty(newName) || isEmpty(get().device)) {
733
+ deviceKitParamsManager.error(
734
+ "\u274C\u5904\u7406deviceName\u5931\u8D25",
735
+ "newName\u6216\u8005device\u4E3A\u7A7A newName ==>" + objToStr(newName)
736
+ );
737
+ return;
738
+ }
739
+ deviceKitParamsManager.info("\u2705 \u65B0\u7684deviceName \u25B6 ", newName);
740
+ const deviceNew = get().device;
741
+ if (deviceNew) {
742
+ deviceNew.deviceName = newName;
743
+ set({
744
+ device: deviceNew
745
+ });
746
+ }
747
+ },
748
+ getDeviceState: async () => {
749
+ try {
750
+ const { onlineState } = await QuecRNDeviceModule5.getOnlineState();
751
+ deviceKitParamsManager.info(
752
+ "\u{1F50E}QuecRNDeviceModule.getOnlineState....",
753
+ "\u83B7\u53D6\u8BBE\u5907\u72B6\u6001 ===> onlineState:" + onlineState
754
+ );
755
+ get().updateOnlineStatus(onlineState);
756
+ return onlineState;
757
+ } catch (error) {
758
+ deviceKitParamsManager.error("\u274C\u83B7\u53D6\u8BBE\u5907\u72B6\u6001\u5931\u8D25", "\u5931\u8D25\u539F\u56E0===> " + objToStr(error));
759
+ return null;
760
+ }
761
+ },
762
+ updateOnlineStatus: (deviceSate) => {
763
+ deviceSate = Number(deviceSate);
764
+ let nextOnlineState = trueNumber(deviceSate, 0 /* ALL_OFFLINE */);
765
+ if (nextOnlineState === get().deviceSate) {
766
+ return;
767
+ }
768
+ const online = nextOnlineState !== 0 /* ALL_OFFLINE */;
769
+ if (!online) {
770
+ offlineTip && offlineTip();
771
+ } else {
772
+ onlineTip && onlineTip();
773
+ }
774
+ set({
775
+ deviceSate,
776
+ online,
777
+ wsOnline: (deviceSate & 1 /* WS_ONLINE */) === 1 /* WS_ONLINE */,
778
+ lanOnline: (deviceSate & 2 /* WIFI_ONLINE */) === 2 /* WIFI_ONLINE */,
779
+ bleOnline: (deviceSate & 4 /* BLE_ONLINE */) === 4 /* BLE_ONLINE */
780
+ });
781
+ },
782
+ getDeviceConnectingState: async () => {
783
+ const connectingState = await getDeviceConnectingState();
784
+ set({
785
+ connectingState: connectingState ?? 0
786
+ });
787
+ },
788
+ updateConnectingState: (connectingState) => {
789
+ set({
790
+ connectingState
791
+ });
792
+ },
793
+ getProductManual: async (productKey) => {
794
+ const finalProductKey = productKey ?? get().device?.productKey;
795
+ if (finalProductKey === void 0) {
796
+ deviceKitParamsManager.error(
797
+ "\u{1F4D6}getProductManual",
798
+ `\u274C getProductDescription error====\uFF08\u83B7\u53D6\u8BF4\u660E\u4E66\u9519\u8BEF\uFF09==> there is not productKey(value:${productKey}) for getProductManual params`
799
+ );
800
+ return;
801
+ }
802
+ const url = await getProductDescription(finalProductKey);
803
+ set({ productUrl: url });
804
+ },
805
+ checkCurrentDeviceExist: async () => {
806
+ const currentDevice = get().device;
807
+ deviceKitParamsManager.info(
808
+ "\u{1F4FA} checkCurrentDeviceExist device.name \u25B6",
809
+ currentDevice?.deviceName
810
+ );
811
+ if (!currentDevice) {
812
+ deviceKitParamsManager.error("\u{1F4FA} \u5F53\u524D\u6CA1\u6709\u9009\u4E2D\u7684\u8BBE\u5907", currentDevice);
813
+ return void 0;
814
+ }
815
+ try {
816
+ const res = currentDevice?.isShared === true ? await get().getShareDeviceInfo() : await get().getDeviceInfo();
817
+ const exist = !!res;
818
+ deviceKitParamsManager.info("\u{1F4FA} \u5F53\u524D\u8BBE\u5907\u662F\u5426\u5B58\u5728 \u25B6", exist);
819
+ return exist;
820
+ } catch (e) {
821
+ if (e instanceof GetDeviceInfoError) {
822
+ switch (e.code) {
823
+ case "request_failed":
824
+ case "no_device":
825
+ deviceKitParamsManager.info("\u{1F4FA} \u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u8BF7\u6C42\u5931\u8D25\uFF0C\u5224\u5B9A\u4E3A\u4E0D\u5B58\u5728", e.message);
826
+ return false;
827
+ case "invalid_param":
828
+ deviceKitParamsManager.error("\u{1F4FA} \u53C2\u6570\u65E0\u6548\uFF0C\u65E0\u6CD5\u5224\u65AD\u8BBE\u5907\u662F\u5426\u5B58\u5728", e.message);
829
+ return void 0;
830
+ default:
831
+ deviceKitParamsManager.error("\u{1F4FA} \u672A\u77E5\u9519\u8BEF\u7801", e);
832
+ return void 0;
833
+ }
834
+ } else {
835
+ deviceKitParamsManager.error("\u{1F4FA} \u975E\u9884\u671F\u9519\u8BEF", e);
836
+ return void 0;
837
+ }
838
+ }
839
+ },
840
+ getDeviceInfo: async (deviceKey, productKey) => {
841
+ const finalDeviceKey = deviceKey || get().device?.deviceKey;
842
+ const finalProductKey = productKey || get().device?.productKey;
843
+ deviceKitParamsManager.info(
844
+ "\u{1F4FA} getDeviceInfoByDeviceKey params \u25B6",
845
+ `${finalDeviceKey}_${finalProductKey}`
846
+ );
847
+ if (!finalDeviceKey || !finalProductKey) {
848
+ throw new GetDeviceInfoError("invalid_param", "deviceKey \u6216 productKey \u4E0D\u5B8C\u6574");
849
+ }
850
+ const [err, res] = await to_default(
851
+ QuecRNDeviceModule5.getDeviceInfoByDeviceKey(finalDeviceKey, finalProductKey)
852
+ );
853
+ if (err) {
854
+ throw new GetDeviceInfoError(
855
+ "no_device",
856
+ `\u8BF7\u6C42\u5931\u8D25,\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664: ${err.message || err}`
857
+ );
858
+ }
859
+ if (!res) {
860
+ throw new GetDeviceInfoError("no_device", "\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664");
861
+ }
862
+ deviceKitParamsManager.info("\u{1F4FA} getDeviceInfoByDeviceKey res \u25B6", res);
863
+ return res;
864
+ },
865
+ getShareDeviceInfo: async (shareCode) => {
866
+ deviceKitParamsManager.info("\u{1F4FA} getShareDeviceInfo shareCode \u25B6", shareCode);
867
+ const finalShareCode = shareCode || get().device?.shareCode;
868
+ if (!finalShareCode) {
869
+ throw new GetDeviceInfoError("invalid_param", "\u53C2\u6570\u65E0\u6548\uFF1A\u7F3A\u5C11 shareCode");
870
+ }
871
+ const [err, res] = await to_default(
872
+ QuecRNDeviceModule5.getDeviceInfoByShareCode(finalShareCode)
873
+ );
874
+ if (err) {
875
+ throw new GetDeviceInfoError(
876
+ "no_device",
877
+ `\u8BF7\u6C42\u5931\u8D25,\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664: ${err.message || err}`
878
+ );
879
+ }
880
+ if (!res) {
881
+ throw new GetDeviceInfoError("no_device", "\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u5DF2\u88AB\u79FB\u9664");
882
+ }
883
+ deviceKitParamsManager.info("\u{1F4FA} getShareDeviceInfo res \u25B6", res);
884
+ return res;
885
+ }
886
+ }));
887
+ }
888
+ return deviceStore;
889
+ };
890
+ var getDeviceStore = () => {
891
+ if (!deviceStore) {
892
+ throw new Error("\u2757\u8BF7\u5148\u8C03\u7528 createDeviceStore() \u521D\u59CB\u5316 deviceStore");
893
+ }
894
+ return deviceStore;
895
+ };
896
+ var getDeviceStoreWithoutError = () => {
897
+ if (!deviceStore) {
898
+ return null;
899
+ }
900
+ return deviceStore;
901
+ };
902
+ var selectFromStore2 = (selector) => {
903
+ const store = getDeviceStore();
904
+ return store(selector);
905
+ };
906
+ var useDeviceStoreState = () => selectFromStore2((state) => state);
907
+ var useDevice = () => selectFromStore2((state) => state.device);
908
+ var useDeviceProps = () => selectFromStore2((state) => state.props);
909
+ var useDeviceFamily = () => selectFromStore2((state) => state.family);
910
+ var useDeviceArea = () => selectFromStore2((state) => state.area);
911
+ var useDeviceProductUrl = () => selectFromStore2((state) => state.productUrl);
912
+ var useEndUserId = () => selectFromStore2((state) => state.endUserId);
913
+ var useUserAccount = () => selectFromStore2((state) => state.userAccount);
914
+ var useDeviceIsOnlyBle = () => selectFromStore2((state) => state.isOnlyBle);
915
+ var useDeviceOnline = () => selectFromStore2((state) => state.online);
916
+ var useDeviceState = () => selectFromStore2((state) => state.deviceSate);
917
+ var useDeviceWsOnline = () => selectFromStore2((state) => state.wsOnline);
918
+ var useDeviceLanOnline = () => selectFromStore2((state) => state.lanOnline);
919
+ var useDeviceBleOnline = () => selectFromStore2((state) => state.bleOnline);
920
+ var useDeviceIsConnecting = () => selectFromStore2((state) => Number(state.connectingState) !== 0);
921
+ var useGetDeviceStatus = () => selectFromStore2((state) => state.getDeviceState);
922
+ var useUpdateDeviceConnectingState = () => selectFromStore2((state) => state.updateConnectingState);
923
+ var useSetProps = () => selectFromStore2((state) => state.useSetProps);
924
+ var useUpdateDevice = () => selectFromStore2((state) => state.updateDevice);
925
+ var useUpdateDeviceName = () => selectFromStore2((state) => state.updateDeviceName);
926
+ var useUpdateOnlineStatus = () => selectFromStore2((state) => state.updateOnlineStatus);
927
+ var useCheckCurrentDeviceExist = () => selectFromStore2((state) => state.checkCurrentDeviceExist);
928
+ var EVENT_TYPE_DEVICE_ONLINE = "onDeviceOnlineState";
929
+ var EVENT_TYPE_DEVICE_CONNECTING = "onDeviceConnectingState";
930
+ var eventEmitter = new NativeEventEmitter(NativeModules.QuecRNDeviceModule);
931
+ var onDeviceStateUpdateListener;
932
+ var onDeviceConnectingStateUpdateListener;
933
+ var useInitUpdateDeviceStateEvent = (updateDeviceStateCallback, updateDeviceConnectingStateCallback) => {
934
+ const deviceListStore2 = getDeviceListStoreWithoutError();
935
+ const deviceListStoreState = deviceListStore2 ? deviceListStore2((state) => state) : null;
936
+ if (deviceListStoreState === null) {
937
+ deviceKitParamsManager.info(
938
+ "PS\uFF1A\u5982\u679C\u4F60\u4E0D\u4F7F\u7528\u8BBE\u5907\u4FE1\u606F\u72B6\u6001\u7BA1\u7406\uFF0C\u8BF7\u5FFD\u7565\u6B64\u8B66\u544A",
939
+ "WARNING \u4F60\u672A\u521D\u59CB\u5316 createDeviceListStore "
940
+ );
941
+ }
942
+ const updateDeviceOnlineState = deviceListStoreState?.updateDeviceOnlineState ?? null;
943
+ const deviceStore2 = getDeviceStoreWithoutError();
944
+ const deviceStoreState = deviceStore2 ? deviceStore2((state) => state) : null;
945
+ if (deviceStoreState === null) {
946
+ deviceKitParamsManager.info(
947
+ "PS\uFF1A\u5982\u679C\u4F60\u4E0D\u4F7F\u7528\u8BBE\u5907\u5217\u8868\u4FE1\u606F\u72B6\u6001\u7BA1\u7406\uFF0C\u8BF7\u5FFD\u7565\u6B64\u8B66\u544A",
948
+ "WARNING \u4F60\u672A\u521D\u59CB\u5316 createDeviceStore "
949
+ );
950
+ }
951
+ const updateOnlineStatus = deviceStoreState?.updateOnlineStatus ?? null;
952
+ const updateConnectingState = deviceStoreState?.updateConnectingState ?? null;
953
+ const device = deviceStoreState?.device ?? null;
954
+ useEffect(() => {
955
+ removeListener(onDeviceStateUpdateListener);
956
+ onDeviceStateUpdateListener = eventEmitter.addListener(
957
+ EVENT_TYPE_DEVICE_ONLINE,
958
+ (event) => {
959
+ deviceKitParamsManager.info(
960
+ EVENT_TYPE_DEVICE_ONLINE,
961
+ " \u{1F91D} ==OnlineState==" + objToStr(event)
962
+ );
963
+ if (isEmpty(event)) {
964
+ return;
965
+ }
966
+ const eventDevice = strToObj(event.device);
967
+ if (device?.deviceKey === eventDevice?.deviceKey && device?.productKey === eventDevice?.productKey && updateOnlineStatus) {
968
+ updateOnlineStatus(event.onlineState);
969
+ }
970
+ if (updateDeviceOnlineState) {
971
+ updateDeviceOnlineState(event);
972
+ }
973
+ updateDeviceStateCallback && updateDeviceStateCallback(event);
974
+ }
975
+ );
976
+ return () => {
977
+ removeListener(onDeviceStateUpdateListener);
978
+ onDeviceStateUpdateListener = null;
979
+ };
980
+ }, [updateDeviceOnlineState, updateOnlineStatus, device]);
981
+ useEffect(() => {
982
+ removeListener(onDeviceConnectingStateUpdateListener);
983
+ onDeviceConnectingStateUpdateListener = eventEmitter.addListener(
984
+ EVENT_TYPE_DEVICE_ONLINE,
985
+ (event) => {
986
+ deviceKitParamsManager.info(
987
+ EVENT_TYPE_DEVICE_CONNECTING,
988
+ " \u26A1 ==ConnectingState==" + objToStr(event)
989
+ );
990
+ const connectingState = isNaN(event?.connectingState) ? 0 : Number(event?.connectingState);
991
+ updateConnectingState && updateConnectingState(connectingState);
992
+ updateDeviceConnectingStateCallback && updateDeviceConnectingStateCallback(event);
993
+ }
994
+ );
995
+ return () => {
996
+ removeListener(onDeviceConnectingStateUpdateListener);
997
+ onDeviceConnectingStateUpdateListener = null;
998
+ };
999
+ }, [updateConnectingState, updateDeviceConnectingStateCallback]);
1000
+ };
1001
+ var removeListener = (listener) => {
1002
+ if (listener) {
1003
+ listener.remove();
1004
+ listener = void 0;
1005
+ }
1006
+ };
1007
+
1008
+ // src/device-list-utils.ts
1009
+ var QuecRNBusinessPanelModule = {
1010
+ changeBusinessPanel: (params) => {
1011
+ console.warn("QuecRNBusinessPanelModule.changeBusinessPanel is not available", params);
1012
+ },
1013
+ switchBusinessPanel: () => {
1014
+ console.warn("QuecRNBusinessPanelModule.switchBusinessPanel is not available");
1015
+ }
1016
+ };
1017
+ var changeDevicePanel = (newDevice) => {
1018
+ deviceKitParamsManager.info(
1019
+ "changeDevicePanel",
1020
+ "__\u66F4\u6362\u8BBE\u5907\u9762\u677F => \u8BBE\u5907\uFF1A" + newDevice.deviceName
1021
+ );
1022
+ QuecRNBusinessPanelModule.changeBusinessPanel({
1023
+ device: JSON.stringify(newDevice)
1024
+ });
1025
+ };
1026
+ var checkoutEmptyPanel = () => {
1027
+ deviceKitParamsManager.info("checkoutEmptyPanel", "__\u66F4\u6362\u6258\u5E95\u9762\u677F");
1028
+ QuecRNBusinessPanelModule.switchBusinessPanel();
1029
+ };
1030
+
1031
+ // src/initDeviceListUpdate.ts
1032
+ var EVENT_TYPE_REFRESH_DEVICE_LIST = "QuecRefreshDeviceList";
1033
+ var refreshDeviceListListener;
1034
+ var panelEventEmitter = new NativeEventEmitter(NativeModules.QuecRNBusinessPanelModule);
1035
+ var useInitDeviceListUpdateEvent = (params) => {
1036
+ const {
1037
+ refreshDeviceListEventCallback,
1038
+ refreshDeviceListSuccessCallback,
1039
+ enableAutoCheckoutDevice
1040
+ } = params ?? {};
1041
+ const deviceListStore2 = getDeviceListStoreWithoutError();
1042
+ const deviceListStoreState = deviceListStore2 ? deviceListStore2((state) => state) : null;
1043
+ if (deviceListStoreState === null) {
1044
+ deviceKitParamsManager.info(
1045
+ "PS\uFF1A\u5982\u679C\u4F60\u4E0D\u4F7F\u7528\u8BBE\u5907\u5217\u8868\u4FE1\u606F\u72B6\u6001\u7BA1\u7406\uFF0C\u8BF7\u5FFD\u7565\u6B64\u8B66\u544A",
1046
+ "WARNING \u4F60\u672A\u521D\u59CB\u5316 createDeviceListStore "
1047
+ );
1048
+ }
1049
+ const deviceStore2 = getDeviceStoreWithoutError();
1050
+ const deviceStoreState = deviceStore2 ? deviceStore2((state) => state) : null;
1051
+ if (deviceStoreState === null) {
1052
+ deviceKitParamsManager.info(
1053
+ "PS\uFF1A\u5982\u679C\u4F60\u4E0D\u4F7F\u7528\u8BBE\u5907\u4FE1\u606F\u72B6\u6001\u7BA1\u7406\uFF0C\u8BF7\u5FFD\u7565\u6B64\u8B66\u544A",
1054
+ "WARNING \u4F60\u672A\u521D\u59CB\u5316 createDeviceStore "
1055
+ );
1056
+ }
1057
+ const listIsEmpty = deviceListStoreState?.listIsEmpty ?? null;
1058
+ const refreshDeviceList = deviceListStoreState?.refreshDeviceList ?? null;
1059
+ const device = deviceStoreState?.device ?? null;
1060
+ const deviceIsEmpty = deviceStoreState?.deviceIsEmpty ?? null;
1061
+ const checkCurrentDeviceExist = deviceStoreState?.checkCurrentDeviceExist ?? null;
1062
+ const [onceCheckNowDevice, setOnceCheckNowDevice] = useState(true);
1063
+ useEffect(() => {
1064
+ removeListener2(refreshDeviceListListener);
1065
+ refreshDeviceListListener = panelEventEmitter.addListener(
1066
+ EVENT_TYPE_REFRESH_DEVICE_LIST,
1067
+ (event) => {
1068
+ deviceKitParamsManager.info(EVENT_TYPE_REFRESH_DEVICE_LIST, "==refresh device list \u{1F504}==");
1069
+ refreshDeviceList && refreshDeviceList((list) => {
1070
+ refreshDeviceListSuccessCallback && refreshDeviceListSuccessCallback(list);
1071
+ if (checkCurrentDeviceExist && enableAutoCheckoutDevice) {
1072
+ checkCurrentDeviceExist().then((res) => {
1073
+ if (res === false && list?.length > 0) {
1074
+ changeDevicePanel(list[0]);
1075
+ }
1076
+ });
1077
+ }
1078
+ });
1079
+ refreshDeviceListEventCallback && refreshDeviceListEventCallback(event);
1080
+ }
1081
+ );
1082
+ return () => {
1083
+ removeListener2(refreshDeviceListListener);
1084
+ refreshDeviceListListener = null;
1085
+ };
1086
+ }, [refreshDeviceList]);
1087
+ useEffect(() => {
1088
+ if (!enableAutoCheckoutDevice) return;
1089
+ if (deviceIsEmpty === true || listIsEmpty === true) {
1090
+ checkoutEmptyPanel();
1091
+ }
1092
+ }, [deviceIsEmpty, listIsEmpty, enableAutoCheckoutDevice]);
1093
+ useEffect(() => {
1094
+ if (!enableAutoCheckoutDevice) return;
1095
+ if (device && onceCheckNowDevice) {
1096
+ setOnceCheckNowDevice(false);
1097
+ if (checkCurrentDeviceExist && enableAutoCheckoutDevice) {
1098
+ checkCurrentDeviceExist().then((res) => {
1099
+ if (res === false) {
1100
+ refreshDeviceList && refreshDeviceList((list) => {
1101
+ if (list[0]) {
1102
+ changeDevicePanel(list[0]);
1103
+ }
1104
+ });
1105
+ }
1106
+ });
1107
+ }
1108
+ }
1109
+ }, [device, onceCheckNowDevice, enableAutoCheckoutDevice]);
1110
+ };
1111
+ var removeListener2 = (listener) => {
1112
+ if (listener) {
1113
+ listener.remove();
1114
+ listener = void 0;
1115
+ }
1116
+ };
1117
+ var EVENT_TYPE_REFRESH_DEVICE = "QuecRefreshDeviceInfo";
1118
+ var refreshDeviceListListener2;
1119
+ var panelEventEmitter2 = new NativeEventEmitter(NativeModules.QuecRNBusinessPanelModule);
1120
+ var useInitDeviceInfoUpdateEvent = (refreshDeviceEventCallback) => {
1121
+ const deviceStore2 = getDeviceStoreWithoutError();
1122
+ const deviceStoreState = deviceStore2 ? deviceStore2((state) => state) : null;
1123
+ if (deviceStoreState === null) {
1124
+ deviceKitParamsManager.info(
1125
+ "PS\uFF1A\u5982\u679C\u4F60\u4E0D\u4F7F\u7528\u8BBE\u5907\u5217\u8868\u4FE1\u606F\u72B6\u6001\u7BA1\u7406\uFF0C\u8BF7\u5FFD\u7565\u6B64\u8B66\u544A",
1126
+ "WARNING \u4F60\u672A\u521D\u59CB\u5316 createDeviceStore "
1127
+ );
1128
+ }
1129
+ const updateDevice = deviceStoreState?.updateDevice ?? null;
1130
+ useEffect(() => {
1131
+ removeListener3(refreshDeviceListListener2);
1132
+ refreshDeviceListListener2 = panelEventEmitter2.addListener(
1133
+ EVENT_TYPE_REFRESH_DEVICE,
1134
+ (e) => {
1135
+ deviceKitParamsManager.info(EVENT_TYPE_REFRESH_DEVICE, "\u{1F4DE} ==refresh device info \u{1F504}==");
1136
+ let newDevice = {};
1137
+ try {
1138
+ newDevice = typeof e.device === "string" ? JSON.parse(e.device) : e.device;
1139
+ } catch (error) {
1140
+ deviceKitParamsManager.info(
1141
+ EVENT_TYPE_REFRESH_DEVICE + " \u{1F4DE} ==refresh device info get new device info ERROR \u274C==",
1142
+ error
1143
+ );
1144
+ }
1145
+ updateDevice && updateDevice(newDevice);
1146
+ refreshDeviceEventCallback && refreshDeviceEventCallback(e);
1147
+ }
1148
+ );
1149
+ return () => {
1150
+ removeListener3(refreshDeviceListListener2);
1151
+ refreshDeviceListListener2 = null;
1152
+ };
1153
+ }, [updateDevice]);
1154
+ };
1155
+ var removeListener3 = (listener) => {
1156
+ if (listener) {
1157
+ listener.remove();
1158
+ listener = void 0;
1159
+ }
1160
+ };
1161
+ var setOfflineReminder = async ({
1162
+ enableOfflineReminder,
1163
+ deviceKey,
1164
+ productKey
1165
+ }) => {
1166
+ try {
1167
+ await QuecRNDeviceModule5.setOfflineReminder(enableOfflineReminder, productKey, deviceKey);
1168
+ deviceKitParamsManager.info("\u{1F50E} QuecRNDeviceModule.setOfflineReminder....", "\u8BBE\u7F6E\u79BB\u7EBF\u63D0\u9192\u5F00\u5173");
1169
+ } catch (error) {
1170
+ deviceKitParamsManager.error(
1171
+ "\u274C QuecRNDeviceModule.setOfflineReminder(\u83B7\u53D6\u8BBE\u5907\u72B6\u6001\u5931\u8D25)",
1172
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1173
+ );
1174
+ }
1175
+ };
1176
+ var getOfflineReminderInfo = async ({
1177
+ productKey,
1178
+ deviceKey
1179
+ }) => {
1180
+ try {
1181
+ const result = await QuecRNDeviceModule5.getOfflineReminderInfo(productKey, deviceKey);
1182
+ deviceKitParamsManager.info("\u{1F50D} QuecRNDeviceModule.getOfflineReminderInfo", result);
1183
+ return +result?.data === 1;
1184
+ } catch (error) {
1185
+ deviceKitParamsManager.error(
1186
+ "\u274C QuecRNDeviceModule.getOfflineReminderInfo(\u67E5\u8BE2\u5931\u8D25)",
1187
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1188
+ );
1189
+ throw false;
1190
+ }
1191
+ };
1192
+ var checkDeviceUpdatePlan = async (device) => {
1193
+ try {
1194
+ await QuecRNDeviceModule5.checkDeviceUpdatePlan(device);
1195
+ deviceKitParamsManager.info("\u{1F50D} QuecRNDeviceModule.checkDeviceUpdatePlan", "\u6709\u5347\u7EA7\u8BA1\u5212");
1196
+ return true;
1197
+ } catch (error) {
1198
+ deviceKitParamsManager.info("\u{1F50D} QuecRNDeviceModule.checkDeviceUpdatePlan", "\u65E0\u5347\u7EA7\u8BA1\u5212");
1199
+ throw false;
1200
+ }
1201
+ };
1202
+ var openDeviceOTAPage = async ({
1203
+ productKey,
1204
+ deviceKey
1205
+ }) => {
1206
+ try {
1207
+ await QuecRNDeviceModule5.openDeviceOTAPage(productKey, deviceKey);
1208
+ deviceKitParamsManager.info("\u{1F4C2} QuecRNDeviceModule.openDeviceOTAPage", "\u5DF2\u6253\u5F00\u8BBE\u5907OTA\u8BE6\u60C5\u9875");
1209
+ } catch (error) {
1210
+ deviceKitParamsManager.error(
1211
+ "\u274C QuecRNDeviceModule.openDeviceOTAPage(\u6253\u5F00\u5931\u8D25)",
1212
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1213
+ );
1214
+ throw error;
1215
+ }
1216
+ };
1217
+ var getTimeDifferenceWithGMT = async () => {
1218
+ try {
1219
+ const result = await QuecRNDeviceModule5.getTimeDifferenceWithGMT();
1220
+ deviceKitParamsManager.info(
1221
+ "\u{1F552} QuecRNDeviceModule.getTimeDifferenceWithGMT(\u83B7\u53D6\u5F53\u524D\u624B\u673A\u8BBE\u7F6E\u7684\u65F6\u533A\u4E0E GMT \u7684\u5DEE\u503C) ==>",
1222
+ result
1223
+ );
1224
+ return result;
1225
+ } catch (error) {
1226
+ deviceKitParamsManager.error(
1227
+ "\u274C QuecRNDeviceModule.getTimeDifferenceWithGMT(\u83B7\u53D6\u5F53\u524D\u624B\u673A\u8BBE\u7F6E\u7684\u65F6\u533A\u4E0E GMT \u7684\u5DEE\u503C\u5931\u8D25) ==>",
1228
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1229
+ );
1230
+ throw error;
1231
+ }
1232
+ };
1233
+ var getDeviceTimeZone = async ({
1234
+ productKey,
1235
+ deviceKey
1236
+ }) => {
1237
+ try {
1238
+ const result = await QuecRNDeviceModule5.getDeviceTimeZone(productKey, deviceKey);
1239
+ deviceKitParamsManager.info(
1240
+ "\u{1F30D} QuecRNDeviceModule.getDeviceTimeZone(\u83B7\u53D6\u8BBE\u5907\u8BBE\u7F6E\u7684\u65F6\u533A) ==>",
1241
+ result
1242
+ );
1243
+ return result;
1244
+ } catch (error) {
1245
+ deviceKitParamsManager.error(
1246
+ "\u274C QuecRNDeviceModule.getDeviceTimeZone(\u83B7\u53D6\u8BBE\u5907\u8BBE\u7F6E\u7684\u65F6\u533A\u5931\u8D25) ==>",
1247
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1248
+ );
1249
+ throw error;
1250
+ }
1251
+ };
1252
+ var setDeviceTimeZone = async ({
1253
+ productKey,
1254
+ deviceKey,
1255
+ timezone
1256
+ }) => {
1257
+ try {
1258
+ await QuecRNDeviceModule5.setDeviceTimeZone(productKey, deviceKey, timezone);
1259
+ deviceKitParamsManager.info(
1260
+ "\u2705 QuecRNDeviceModule.setDeviceTimeZone",
1261
+ `\u5DF2\u8BBE\u7F6E\u65F6\u533A\u4E3A ${timezone}`
1262
+ );
1263
+ } catch (error) {
1264
+ deviceKitParamsManager.error(
1265
+ "\u274C QuecRNDeviceModule.setDeviceTimeZone(\u8BBE\u7F6E\u5931\u8D25)",
1266
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1267
+ );
1268
+ throw error;
1269
+ }
1270
+ };
1271
+ var timeZoneSyncForBleDevice = async ({
1272
+ productKey,
1273
+ deviceKey
1274
+ }) => {
1275
+ try {
1276
+ await QuecRNDeviceModule5.timeZoneSync(productKey, deviceKey);
1277
+ deviceKitParamsManager.info(
1278
+ "\u23F1\uFE0F QuecRNDeviceModule.timeZoneSync",
1279
+ `\u8BBE\u5907\u5DF2\u6821\u65F6\uFF08productKey: ${productKey}, deviceKey: ${deviceKey}\uFF09`
1280
+ );
1281
+ } catch (error) {
1282
+ deviceKitParamsManager.error(
1283
+ "\u274C QuecRNDeviceModule.timeZoneSync(\u8BBE\u5907\u6821\u65F6\u5931\u8D25)",
1284
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1285
+ );
1286
+ throw error;
1287
+ }
1288
+ };
1289
+ var unbindBleDevice = async ({
1290
+ productKey,
1291
+ deviceKey,
1292
+ isInit,
1293
+ random,
1294
+ pureBtResetCredentials
1295
+ }) => {
1296
+ try {
1297
+ await QuecRNDeviceModule5.unbindlingPureBtDevice(
1298
+ productKey,
1299
+ deviceKey,
1300
+ isInit,
1301
+ random,
1302
+ pureBtResetCredentials
1303
+ );
1304
+ deviceKitParamsManager.info(
1305
+ "\u{1F513} QuecRNDeviceModule.unbindlingPureBtDevice",
1306
+ `\u89E3\u7ED1\u6210\u529F\uFF08productKey: ${productKey}, deviceKey: ${deviceKey}\uFF09`
1307
+ );
1308
+ } catch (error) {
1309
+ deviceKitParamsManager.error(
1310
+ "\u274C QuecRNDeviceModule.unbindlingPureBtDevice(\u89E3\u7ED1\u5931\u8D25)",
1311
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1312
+ );
1313
+ throw error;
1314
+ }
1315
+ };
1316
+ var unbindShareDevice = async ({ shareCode }) => {
1317
+ try {
1318
+ await QuecRNDeviceModule5.unShareDeviceByShareUserWithShareCode(shareCode);
1319
+ deviceKitParamsManager.info(
1320
+ "\u{1F513} QuecRNDeviceModule.unShareDeviceByShareUserWithShareCode",
1321
+ `\u89E3\u7ED1\u6210\u529F\uFF08shareCode: ${shareCode}\uFF09`
1322
+ );
1323
+ } catch (error) {
1324
+ deviceKitParamsManager.error(
1325
+ "\u274C QuecRNDeviceModule.unShareDeviceByShareUserWithShareCode(\u89E3\u7ED1\u5931\u8D25)",
1326
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1327
+ );
1328
+ throw error;
1329
+ }
1330
+ };
1331
+ var unbindDevice = async ({
1332
+ deviceKey,
1333
+ productKey
1334
+ }) => {
1335
+ try {
1336
+ await QuecRNDeviceModule5.unbindDeviceWithDeviceKey(deviceKey, productKey);
1337
+ deviceKitParamsManager.info(
1338
+ "\u{1F513} QuecRNDeviceModule.unbindDeviceWithDeviceKey",
1339
+ `\u89E3\u7ED1\u6210\u529F\uFF08deviceKey: ${deviceKey}, productKey: ${productKey}\uFF09`
1340
+ );
1341
+ } catch (error) {
1342
+ deviceKitParamsManager.error(
1343
+ "\u274C QuecRNDeviceModule.unbindDeviceWithDeviceKey(\u89E3\u7ED1\u5931\u8D25)",
1344
+ "\u5931\u8D25\u539F\u56E0===> " + objToStr(error)
1345
+ );
1346
+ throw error;
1347
+ }
1348
+ };
1349
+
1350
+ export { DEVICE_ACCESS_TYPE_DIRECTLY, DEVICE_ACCESS_TYPE_GATEWAY, DEVICE_ACCESS_TYPE_GATEWAY_CHILD, DEVICE_NAME_MAX_LENGTH, DEVICE_TYPE_BIND, DEVICE_TYPE_SHARE, EVENT_TYPE_DEVICE_CONNECTING, EVENT_TYPE_DEVICE_ONLINE, EVENT_TYPE_REFRESH_DEVICE, EVENT_TYPE_REFRESH_DEVICE_LIST, LOADING_SEND_TIMEOUT, NOT_CONNECTING, changeDevicePanel, checkDeviceUpdatePlan, checkoutEmptyPanel, connectChannel, createDeviceListStore, createDeviceStore, deviceKitParamsManager, disconnectChannel, getDeviceConnectingState, getDeviceListStore, getDeviceListStoreWithoutError, getDeviceOnlineState, getDeviceStore, getDeviceStoreWithoutError, getDeviceTimeZone, getOfflineReminderInfo, getProductDescription, getTimeDifferenceWithGMT, onlineStatus, openDeviceOTAPage, setDeviceTimeZone, setOfflineReminder, timeZoneSyncForBleDevice, unbindBleDevice, unbindDevice, unbindShareDevice, useCheckCurrentDeviceExist, useDevice, useDeviceArea, useDeviceBleOnline, useDeviceFamily, useDeviceIsConnecting, useDeviceIsOnlyBle, useDeviceLanOnline, useDeviceList, useDeviceListLoadMore, useDeviceListRefresh, useDeviceListStoreState, useDeviceOnline, useDeviceProductUrl, useDeviceProps, useDeviceState, useDeviceStoreState, useDeviceWsOnline, useEndUserId, useGetDeviceStatus, useInitDeviceInfoUpdateEvent, useInitDeviceListUpdateEvent, useInitUpdateDeviceStateEvent, useSetProps, useUpdateDevice, useUpdateDeviceConnectingState, useUpdateDeviceName, useUpdateOnlineStatus, useUserAccount };
1351
+ //# sourceMappingURL=index.js.map
1352
+ //# sourceMappingURL=index.js.map