npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

v3.0.117

Published

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

Downloads

213

Readme

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