qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice v3.0.113
qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice
腾讯云物联网开发平台应用开发小程序Sdk同步网关子设备插件
由于设备与家庭的绑定关系和网关及子设备的拓扑关系是两个不同的关联关系,所以可能会有两边不同步的情况出现。
例:
网关从家庭解绑,所有子设备都会从家庭解绑,但是网关-子设备的拓扑关系还存在,所以当网关重新绑定到家庭后,其下的子设备并不会自动重新绑定到家庭,此时需要调用插件方法来执行同步操作
网关直接向物联通通信侧申请解绑子设备,当时这时客户端并没有打开,就会出现子设备任然绑定在家庭中,但是其拓扑关系已解除,此时也需要调用插件方法来执行同步移除多余子设备的操作
安装依赖
npm install qcloud-iotexplorer-appdev-sdk
安装SDK
npm install qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice
使用
step1.向 sdk 里面注册 airkiss 插件,sdk 的初始化方式参考文档qcloud-iotexplorer-appdev-sdk
import PluginSyncGatewaySubdevice from 'qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice';
sdk.usePlugin(PluginSyncGatewaySubdevice);
> step2.执行同步网关子设备操作
用法1:同步单个网关
const deviceList = ....xxxx; // 设备列表
const gatewayDeviceInfo = deviceList.find(item => item.DeviceType === 1)
const { subDeviceList, // 真实子设备列表 diffResult: { add, // 未绑定到家庭的子设备列表 remove, // 多余的子设备列表(已解除拓扑关系但仍绑定在家庭) }, } = await sdk.plugins.syncGatewaySubDevicePlugin.sync(gatewayDeviceInfo.DeviceId); // 知道网关设备id,需要同步其下子设备
// 拿到diffResult后,可以同步到本地UI
add.forEach(({ deviceInfo, success, error }) => { // 新添加到家庭的设备,只处理添加成功的 if (success) { deviceList.push({ ...item, isShareDevice: gatewayDeviceInfo.isShareDevice, }); } else { console.warn('该子设备添加失败', error); } });
remove.forEach(({ deviceInfo, success, error }) => { const index = deviceList.findIndex(deviceInfo => deviceInfo.DeviceId === item.DeviceId);
// 需要删除的,无论操作成功或失败,都从列表中删除
deviceList.splice(index, 1);
console.log('删除子设备', item, index, deviceList);
});
用法2:同步整个家庭的所有网关(注意:需要传入的deviceList需要为某个家庭的全量设备列表,否则无法正确比对子设备关联情况)
const deviceList = ....xxxx; // 设备列表
const { deviceList: newDeviceList, // 真实子设备列表 syncResults: { gatewayDeviceInfo, subDeviceList, diffResult: { add, remove, }; }, ...others , } = await sdk.plugins.syncGatewaySubDevicePlugin.syncByList(deviceList); // 直接传入某个家庭的全量设备列表
// 执行结束后,已处理完整个家庭的网关-子设备同步操作,可以直接用返回的新的 deviceList 来渲染 UI,syncResults 中可以查看具体执行了同步操作的网关及其子设备同步情况
## API
### plugin.sync(gatewayDeviceInfo /* or gatewayDeviceId */): Promise<SyncGatewaySubDeviceResult>
执行某个网关设备的同步子设备操作
#### SyncGatewaySubDeviceResult
* SyncGatewaySubDeviceResult.subDeviceList: any[]; 真实子设备列表
* SyncGatewaySubDeviceResult.diffResult 同步结果,需要拿到对比结果后手动同步到UI,或重新拉取设备列表
* SyncGatewaySubDeviceResult.diffResult.add: SyncGatewaySubDeviceDiffInfo[];
* SyncGatewaySubDeviceResult.diffResult.remove: SyncGatewaySubDeviceDiffInfo[];
* SyncGatewaySubDeviceDiffInfo: { success: boolean; deviceInfo: any; error?: Error }; 同步操作结果
### plugin.syncByList(deviceList): Promise<{ deviceList: any[]; syncResults: SyncGatewaySubDeviceByDeviceListResult[] }>;
批量执行某个家庭的所有网关同步子设备操作。
*注意:需要传入该家庭的全量设备列表,否则无法正确比对设备绑定关系*
#### deviceList: any[]; 同步后的全量设备列表
#### SyncGatewaySubDeviceByDeviceListResult
#### SyncGatewaySubDeviceByDeviceListResult.gatewayDeviceInfo; 网关的设备信息
#### SyncGatewaySubDeviceByDeviceListResult.subDeviceList; 该网关的真实子设备列表
#### SyncGatewaySubDeviceByDeviceListResult.diffResult; 同 SyncGatewaySubDeviceResult.diffResult
28 days ago
3 months ago
3 months ago
4 months ago
4 months ago
6 months ago
7 months ago
8 months ago
8 months ago
9 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago