Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice

Package Overview
Dependencies
2
Maintainers
5
Versions
91
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice

腾讯云物联网开发平台应用开发小程序Sdk同步网关子设备插件


Version published
Weekly downloads
6
decreased by-89.09%
Maintainers
5
Install size
6.71 MB
Created
Weekly downloads
 

Readme

Source

qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice

腾讯云物联网开发平台应用开发小程序Sdk同步网关子设备插件

由于设备与家庭的绑定关系和网关及子设备的拓扑关系是两个不同的关联关系,所以可能会有两边不同步的情况出现。

例:

  1. 网关从家庭解绑,所有子设备都会从家庭解绑,但是网关-子设备的拓扑关系还存在,所以当网关重新绑定到家庭后,其下的子设备并不会自动重新绑定到家庭,此时需要调用插件方法来执行同步操作

  2. 网关直接向物联通通信侧申请解绑子设备,当时这时客户端并没有打开,就会出现子设备任然绑定在家庭中,但是其拓扑关系已解除,此时也需要调用插件方法来执行同步移除多余子设备的操作

安装依赖

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.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

FAQs

Last updated on 15 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc