@ray-js/lock-sdk 1.0.0-beta-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 (95) hide show
  1. package/lib/api/index.d.ts +5 -0
  2. package/lib/api/index.js +18 -0
  3. package/lib/api/linkage.d.ts +161 -0
  4. package/lib/api/linkage.js +74 -0
  5. package/lib/api/lock.d.ts +195 -0
  6. package/lib/api/lock.js +129 -0
  7. package/lib/api/log.d.ts +166 -0
  8. package/lib/api/log.js +44 -0
  9. package/lib/api/setting.d.ts +14 -0
  10. package/lib/api/setting.js +36 -0
  11. package/lib/api/temp.d.ts +211 -0
  12. package/lib/api/temp.js +130 -0
  13. package/lib/api/user.d.ts +154 -0
  14. package/lib/api/user.js +59 -0
  15. package/lib/api/video.d.ts +9 -0
  16. package/lib/api/video.js +17 -0
  17. package/lib/config/dp-code/index.d.ts +175 -0
  18. package/lib/config/dp-code/index.js +224 -0
  19. package/lib/config/dp-map/common.d.ts +102 -0
  20. package/lib/config/dp-map/common.js +120 -0
  21. package/lib/config/dp-map/normal.d.ts +6 -0
  22. package/lib/config/dp-map/normal.js +51 -0
  23. package/lib/config/dp-map/open.d.ts +21 -0
  24. package/lib/config/dp-map/open.js +62 -0
  25. package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
  26. package/lib/config/dp-map/unlock-method-big.js +237 -0
  27. package/lib/config/dp-map/unlock-method.d.ts +551 -0
  28. package/lib/config/dp-map/unlock-method.js +231 -0
  29. package/lib/config/index.d.ts +46 -0
  30. package/lib/config/index.js +56 -0
  31. package/lib/constant.d.ts +101 -0
  32. package/lib/constant.js +136 -0
  33. package/lib/dp-interface.d.ts +7 -0
  34. package/lib/dp-interface.js +1 -0
  35. package/lib/event.d.ts +8 -0
  36. package/lib/event.js +9 -0
  37. package/lib/index.d.ts +25 -0
  38. package/lib/index.js +92 -0
  39. package/lib/interface.d.ts +807 -0
  40. package/lib/interface.js +1 -0
  41. package/lib/linkage.d.ts +26 -0
  42. package/lib/linkage.js +175 -0
  43. package/lib/log.d.ts +91 -0
  44. package/lib/log.js +314 -0
  45. package/lib/media.d.ts +43 -0
  46. package/lib/media.js +80 -0
  47. package/lib/open.d.ts +48 -0
  48. package/lib/open.js +247 -0
  49. package/lib/other.d.ts +36 -0
  50. package/lib/other.js +178 -0
  51. package/lib/parse/index.d.ts +6 -0
  52. package/lib/parse/index.js +22 -0
  53. package/lib/signal.d.ts +26 -0
  54. package/lib/signal.js +38 -0
  55. package/lib/sleep.d.ts +61 -0
  56. package/lib/sleep.js +121 -0
  57. package/lib/state.d.ts +54 -0
  58. package/lib/state.js +429 -0
  59. package/lib/sync/remote-serect-key.d.ts +5 -0
  60. package/lib/sync/remote-serect-key.js +60 -0
  61. package/lib/sync/t0.d.ts +5 -0
  62. package/lib/sync/t0.js +33 -0
  63. package/lib/sync/temp.d.ts +7 -0
  64. package/lib/sync/temp.js +88 -0
  65. package/lib/sync/unlock-mothod.d.ts +5 -0
  66. package/lib/sync/unlock-mothod.js +54 -0
  67. package/lib/temporary.d.ts +226 -0
  68. package/lib/temporary.js +637 -0
  69. package/lib/unlock-method.d.ts +269 -0
  70. package/lib/unlock-method.js +723 -0
  71. package/lib/user.d.ts +108 -0
  72. package/lib/user.js +361 -0
  73. package/lib/utils/base64-to-hex.d.ts +1 -0
  74. package/lib/utils/base64-to-hex.js +12 -0
  75. package/lib/utils/byte.d.ts +19 -0
  76. package/lib/utils/byte.js +74 -0
  77. package/lib/utils/constant.d.ts +11 -0
  78. package/lib/utils/constant.js +17 -0
  79. package/lib/utils/device.d.ts +207 -0
  80. package/lib/utils/device.js +353 -0
  81. package/lib/utils/errors.d.ts +2 -0
  82. package/lib/utils/errors.js +125 -0
  83. package/lib/utils/event.d.ts +23 -0
  84. package/lib/utils/event.js +144 -0
  85. package/lib/utils/hex-to-base64.d.ts +1 -0
  86. package/lib/utils/hex-to-base64.js +8 -0
  87. package/lib/utils/hex-to-bytes.d.ts +6 -0
  88. package/lib/utils/hex-to-bytes.js +16 -0
  89. package/lib/utils/index.d.ts +169 -0
  90. package/lib/utils/index.js +419 -0
  91. package/lib/utils/log.d.ts +5 -0
  92. package/lib/utils/log.js +78 -0
  93. package/lib/utils/publishDps.d.ts +11 -0
  94. package/lib/utils/publishDps.js +91 -0
  95. package/package.json +37 -0
@@ -0,0 +1,207 @@
1
+ /***
2
+ * 统一重新封装 TTT 能力api
3
+ * 以便于以后支持跨端能力
4
+ */
5
+ import { DeviceInfo, DpData, ParamType } from "../interface";
6
+ export declare const getDeviceInfo: (devId: string) => Promise<DeviceInfo>;
7
+ export declare const getDeviceProperties: (devId: string) => Promise<Record<string, any>>;
8
+ export declare const setDeviceProperty: (devId: string, code: string, value: string | number | Record<string, any>) => Promise<boolean>;
9
+ export declare const publishDeviceDps: (params: {
10
+ deviceId: string;
11
+ dps: Record<string, boolean | number | string>;
12
+ }) => Promise<unknown>;
13
+ export declare const registerDevice: (devIds: string[]) => void;
14
+ export declare const registerBleStatus: (devId: string) => void;
15
+ export declare const onDpDataChange: (func: ParamType<typeof ty.device.onDpDataChange>) => void;
16
+ export declare const offDpDataChange: (func: ParamType<typeof ty.device.offDpDataChange>) => void;
17
+ export declare const onDeviceInfoUpdated: (func: (data: {
18
+ deviceId: string;
19
+ dps?: DpData;
20
+ }) => void) => void;
21
+ export declare const offDeviceInfoUpdated: (func: (data: {
22
+ deviceId: string;
23
+ dps?: DpData;
24
+ }) => void) => void;
25
+ export declare const onOnlineChange: (func: ParamType<typeof ty.device.onDeviceOnlineStatusUpdate>) => void;
26
+ export declare const offOnlineChange: (func: ParamType<typeof ty.device.offDeviceOnlineStatusUpdate>) => void;
27
+ export declare const onBleChange: (func: ParamType<typeof ty.device.onBLEConnectStatusChange>) => void;
28
+ export declare const offBleChange: (func: ParamType<typeof ty.device.offBLEConnectStatusChange>) => void;
29
+ export declare const getSystemInfo: () => any;
30
+ export declare const showModal: (options: ParamType<typeof ty.showModal>) => any;
31
+ export declare const showToast: (options: ParamType<typeof ty.showToast>) => any;
32
+ export declare const api: <T>(options: {
33
+ url: string;
34
+ data: Record<string, any>;
35
+ version: string;
36
+ }) => Promise<unknown>;
37
+ export declare const getDeviceOnlineType: (deviceId: string) => Promise<number>;
38
+ export declare const requestCloud: <T>(options: {
39
+ api: string;
40
+ version: string;
41
+ data: Record<string, any>;
42
+ }) => Promise<T>;
43
+ export declare const getLaunchOptionsSync: () => any;
44
+ export declare function encrypt(deviceId: string, plaintext: string): Promise<string>;
45
+ export declare function decrypt(deviceId: string, plaintext: string): Promise<string>;
46
+ export declare const getCurrentHomeInfo: () => Promise<{
47
+ /** 家庭名称 */
48
+ homeName: string;
49
+ /** 家庭id */
50
+ homeId: string;
51
+ /** 经度 */
52
+ longitude: string;
53
+ /** 维度 */
54
+ latitude: string;
55
+ /** 详细地址 */
56
+ address: string;
57
+ /**
58
+ * 是否是管理员
59
+ * true 是管理员; false 非管理员
60
+ */
61
+ admin: boolean;
62
+ }>;
63
+ export declare const isSupportShortLink: (link: string) => Promise<unknown>;
64
+ export declare const onBackgroundFetchData: (fetchApiKeys: string[], cb: (data: {
65
+ fetchedData: Record<string, {
66
+ fetchedData: any;
67
+ timeStamp: number;
68
+ }>;
69
+ }) => void) => void;
70
+ export declare const getBackgroundFetchData: (fetchApiKeys: string[]) => Promise<{
71
+ fetchedData: Record<string, {
72
+ fetchedData: any;
73
+ timeStamp: number;
74
+ }>;
75
+ } | null>;
76
+ interface SendMqttMessageParams {
77
+ /** 消息内容 */
78
+ message: Record<string, {}>;
79
+ /** 设备id */
80
+ deviceId: string;
81
+ /** 协议号 */
82
+ protocol: number;
83
+ }
84
+ /**
85
+ * 发送 MQTT 消息
86
+ * @param params
87
+ * @returns
88
+ */
89
+ export declare const sendMqttMessage: (params: SendMqttMessageParams) => Promise<{
90
+ fetchedData: Record<string, {
91
+ fetchedData: any;
92
+ timeStamp: number;
93
+ }>;
94
+ } | null>;
95
+ type MqttResponse = {
96
+ /** 设备 id */
97
+ deviceId?: string;
98
+ /** 原始消息数据 */
99
+ message: any;
100
+ /** 双端抹平后的消息数据 */
101
+ messageData: any;
102
+ /** 消息类型 */
103
+ type: string;
104
+ /** 协议号 */
105
+ protocol: number;
106
+ /** topic */
107
+ topic?: string;
108
+ };
109
+ type MqttMessageListener = (data: MqttResponse) => void;
110
+ export declare const onMqttMessage: (cb: MqttMessageListener) => void;
111
+ export declare const offMqttMessage: (cb: MqttMessageListener) => void;
112
+ export declare const registerMQTTDeviceListener: (deviceId: string) => void;
113
+ export declare const registerMQTTProtocolListener: (protocol: number) => void;
114
+ export declare const openPanel: (params: ParamType<typeof ty.openPanel>) => any;
115
+ export declare const openNativeRouter: (name: string, params: Record<string, any>) => Promise<unknown>;
116
+ export type SceneAction = {
117
+ /** 条件 ID */
118
+ id?: string;
119
+ /** 场景 ID */
120
+ ruleId?: string;
121
+ /** 场景 ID */
122
+ orderNum?: number;
123
+ /** 条件为设备类型时,表示设备 ID */
124
+ entityId: string;
125
+ /** 设备名称 */
126
+ entityName?: string;
127
+ /**
128
+ * 动作类型。枚举:
129
+ * ruleTrigger:触发场景
130
+ * ruleEnable:启用场景
131
+ * ruleDisable:禁用场景
132
+ * appPushTrigger:推送消息
133
+ * mobileVoiceSend:电话服务
134
+ * smsSend:短信服务
135
+ * deviceGroupDpIssue:执行群组
136
+ * irIssue:执行红外设备
137
+ * dpIssue:执行普通设备
138
+ * delay:延时
139
+ * irIssueVii:执行红外设备,执行参数为真实的红外控制码
140
+ * toggle:执行切换开关动作
141
+ * dpStep:执行步进动作
142
+ */
143
+ actionExecutor: string;
144
+ /** 动作执行信息 */
145
+ executorProperty: any;
146
+ /** 动作额外信息 */
147
+ extraProperty: any;
148
+ /** 设备是否在线 */
149
+ isDevOnline?: boolean;
150
+ /** 条件为设备类型时,表示设备是否被移除 */
151
+ devDelMark?: boolean;
152
+ /** 条件为设备类型时,表示设备被删除时的图标 */
153
+ deleteDevIcon?: string;
154
+ /** 条件为设备类型时,设备的图标 */
155
+ devIcon?: string;
156
+ /** 动作的策略 */
157
+ actionStrategy?: string;
158
+ /** 设备产品 ID */
159
+ pid?: string;
160
+ /** 设备产品 ID */
161
+ productId?: string;
162
+ /** 条件为设备类型时,表示设备产品图片 */
163
+ productPic?: string;
164
+ /** 条件默认图标 */
165
+ defaultIconUrl?: string;
166
+ /** 动作展示信息 */
167
+ actionDisplay?: string;
168
+ /** 动作展示信息 */
169
+ actionDisplayNew?: any;
170
+ /** 执行状态 */
171
+ status?: boolean;
172
+ /** 批量控制设备的数据 */
173
+ relationGroup?: any;
174
+ };
175
+ export declare const createAction: (params: {
176
+ /**
177
+ * 动作类型:device,smart,remind,delay
178
+ * device:设备
179
+ * smart:操作某个智能(执行智能、开关自动化)
180
+ * remind:提醒
181
+ * delay:延时
182
+ */
183
+ createType: string;
184
+ /**
185
+ * 智能类型:scene,auto
186
+ * scene:一键执行
187
+ * auto:自动化
188
+ */
189
+ smartType: string;
190
+ }) => Promise<SceneAction[]>;
191
+ export declare const editAction: (params: {
192
+ /** 当前编辑的actionIndex */
193
+ editIndex: number;
194
+ /** 智能类型 */
195
+ smartType: string;
196
+ /** 动作列表 */
197
+ actionArray: SceneAction[];
198
+ }) => Promise<SceneAction[]>;
199
+ export declare const getHomeInfo: () => Promise<{
200
+ homeName: string;
201
+ homeId: string;
202
+ longitude: string;
203
+ latitude: string;
204
+ address: string;
205
+ admin: boolean;
206
+ }>;
207
+ export {};
@@ -0,0 +1,353 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.reduce.js";
4
+ /***
5
+ * 统一重新封装 TTT 能力api
6
+ * 以便于以后支持跨端能力
7
+ */
8
+
9
+ export const getDeviceInfo = devId => {
10
+ return new Promise((resolve, reject) => {
11
+ ty.device.getDeviceInfo({
12
+ deviceId: devId,
13
+ success: res => resolve(res),
14
+ fail: reject
15
+ });
16
+ });
17
+ };
18
+ export const getDeviceProperties = async devId => {
19
+ return new Promise((resolve, reject) => {
20
+ ty.device.getDeviceProperty({
21
+ deviceId: devId,
22
+ success: _ref => {
23
+ let {
24
+ properties
25
+ } = _ref;
26
+ const result = Object.keys(properties).reduce((res, cur) => {
27
+ const value = properties[cur];
28
+ try {
29
+ res[cur] = JSON.parse(value);
30
+ } catch {
31
+ res[cur] = value;
32
+ }
33
+ return res;
34
+ }, {});
35
+ resolve(result);
36
+ },
37
+ fail: reject
38
+ });
39
+ });
40
+ };
41
+ export const setDeviceProperty = async (devId, code, value) => {
42
+ return new Promise((resolve, reject) => {
43
+ ty.device.setDeviceProperty({
44
+ deviceId: devId,
45
+ code,
46
+ value: JSON.stringify(value),
47
+ success: () => {
48
+ resolve(true);
49
+ },
50
+ fail: reject
51
+ });
52
+ });
53
+ };
54
+ export const publishDeviceDps = params => {
55
+ return new Promise((resolve, reject) => {
56
+ ty.device.publishDps(_objectSpread(_objectSpread({
57
+ mode: 2,
58
+ pipelines: [],
59
+ options: {}
60
+ }, params), {}, {
61
+ success: resolve,
62
+ fail: reject
63
+ }));
64
+ });
65
+ };
66
+ export const registerDevice = devIds => {
67
+ ty.device.registerDeviceListListener({
68
+ deviceIdList: devIds
69
+ });
70
+ };
71
+ export const registerBleStatus = devId => {
72
+ ty.device.subscribeBLEConnectStatus({
73
+ deviceId: devId
74
+ });
75
+ };
76
+ export const onDpDataChange = func => {
77
+ ty.device.onDpDataChange(func);
78
+ };
79
+ export const offDpDataChange = func => {
80
+ // 由于 小程序底层删除为同步删除,如果在 onDpDataChange 回调中删除监听函数,可能会导致某些回调无法被触发,所以这里使用异步删除
81
+ setTimeout(() => {
82
+ ty.device.offDpDataChange(func);
83
+ }, 0);
84
+ };
85
+
86
+ // 设备信息变化
87
+ export const onDeviceInfoUpdated = func => {
88
+ ty.device.onDeviceInfoUpdated(func);
89
+ };
90
+ export const offDeviceInfoUpdated = func => {
91
+ ty.device.offDeviceInfoUpdated(func);
92
+ };
93
+ // 设备在离线变更
94
+ export const onOnlineChange = func => {
95
+ ty.device.onDeviceOnlineStatusUpdate(func);
96
+ };
97
+ export const offOnlineChange = func => {
98
+ ty.device.offDeviceOnlineStatusUpdate(func);
99
+ };
100
+
101
+ // 蓝牙连接状态变更
102
+ export const onBleChange = func => {
103
+ ty.device.onBLEConnectStatusChange(func);
104
+ };
105
+ export const offBleChange = func => {
106
+ ty.device.offBLEConnectStatusChange(func);
107
+ };
108
+ export const getSystemInfo = () => ty.getSystemInfoSync();
109
+ export const showModal = options => {
110
+ return ty.showModal(options);
111
+ };
112
+ export const showToast = options => {
113
+ return ty.showToast(options);
114
+ };
115
+ export const api = options => {
116
+ return new Promise((resolve, reject) => {
117
+ ty.apiRequestByAtop({
118
+ api: options.url,
119
+ postData: options.data,
120
+ version: options.version,
121
+ success: d => {
122
+ resolve(d);
123
+ },
124
+ fail: err => {
125
+ reject(err);
126
+ }
127
+ });
128
+ });
129
+ };
130
+ export const getDeviceOnlineType = deviceId => {
131
+ return new Promise((resolve, reject) => {
132
+ ty.device.getDeviceOnlineType({
133
+ deviceId,
134
+ success: d => {
135
+ resolve(d.onlineType);
136
+ },
137
+ fail: err => {
138
+ reject(err);
139
+ }
140
+ });
141
+ });
142
+ };
143
+ export const requestCloud = options => {
144
+ return new Promise((resolve, reject) => {
145
+ ty.requestCloud({
146
+ api: options.api,
147
+ version: options.version,
148
+ data: options.data,
149
+ success: d => {
150
+ resolve(d);
151
+ },
152
+ fail: err => {
153
+ var _err$innerError;
154
+ reject((_err$innerError = err.innerError) !== null && _err$innerError !== void 0 ? _err$innerError : err);
155
+ }
156
+ });
157
+ });
158
+ };
159
+ export const getLaunchOptionsSync = () => {
160
+ return ty.getLaunchOptionsSync();
161
+ };
162
+
163
+ // 加密函数(ECB 模式)
164
+ export async function encrypt(deviceId, plaintext) {
165
+ return new Promise((resolve, reject) => {
166
+ // @ts-expect-error
167
+ ty.device.aes128EncryptedStringWithPassword({
168
+ deviceId,
169
+ password: plaintext,
170
+ success: res => {
171
+ resolve(res.toUpperCase());
172
+ },
173
+ fail: reject
174
+ });
175
+ });
176
+ }
177
+
178
+ // 解密函数(ECB 模式)
179
+ export async function decrypt(deviceId, plaintext) {
180
+ return new Promise((resolve, reject) => {
181
+ // @ts-expect-error
182
+ ty.device.aes128DecryptedStringWithPassword({
183
+ deviceId,
184
+ password: plaintext,
185
+ success: res => {
186
+ resolve(res);
187
+ },
188
+ fail: reject
189
+ });
190
+ });
191
+ }
192
+
193
+ // 获取当前家庭信息
194
+ export const getCurrentHomeInfo = async () => {
195
+ return new Promise((resolve, reject) => {
196
+ ty.home.getCurrentHomeInfo({
197
+ success: res => resolve(res),
198
+ fail: reject
199
+ });
200
+ });
201
+ };
202
+ export const isSupportShortLink = async link => {
203
+ return new Promise(resolve => {
204
+ ty.canIUseRouter({
205
+ url: link,
206
+ success: res => {
207
+ if (res !== null && res !== void 0 && res.result) {
208
+ resolve(link);
209
+ } else {
210
+ resolve("");
211
+ }
212
+ },
213
+ fail: () => {
214
+ resolve("");
215
+ }
216
+ });
217
+ });
218
+ };
219
+ export const onBackgroundFetchData = (fetchApiKeys, cb) => {
220
+ // @ts-expect-error
221
+ if (ty.onBackgroundFetchData) {
222
+ // @ts-expect-error
223
+ ty.onBackgroundFetchData({
224
+ fetchApiKeys,
225
+ success: data => {
226
+ cb(data);
227
+ },
228
+ fail: () => {
229
+ // 不处理
230
+ }
231
+ });
232
+ }
233
+ };
234
+ export const getBackgroundFetchData = async fetchApiKeys => {
235
+ // @ts-expect-error
236
+ if (ty.getBackgroundFetchData) {
237
+ return new Promise(resolve => {
238
+ // @ts-expect-error
239
+ ty.getBackgroundFetchData({
240
+ fetchType: "periodic",
241
+ fetchApiKeys,
242
+ success: res => {
243
+ resolve(res);
244
+ },
245
+ fail: () => {
246
+ resolve(null);
247
+ }
248
+ });
249
+ });
250
+ }
251
+ return null;
252
+ };
253
+ /**
254
+ * 发送 MQTT 消息
255
+ * @param params
256
+ * @returns
257
+ */
258
+ export const sendMqttMessage = async params => {
259
+ return new Promise((resolve, reject) => {
260
+ ty.device.sendMqttMessage(_objectSpread(_objectSpread({}, params), {}, {
261
+ options: {},
262
+ success: res => {
263
+ resolve(res);
264
+ },
265
+ fail: err => {
266
+ reject(err);
267
+ }
268
+ }));
269
+ });
270
+ };
271
+ export const onMqttMessage = cb => {
272
+ ty.device.onMqttMessageReceived(cb);
273
+ };
274
+ export const offMqttMessage = cb => {
275
+ ty.device.offMqttMessageReceived(cb);
276
+ };
277
+ export const registerMQTTDeviceListener = deviceId => {
278
+ ty.device.registerMQTTDeviceListener({
279
+ deviceId
280
+ });
281
+ };
282
+ export const registerMQTTProtocolListener = protocol => {
283
+ ty.device.registerMQTTProtocolListener({
284
+ protocol
285
+ });
286
+ };
287
+ export const openPanel = params => {
288
+ return ty.openPanel(params);
289
+ };
290
+ export const openNativeRouter = (name, params) => {
291
+ const query = Object.entries(params).reduce((acc, _ref2) => {
292
+ let [key, value] = _ref2;
293
+ if (typeof value !== "undefined") {
294
+ acc.push(`${key}=${value}`);
295
+ }
296
+ return acc;
297
+ }, []).join("&");
298
+ return new Promise((resolve, reject) => {
299
+ ty.canIUseRouter({
300
+ url: name,
301
+ success: res => {
302
+ if (res !== null && res !== void 0 && res.result) {
303
+ ty.router({
304
+ url: `thingSmart://${name}?${query}`,
305
+ success: () => {
306
+ resolve(true);
307
+ },
308
+ fail: e => {
309
+ reject(e);
310
+ }
311
+ });
312
+ }
313
+ },
314
+ fail: err => {
315
+ reject(err);
316
+ }
317
+ });
318
+ });
319
+ };
320
+ export const createAction = params => {
321
+ return new Promise((resolve, reject) => {
322
+ ty.device.createAction(_objectSpread(_objectSpread({}, params), {}, {
323
+ actionArray: [],
324
+ success: res => {
325
+ resolve(res.actionArray);
326
+ },
327
+ fail: err => {
328
+ reject(err);
329
+ }
330
+ }));
331
+ });
332
+ };
333
+ export const editAction = params => {
334
+ return new Promise((resolve, reject) => {
335
+ // @ts-expect-error
336
+ ty.device.editAction(_objectSpread(_objectSpread({}, params), {}, {
337
+ success: res => {
338
+ resolve(res.actionArray);
339
+ },
340
+ fail: err => {
341
+ reject(err);
342
+ }
343
+ }));
344
+ });
345
+ };
346
+ export const getHomeInfo = async () => {
347
+ return new Promise((resolve, reject) => {
348
+ ty.home.getCurrentHomeInfo({
349
+ success: res => resolve(res),
350
+ fail: reject
351
+ });
352
+ });
353
+ };
@@ -0,0 +1,2 @@
1
+ import { ErrorData } from "../interface";
2
+ export declare const getError: (code: number, ...places: string[]) => ErrorData;
@@ -0,0 +1,125 @@
1
+ const errors = {
2
+ // 设备离线
3
+ 1001: "Device offline",
4
+ // 操作超时
5
+ 1002: "Operation timeout",
6
+ // 远程开锁失败
7
+ 1003: "Remote unlocking failure",
8
+ // 设备报告远程开锁失败
9
+ 1004: "Device reports that remote unlocking failed",
10
+ // 远程开锁失效
11
+ 1005: "Remote unlocking failure",
12
+ // 秘钥次数使用完
13
+ 1006: "Secret key times has been used up",
14
+ // 秘钥不在有效期内
15
+ 1007: "Secret key is not valid",
16
+ // 秘钥比对错误
17
+ 1008: "Secret key is wrong",
18
+ // 缺少必要属性
19
+ 1009: "Missing required attribute: {0}",
20
+ // 生效起始时间不能大于生效结束时间
21
+ 1010: "The effective time cannot be greater than the valid time",
22
+ // 更新设备侧成员时效失败
23
+ 1011: "Failed to update device side member validity",
24
+ // 更新成员时效失败
25
+ 1012: "Failed to update member validity",
26
+ // App不支持该功能
27
+ 1013: "App not support the function",
28
+ // 设备不支持该功能
29
+ 1014: "Device does not support the function",
30
+ 1015: "Timeout when entering unlocking method",
31
+ 1016: "Failed to enter unlocking method",
32
+ 1017: "Repeated entry when entering unlocking method",
33
+ 1018: "Hardware ID allocation completed when entering unlocking method",
34
+ 1019: "Error in adding password, field is non-numeric (backup)",
35
+ 1020: "Error in adding password, password length",
36
+ 1021: "Unsupported unlocking method type",
37
+ 1022: "Currently entering fingerprint",
38
+ 1023: "Currently binding door card",
39
+ 1024: "Currently binding face",
40
+ 1025: "Password is too simple",
41
+ 1026: "Parameter error, such as repeated message sequence number",
42
+ 1027: "Start add Unlock method failure",
43
+ // 删除失败
44
+ 1028: "Delete failed",
45
+ // 硬件 ID 不能删除
46
+ 1029: "Hardware ID cannot be deleted",
47
+ // 仅支持数字密码
48
+ 1030: "Only numeric passwords are supported",
49
+ // 密码名称长度不能大于20个字符
50
+ 1031: "Password name length cannot exceed 20 characters",
51
+ // 未配置时效
52
+ 1032: "Validity not configured",
53
+ // 未配置时效生效日期
54
+ 1033: "Validity start date not configured",
55
+ // 未配置时效失效日期
56
+ 1034: "Validity end date not configured",
57
+ // 时效配置周重复时未设置周配置
58
+ 1035: "Weekly repeat validity configuration not set",
59
+ // 时效配置月重复时未设置天配置
60
+ 1036: "Monthly repeat validity configuration not set",
61
+ // 密码已存在
62
+ 1037: "Password already exists",
63
+ // 密码名称重复
64
+ 1038: "Password name is duplicated",
65
+ // 密码生效时间与结束时间不正确
66
+ 1039: "Password effective time and end time are incorrect",
67
+ // 临时密码 id 不存在
68
+ 1040: "Temporary password ID does not exist",
69
+ // 设备无硬件 ID 可用
70
+ 1041: "Device has no hardware ID available",
71
+ // 添加临时密码失败
72
+ 1042: "Failed to add temporary password",
73
+ // 临时密码添加失败,未获取到云端预分配的编号
74
+ 1043: "Temporary password addition failed, pre-allocated number not obtained from cloud",
75
+ // 清空单个密码时,缺少传入 unlockBindingId
76
+ 1044: "When clearing a single password, missing unlockBindingId",
77
+ // 功能不支持
78
+ 1045: "Function not supported",
79
+ // 远程开关门未开启
80
+ 1046: "Remote door opening and closing function is not enabled",
81
+ // 无权限远程开关门
82
+ 1047: "Remote door opening and closing without permission",
83
+ // 无此用户
84
+ 1048: "No such user",
85
+ // 不支持修改管理员时效
86
+ 1049: "Does not support modifying administrator validity period",
87
+ // 开锁方式未存在绑定关系
88
+ 1050: "Unlock method does not have a binding relationship",
89
+ // 无效数据
90
+ 1051: "Invalid data",
91
+ // 操作正式执行,请稍后
92
+ 1052: "Operation is being executed, please wait",
93
+ // 同步添加云端开锁方式失败
94
+ 1053: "Failed to synchronize and add cloud unlocking method",
95
+ // 密码不能为空
96
+ 1054: "Password cannot be empty",
97
+ // 特殊开锁方式使用短信通知时,验证码不能为空
98
+ 1055: "Verification code cannot be empty",
99
+ // 特殊开锁方式使用短信通知时,国家码不能为空
100
+ 1056: "Country code cannot be empty",
101
+ // 特殊开锁方式 app 消息通知必须开启
102
+ 1057: "Special unlock method app message notification must be enabled",
103
+ // 特殊开锁方式 app 消息或手机短信必须开启一个
104
+ 1058: "Special unlock method app message notification or phone SMS must be enabled",
105
+ // 门铃通知服务未开通
106
+ 1059: "Doorbell notification service not enabled"
107
+ };
108
+ export const getError = function (code) {
109
+ if (errors[code]) {
110
+ let desc = errors[code];
111
+ if ((arguments.length <= 1 ? 0 : arguments.length - 1) > 0) {
112
+ for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
113
+ desc = desc.replace(`{${i}}`, i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
114
+ }
115
+ }
116
+ return {
117
+ errorCode: code,
118
+ errorMsg: desc
119
+ };
120
+ }
121
+ return {
122
+ errorCode: code,
123
+ errorMsg: "unknow error"
124
+ };
125
+ };
@@ -0,0 +1,23 @@
1
+ type Callback<T> = (args: T) => void;
2
+ declare function createEmitter(): {
3
+ on: <T>(type: string, cb: Callback<T>) => void;
4
+ off: <T>(type: string, cb: Callback<T>) => void;
5
+ once: <T>(type: string, cb: Callback<T>) => void;
6
+ emit: <T>(type: string, data: T) => void;
7
+ clear: () => void;
8
+ hasListener: (type: string) => boolean;
9
+ cache: <T>(type: string, data: T) => void;
10
+ clearCache: (type: string) => void;
11
+ };
12
+ export { createEmitter };
13
+ declare const _default: {
14
+ on: <T>(type: string, cb: Callback<T>) => void;
15
+ off: <T>(type: string, cb: Callback<T>) => void;
16
+ once: <T>(type: string, cb: Callback<T>) => void;
17
+ emit: <T>(type: string, data: T) => void;
18
+ clear: () => void;
19
+ hasListener: (type: string) => boolean;
20
+ cache: <T>(type: string, data: T) => void;
21
+ clearCache: (type: string) => void;
22
+ };
23
+ export default _default;