mini_program_gizwits_sdk 3.1.20-1 → 3.1.20-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.
- package/package.json +1 -1
- package/src/handler/socket.ts +5 -0
- package/src/productConfigFileManage.ts +14 -0
- package/src/sdk.ts +16 -1
package/package.json
CHANGED
package/src/handler/socket.ts
CHANGED
|
@@ -70,6 +70,11 @@ export default class GizwitsWS {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
updateToken = ({token, uid}) => {
|
|
74
|
+
this.token = token;
|
|
75
|
+
this.uid = uid;
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
_getDevice = (did: string): IDevice | IError => {
|
|
74
79
|
if (this._bindingDevices === null) {
|
|
75
80
|
return errorCode.GIZ_SDK_SDK_NOT_INITIALIZED
|
|
@@ -36,6 +36,20 @@ class ProductConfigFileManage {
|
|
|
36
36
|
}
|
|
37
37
|
return this.data[pk];
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
public getAttrItem = async (pk:string, key: string) => {
|
|
41
|
+
if (!this.data[pk]) {
|
|
42
|
+
await this.getConfigFile(pk)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (let index in this.data[pk].entities[0].attrs) {
|
|
46
|
+
const item = this.data[pk].entities[0].attrs[index]
|
|
47
|
+
if (item.name === key) {
|
|
48
|
+
return item;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
const productConfigFileManage = new ProductConfigFileManage();
|
package/src/sdk.ts
CHANGED
|
@@ -353,7 +353,7 @@ class GizwitsMiniSDK {
|
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
355
|
|
|
356
|
-
private handleSocketDeviceData: IOnDeviceStatusChanged = (data) => {
|
|
356
|
+
private handleSocketDeviceData: IOnDeviceStatusChanged = async (data) => {
|
|
357
357
|
const target = this.allDevices.find((item) => item.did === data.did);
|
|
358
358
|
if (!target) {
|
|
359
359
|
return;
|
|
@@ -364,12 +364,26 @@ class GizwitsMiniSDK {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
if (this.listenerMap['GizDeviceAttrsNotifications']) {
|
|
367
|
+
|
|
368
|
+
// 需要把枚举格式化回来
|
|
369
|
+
|
|
370
|
+
if ((data as IDeviceStatusChangedProps).attrs) {
|
|
371
|
+
for(let key in (data as IDeviceStatusChangedProps).attrs) {
|
|
372
|
+
const itemData = await productConfigFileManage.getAttrItem(target.productKey, key);
|
|
373
|
+
if (itemData.data_type ==='enum') {
|
|
374
|
+
const enumIndex = itemData.enum.findIndex(item => item === (data as IDeviceStatusChangedProps).attrs[key]);
|
|
375
|
+
(data as IDeviceStatusChangedProps).attrs[key] = enumIndex || 0;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
367
379
|
this.listenerMap['GizDeviceAttrsNotifications'].map((item) => {
|
|
368
380
|
item({
|
|
369
381
|
device: target,
|
|
370
382
|
...('attrs' in data ? { data: data.attrs } : { raw: data.raw }),
|
|
371
383
|
});
|
|
372
384
|
});
|
|
385
|
+
|
|
386
|
+
|
|
373
387
|
}
|
|
374
388
|
};
|
|
375
389
|
|
|
@@ -609,6 +623,7 @@ class GizwitsMiniSDK {
|
|
|
609
623
|
if (data.success) {
|
|
610
624
|
setGlobalData('token', data.data?.token);
|
|
611
625
|
setGlobalData('uid', data.data?.uid);
|
|
626
|
+
this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
|
|
612
627
|
}
|
|
613
628
|
return data;
|
|
614
629
|
};
|