mini_program_gizwits_sdk 3.2.30 → 3.3.2

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.
@@ -1,4 +1,4 @@
1
- export type TLogType = 'debug' | 'info' | 'warn' | 'error';
1
+ export declare type TLogType = 'debug' | 'info' | 'warn' | 'error';
2
2
  declare class Log {
3
3
  logMap: {
4
4
  id: string;
@@ -1,8 +1,8 @@
1
1
  import { wrapErrorInfo } from '../utils';
2
2
  import EventListener from './EventListener';
3
- type GizBleDeviceListotifications = (devices: IDevice[]) => void;
4
- type GizBleDeviceDataNotifications = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult, hexString: string) => void;
5
- type GizBleErrorNotifications = (err: {
3
+ declare type GizBleDeviceListotifications = (devices: IDevice[]) => void;
4
+ declare type GizBleDeviceDataNotifications = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult, hexString: string) => void;
5
+ declare type GizBleErrorNotifications = (err: {
6
6
  errCode: number;
7
7
  errMsg: string;
8
8
  }) => void;
@@ -22,11 +22,7 @@ export interface IStartScanResult {
22
22
  scanList: IDevice[];
23
23
  err?: ReturnType<typeof wrapErrorInfo>;
24
24
  }
25
- interface IDeviceReq<T> {
26
- success: boolean;
27
- data: T;
28
- }
29
- export type OnScanDevice = (scanList: IDevice[]) => void;
25
+ export declare type OnScanDevice = (scanList: IDevice[]) => void;
30
26
  interface ConnectDevice {
31
27
  deviceId?: string;
32
28
  serviceId?: string;
@@ -93,24 +89,9 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
93
89
  stopScan: () => Promise<any>;
94
90
  disableScan: () => Promise<WechatMiniprogram.BluetoothError>;
95
91
  enableScan: () => void;
96
- private connectDeviceBle;
97
- private connectDeviceBindRequest;
98
- private connectDeviceLoginRequest;
99
- private _connectDevice;
100
- connectDevice: (device: IDevice) => Promise<{
92
+ connectDevice: (deviceId: string) => Promise<{
101
93
  success: boolean;
102
94
  message: any;
103
- data?: undefined;
104
- } | {
105
- success: boolean;
106
- data: {
107
- serviceId: any;
108
- characteristicId: any;
109
- };
110
- message?: undefined;
111
- } | IDeviceReq<string> | {
112
- success: boolean;
113
- message: string;
114
95
  }>;
115
96
  private handleBindReq;
116
97
  private handleLoginReq;
@@ -10,8 +10,8 @@ interface ILanDevice extends IDevice {
10
10
  expandData: DiscoverUDP;
11
11
  ip: string;
12
12
  }
13
- type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
14
- type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
13
+ declare type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
14
+ declare type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
15
15
  export interface TLanHandleEvent {
16
16
  GizLanDeviceList: GizLanDeviceListNotifications;
17
17
  GizLanDeviceData: GizLanDeviceDataNotifications;
@@ -48,7 +48,7 @@ export declare class LanHandle extends EventListener<TLanHandleEvent> {
48
48
  connectDevice: (device: any) => Promise<IResult<any>>;
49
49
  onError: (err: any) => void;
50
50
  isMatchPk: (pk: any) => boolean;
51
- onMessage: (res: WechatMiniprogram.UDPSocketOnMessageListenerResult) => void;
51
+ onMessage: (res: WechatMiniprogram.UDPSocketOnMessageCallbackResult) => void;
52
52
  onDeviceClose: ({ productKey, mac }: {
53
53
  productKey: any;
54
54
  mac: any;
@@ -35,7 +35,7 @@ export default class GizwitsWS {
35
35
  }) => void;
36
36
  _getDevice: (did: string) => IDevice | IError;
37
37
  _getConnect: (device: IDevice) => Connection;
38
- _getDeviceAndConnect: (did: string) => [IDevice, Connection] | IError;
38
+ _getDeviceAndConnect: (did: string) => IError | [IDevice, Connection];
39
39
  connectDevice: (device: IDevice) => {
40
40
  success: boolean;
41
41
  errorCode: IError;
@@ -97,7 +97,7 @@ export declare class Connection {
97
97
  _checkConnectTimerId?: any;
98
98
  constructor({ appID, token, uid, wsInfo, onDeviceStatusChanged, onBindingChanged, onSocketStatusChanged, }: IConnectProps);
99
99
  destory: () => void;
100
- _networkChange: (res: WechatMiniprogram.OnNetworkStatusChangeListenerResult) => Promise<void>;
100
+ _networkChange: (res: WechatMiniprogram.OnNetworkStatusChangeCallbackResult) => Promise<void>;
101
101
  _appShow: () => Promise<void>;
102
102
  _addSubDid: (did: any) => void;
103
103
  _removeSubDid: (did: any) => void;
@@ -6,7 +6,7 @@ declare class ProductConfigFileManage {
6
6
  data: IData;
7
7
  key: string;
8
8
  init: () => Promise<void>;
9
- getConfigFile: (pk: string) => Promise<IDataPointConfig | null>;
9
+ getConfigFile: (pk: string) => Promise<IDataPointConfig>;
10
10
  getAttrItem: (pk: string, key: string) => Promise<import("./protocol/DataPoint").IDataPointAttr>;
11
11
  }
12
12
  declare const productConfigFileManage: ProductConfigFileManage;
@@ -13,14 +13,14 @@ interface IDataPointPosition {
13
13
  len: number;
14
14
  bit_offset: number;
15
15
  }
16
- type TDataType = 'bool' | 'uint8' | 'uint16' | 'uint32' | 'binary' | 'enum' | 'number';
16
+ declare type TDataType = 'bool' | 'uint8' | 'uint16' | 'uint32' | 'binary' | 'enum' | 'number';
17
17
  interface IUnitSpec {
18
18
  addition: number;
19
19
  max: number;
20
20
  ratio: number;
21
21
  min: number;
22
22
  }
23
- type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault' | 'ALL';
23
+ declare type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault' | 'ALL';
24
24
  export interface IDataPointAttr {
25
25
  display_name: string;
26
26
  uint_spec: IUnitSpec;
@@ -41,7 +41,7 @@ interface IRawData {
41
41
  action: string;
42
42
  payload: string;
43
43
  }
44
- type messageType = 'APP2DEV' | 'DEV2APP' | 'UNKNOW';
44
+ declare type messageType = 'APP2DEV' | 'DEV2APP' | 'UNKNOW';
45
45
  declare const unpack: (data: number[], pk: string) => Promise<{
46
46
  kvData: {};
47
47
  rawData: IRawData;
@@ -60,8 +60,8 @@ declare const pack: (data: object, pk: string) => Promise<{
60
60
  };
61
61
  }>;
62
62
  declare const padBoradcastData: (data: number[]) => string;
63
- type TargetType = 'int' | 'string';
63
+ declare type TargetType = 'int' | 'string';
64
64
  declare const formatEnum: (attrs: any, pk: string, targetType: TargetType) => Promise<any>;
65
- type BTargetType = 'string' | 'object';
65
+ declare type BTargetType = 'string' | 'object';
66
66
  declare const formatBinary: (attrs: any, pk: string, targetType: BTargetType) => Promise<any>;
67
67
  export { pack, unpack, padBoradcastData, formatEnum, formatBinary };
@@ -1,5 +1,5 @@
1
1
  import ProtocolBase from "./ProtocolBase";
2
- type TDecodeType = 'ASCII' | 'HEX';
2
+ declare type TDecodeType = 'ASCII' | 'HEX';
3
3
  declare class DiscoverUDP extends ProtocolBase {
4
4
  did: string;
5
5
  mac: string;
@@ -0,0 +1,8 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ declare type IStatus = 0 | 1;
3
+ declare class Reset extends ProtocolBase {
4
+ status: IStatus;
5
+ constructor(data: number[]);
6
+ static pack: () => number[];
7
+ }
8
+ export default Reset;
@@ -0,0 +1,7 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ declare type IStatus = 0 | 1;
3
+ declare class SetReset extends ProtocolBase {
4
+ status: IStatus;
5
+ static pack: (status: 0 | 1) => number[];
6
+ }
7
+ export default SetReset;
@@ -0,0 +1,212 @@
1
+ import { TLogType } from './GizLog';
2
+ import { ILoginRes } from './services/login';
3
+ import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
4
+ import { IDataPointConfig } from './protocol/DataPoint';
5
+ interface SyncCallBackParams {
6
+ event: TSyncEvnet;
7
+ currentNum?: number;
8
+ totalNum?: number;
9
+ message?: string;
10
+ }
11
+ declare type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
12
+ export declare type SyncCallBack = (data: SyncCallBackParams) => void;
13
+ export interface ISDKResult<T> {
14
+ data?: T;
15
+ err?: IError;
16
+ message?: string;
17
+ success: boolean;
18
+ }
19
+ export interface ISetCommonDeviceOnboardingDeployProps {
20
+ ssid: string;
21
+ password: string;
22
+ timeout: number;
23
+ isBind?: boolean;
24
+ mode?: 0 | 3;
25
+ softAPSSIDPrefix?: string;
26
+ }
27
+ export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
28
+ softAPSSIDPrefix: string;
29
+ }
30
+ export interface IRandomCodesResult {
31
+ random_code: string;
32
+ product_key: string;
33
+ mac: string;
34
+ did: string;
35
+ user_id: string;
36
+ timestamp: number;
37
+ type: string;
38
+ wifi_soft_ver: string;
39
+ lan_proto_ver: string;
40
+ }
41
+ interface IBindRemoteDeviceParams {
42
+ productKey: string;
43
+ mac: string;
44
+ beOwner?: boolean;
45
+ alias?: string;
46
+ }
47
+ interface IDeviceStatusNoti {
48
+ device: IDevice;
49
+ connectType: TConnectType;
50
+ }
51
+ interface IDeviceAttrsNoti {
52
+ device: IDevice;
53
+ data: object;
54
+ }
55
+ export interface TListenerType {
56
+ GizDeviceListNotifications: TDeviceListNotifications;
57
+ GizDeviceStatusNotifications: TDeviceStatusNotifications;
58
+ GizDeviceAttrsNotifications: TDeviceAttrsNotifications;
59
+ onScanListChange: OnScanListChange;
60
+ onBleHandleError: OnBleHandleError;
61
+ }
62
+ declare type TDeviceListNotifications = (devices: IDevice[]) => void;
63
+ declare type TDeviceStatusNotifications = (data: IDeviceStatusNoti) => void;
64
+ declare type TDeviceAttrsNotifications = (data: IDeviceAttrsNoti) => void;
65
+ declare type OnScanListChange = (devices: IDevice[]) => void;
66
+ declare type OnBleHandleError = (error: IError) => void;
67
+ interface IDeviceSafetyRegisterParams {
68
+ mac: string;
69
+ productKey: string;
70
+ }
71
+ export interface IResult<T> {
72
+ success: boolean;
73
+ data?: T;
74
+ err?: IError;
75
+ }
76
+ interface ICloudServiceInfo {
77
+ openAPIInfo: string;
78
+ }
79
+ export declare type TimeoutHandle = ReturnType<typeof setTimeout> | null;
80
+ export declare type IntervalHandle = ReturnType<typeof setInterval> | null;
81
+ export interface IProductInfo {
82
+ productKey: string;
83
+ productSecret: string;
84
+ }
85
+ interface GizwitsSdkOption {
86
+ appID: string;
87
+ appSecret: string;
88
+ productInfo: IProductInfo[];
89
+ cloudServiceInfo?: ICloudServiceInfo;
90
+ token?: string;
91
+ uid?: string;
92
+ offlineThreshold?: number;
93
+ }
94
+ declare class GizwitsMiniSDK {
95
+ private listenerMap;
96
+ private keepScanTimer;
97
+ private _deviceList;
98
+ private get deviceList();
99
+ private set deviceList(value);
100
+ private _bleDevices;
101
+ get bleDevices(): IDevice[];
102
+ set bleDevices(data: IDevice[]);
103
+ private _lanDevices;
104
+ private get lanDevices();
105
+ private set lanDevices(value);
106
+ private get allDevices();
107
+ private get bleScanDevice();
108
+ private productInfo;
109
+ private currentWifiConfigHandle;
110
+ private _bleHandle;
111
+ private _lanHandle;
112
+ private _gizSocket;
113
+ private offlineThreshold?;
114
+ private syncDataCallBack?;
115
+ private syncDataLengthCallback?;
116
+ private syncTotalNum;
117
+ private syncCurrnetNum;
118
+ private syncDataTimoutTimer;
119
+ private SYNC_TIMEOUT;
120
+ private syncDevice?;
121
+ constructor(props: GizwitsSdkOption);
122
+ private get bleHandle();
123
+ private get lanHandle();
124
+ private get socketHandle();
125
+ private init;
126
+ reInit(props: GizwitsSdkOption): void;
127
+ get specialProductKeys(): string[];
128
+ get specialProductKeySecrets(): string[];
129
+ private handleBleError;
130
+ private handleBleDevices;
131
+ handleLanDevices: (devices: IDevice[]) => void;
132
+ private handleLanDeviceData;
133
+ private handleBleDeviceData;
134
+ private handleSocketDeviceData;
135
+ private handleSocketStatus;
136
+ private notiDeviceList;
137
+ private initLan;
138
+ startAutoScan: (services?: string[]) => void;
139
+ stopAutoScan: () => void;
140
+ setDeviceMeta: <K extends "did" | "mac" | "productKey" | "bleWorkStatus" | "name" | "isBind" | "rootDeviceId" | "bleDeviceID" | "remark" | "passcode" | "connectType" | "isOnline" | "isLanOnline" | "isBleOnline" | "host" | "wss_port" | "ctime">(curDev: IDevice, key: K, value: IDevice[K], force?: boolean) => void;
141
+ static getVersion: () => {
142
+ success: boolean;
143
+ data: string;
144
+ };
145
+ initBle: () => Promise<ISDKResult<null>>;
146
+ scanBleDevice: (delay: number, services?: string[]) => Promise<ISDKResult<IDevice[]>>;
147
+ write: (device: IDevice, attrs: object) => Promise<import("./wechatApi").IWechatResult | {
148
+ success: boolean;
149
+ message: string;
150
+ } | {
151
+ success: boolean;
152
+ message?: undefined;
153
+ }>;
154
+ writeRaw: (device: IDevice, data: number[]) => Promise<IError | import("./wechatApi").IWechatResult | {
155
+ success: boolean;
156
+ }>;
157
+ setDeviceTimeStamp: (device: IDevice) => Promise<import("./wechatApi").IWechatResult | {
158
+ success: boolean;
159
+ message: string;
160
+ }>;
161
+ syncDeviceData: (device: IDevice, callback?: SyncCallBack) => Promise<import("./wechatApi").IWechatResult | {
162
+ success: boolean;
163
+ message: string;
164
+ }>;
165
+ queryNeedSyncDataLength: (device: IDevice) => Promise<ISDKResult<number>>;
166
+ cancelSyncDeviceData: () => Promise<void>;
167
+ private cleanSyncDeviceData;
168
+ getProductConfig: (pk: string) => Promise<ISDKResult<IDataPointConfig>>;
169
+ stopScanBleDevice: () => void;
170
+ login: (openID: string) => Promise<ISDKResult<ILoginRes>>;
171
+ getDeviceStatus: (device: IDevice, attrNames?: string[]) => Promise<import("./wechatApi").IWechatResult | {
172
+ success: boolean;
173
+ }>;
174
+ subscribe: (device: IDevice, connectType?: TConnectType, _autoGetDeviceStatus?: boolean) => Promise<{
175
+ success: boolean;
176
+ message: any;
177
+ } | {
178
+ success: boolean;
179
+ errorCode: IError;
180
+ } | IResult<any>>;
181
+ unSubscribe: (device: IDevice) => Promise<{
182
+ success: boolean;
183
+ }>;
184
+ bindRemoteDevice: ({ mac, productKey, alias, beOwner, }: IBindRemoteDeviceParams) => Promise<ISDKResult<IOpenApiDevice>>;
185
+ unbindDevice: ({ devices, }: {
186
+ devices: IDevice[];
187
+ }) => Promise<ISDKResult<IUnbindReturn>>;
188
+ deviceSafetyRegister: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
189
+ deviceSafetyUnbind: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
190
+ setDeviceOnboardingDeploy: ({ ssid, password, mode, timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<ISDKResult<IDevice[]>>;
191
+ private setDomain;
192
+ private deviceSafetyApi;
193
+ getBindingList: () => Promise<import("./openApiRequest").IServiceResult<IDevice[]>>;
194
+ getDevices: () => Promise<ISDKResult<IDevice[]>>;
195
+ stopDeviceOnboardingDeploy: () => void;
196
+ setLogLevel: (level: TLogType) => {
197
+ success: boolean;
198
+ err: IError;
199
+ };
200
+ renameDevice: (device: IDevice, name: string) => Promise<import("./openApiRequest").IServiceResult<import("./services/devices").IRenamePropsReturn> | {
201
+ success: boolean;
202
+ message: string;
203
+ }>;
204
+ removeEventListener: <K extends "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange" | "onBleHandleError">(type: K, func: TListenerType[K]) => {
205
+ success: boolean;
206
+ };
207
+ addEventListener: <K extends "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange" | "onBleHandleError">(type: K, func: TListenerType[K]) => Promise<{
208
+ success: boolean;
209
+ }>;
210
+ destory: () => void;
211
+ }
212
+ export default GizwitsMiniSDK;
@@ -28,8 +28,8 @@ export declare const getFirstConnectType: (device: IDevice, type?: TConnectType)
28
28
  export declare const getProductInfoThroughPK: (pk: string, productInfos: IProductInfo[]) => IProductInfo;
29
29
  export declare const mergeObject: (obj1: any, obj2: any) => any;
30
30
  export declare function hex2ab(str: any): Uint8Array;
31
- type BroadcastCmd = 0x19 | 0x94;
32
- type TBoradcastRes = {
31
+ declare type BroadcastCmd = 0x19 | 0x94;
32
+ declare type TBoradcastRes = {
33
33
  mac: string;
34
34
  cmd: BroadcastCmd;
35
35
  data: string[];
@@ -1,6 +1,6 @@
1
1
  import { IRandomCodesResult, IResult } from "../sdk";
2
- import { BleHandle } from "../handler/ble";
3
2
  import ConfigBase from "./ConfigBase";
3
+ import { BleHandle } from "../handler/ble";
4
4
  interface IArgs {
5
5
  bleDeviceId: string;
6
6
  arrayBuffer: ArrayBuffer;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.2.30",
4
- "description": "修正flag转换",
3
+ "version": "3.3.2",
4
+ "description": "增加代理蓝牙设备重置功能",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
7
  "test": "node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
8
8
  "testBle": "node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s",
9
- "build": "rm -rf ./dist && webpack",
9
+ "build": "rm -r ./dist && webpack",
10
10
  "release": "npm run build && release-it",
11
11
  "cover": "istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
12
12
  "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
@@ -31,13 +31,13 @@
31
31
  "chai": "^4.2.0",
32
32
  "coveralls": "^3.0.11",
33
33
  "istanbul": "^1.1.0-alpha.1",
34
- "miniprogram-api-typings": "^3.9.0",
34
+ "miniprogram-api-typings": "^3.5.0",
35
35
  "mocha": "^7.1.1",
36
36
  "release-it": "^14.2.2",
37
37
  "sinon": "^9.2.4",
38
38
  "ts-loader": "^6.2.2",
39
39
  "ts-node": "^8.8.1",
40
- "typescript": "^4.9.5",
40
+ "typescript": "^3.8.3",
41
41
  "uglifyjs-webpack-plugin": "^2.2.0",
42
42
  "webpack": "^4.42.1",
43
43
  "webpack-bundle-analyzer": "^4.5.0",