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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@quec-wx-mp/api-device-group

v1.0.0

Published

设备分组

Readme

设备分组

设备分组模块,提供设备组创建、编辑、删除、查询、设备入组/移组以及批量控制等API。

安装

npm install @quec-wx-mp/api-device-group
import deviceGroup from '@quec-wx-mp/api-device-group'
const plugin = requirePlugin('quecPlugin')

plugin.use(deviceGroup)

API 列表

| 方法 | 说明 | | ------------------------------- | -------------------------- | | addDeviceGroup | 添加设备组 | | addDeviceToGroup | 添加设备到设备组 | | deleteDeviceGroup | 删除设备组 | | deleteDeviceToGroup | 从设备组移除设备 | | deviceGroupInfo | 查询设备组详情 | | deviceGroupList | 查询设备组列表 | | getDeviceGroupList | 根据设备查询设备组列表 | | getDeviceListByNotInDeviceGroup | 查询不在设备组内的设备列表 | | getFamilyGroupList | 查询家庭设备组列表 | | getGroupDeviceList | 查询设备组中的设备列表 | | setDeviceGroup | 修改设备组 | | batchControlDevice | 批量控制设备 |


API 详细说明

1) 添加设备组

接口名称

addDeviceGroup

功能描述

创建一个设备组。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ---------------- | -------- | ------ | ---- | ----------- | | name | string | - | 是 | 分组名称 | | fid | string | - | 否 | 家庭 id | | parentId | string | - | 否 | 父设备组 ID | | address | string | - | 否 | 地址 | | contactPhoneList | string | - | 否 | 联系人 | | coordinate | string | - | 否 | 经纬度 | | coordinateSystem | string | - | 否 | 坐标系 | | description | string | - | 否 | 说明 | | extend | string | - | 否 | 扩展字段 | | manager | string | - | 否 | 管理员 | | managerType | string | - | 否 | 管理员类型 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为新增分组信息。

示例代码

plugin.deviceGroup.addDeviceGroup({
  name: '客厅分组',
  fid: 'family_id',
  address: '北京',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

2) 添加设备到设备组

接口名称

addDeviceToGroup

功能描述

将设备批量加入指定设备组。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | ------------------------------ | | dgid | string | - | 是 | 设备组 id | | list | array | - | 是 | 设备列表,元素格式:{ dk, pk } | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.deviceGroup.addDeviceToGroup({
  dgid: 'group_id',
  list: [{ dk: 'device_key', pk: 'product_key' }],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

3) 删除设备组

接口名称

deleteDeviceGroup

功能描述

根据设备组 id 删除设备组。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------- | | dgid | string | - | 是 | 设备组 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.deviceGroup.deleteDeviceGroup({
  dgid: 'group_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

4) 从设备组移除设备

接口名称

deleteDeviceToGroup

功能描述

将设备从指定设备组中移除。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | ------------------------------ | | dgid | string | - | 是 | 设备组 id | | list | array | - | 是 | 设备列表,元素格式:{ dk, pk } | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.deviceGroup.deleteDeviceToGroup({
  dgid: 'group_id',
  list: [{ dk: 'device_key', pk: 'product_key' }],
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

5) 查询设备组详情

接口名称

deviceGroupInfo

功能描述

查询单个设备组的详细信息。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------- | | dgid | string | - | 是 | 设备组 id | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为设备组详情。

示例代码

plugin.deviceGroup.deviceGroupInfo({
  dgid: 'group_id',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

6) 查询设备组列表

接口名称

deviceGroupList

功能描述

按条件分页查询设备组列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ---------------- | -------- | ------ | ---- | ----------- | | name | string | - | 是 | 分组名称 | | page | number | 1 | 否 | 当前页 | | pageSize | string | 10 | 否 | 页大小 | | dgid | string | - | 否 | 设备组 ID | | parentId | string | - | 否 | 父设备组 ID | | address | string | - | 否 | 地址 | | contactPhoneList | string | - | 否 | 联系人 | | description | string | - | 否 | 说明 | | extend | string | - | 否 | 扩展字段 | | manager | string | - | 否 | 管理员 | | managerType | string | - | 否 | 管理员类型 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为设备组分页列表。

示例代码

plugin.deviceGroup.deviceGroupList({
  name: '客厅',
  page: 1,
  pageSize: '10',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

7) 根据设备查询设备组列表

接口名称

getDeviceGroupList

功能描述

根据设备 dk/pk 查询设备所在设备组列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------------- | | dk | string | - | 是 | 设备 deviceKey | | pk | string | - | 是 | 设备 productKey | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为设备组列表。

示例代码

plugin.deviceGroup.getDeviceGroupList({
  dk: 'device_key',
  pk: 'product_key',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

8) 查询不在设备组内的设备列表

接口名称

getDeviceListByNotInDeviceGroup

功能描述

查询可加入指定设备组的设备列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | --------- | | dgid | string | - | 是 | 设备组 id | | fid | string | - | 否 | 家庭 id | | page | number | 1 | 否 | 当前页 | | pageSize | string | 10 | 否 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为设备列表。

示例代码

plugin.deviceGroup.getDeviceListByNotInDeviceGroup({
  dgid: 'group_id',
  fid: 'family_id',
  page: 1,
  pageSize: '10',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

9) 查询家庭设备组列表

接口名称

getFamilyGroupList

功能描述

分页查询家庭下的设备组列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | fid | string | - | 是 | 家庭 id | | page | number | 1 | 否 | 当前页 | | pageSize | string | 10 | 否 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为家庭设备组列表。

示例代码

plugin.deviceGroup.getFamilyGroupList({
  fid: 'family_id',
  page: 1,
  pageSize: '10',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

10) 查询设备组中的设备列表

接口名称

getGroupDeviceList

功能描述

分页查询某个设备组中的设备列表。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | --------------- | -------- | ------ | ---- | ------------------------------- | | dgid | string | - | 否 | 设备组 ID | | deviceGroupName | string | - | 否 | 设备组名称 | | pk | string | - | 否 | 产品 pk | | dkList | string | - | 否 | dk 列表,多个 dk 用英文逗号分隔 | | page | number | 1 | 否 | 当前页 | | pageSize | string | 10 | 否 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为设备分页列表。

示例代码

plugin.deviceGroup.getGroupDeviceList({
  dgid: 'group_id',
  page: 1,
  pageSize: '10',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

11) 修改设备组

接口名称

setDeviceGroup

功能描述

修改设备组信息。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ---------------- | -------- | ------ | ---- | ------------ | | dgid | string | - | 是 | 设备组 ID | | name | string | - | 是 | 设备组名称 | | parentId | string | - | 否 | 父设备组 ID | | address | string | - | 否 | 地址 | | contactPhoneList | string | - | 否 | 联系人 | | coordinate | string | - | 否 | 经纬度 | | coordinateSystem | string | - | 否 | 坐标系 | | description | string | - | 否 | 说明 | | extend | string | - | 否 | 扩展字段 | | manager | string | - | 否 | 管理员 | | managerType | string | - | 否 | 组管理员类型 | | page | number | 1 | 否 | 当前页 | | pageSize | string | 10 | 否 | 页大小 | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应。

示例代码

plugin.deviceGroup.setDeviceGroup({
  dgid: 'group_id',
  name: '新分组名称',
  address: '上海',
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})

12) 批量控制设备

接口名称

batchControlDevice

功能描述

对设备列表执行批量控制(透传/属性/服务)。

参数

| 属性 | 类型 | 默认值 | 必填 | 说明 | | ---------- | -------- | ------ | ---- | ----------------------------------------- | | data | string | - | 是 | 控制命令,透传时最大 4096 字符 | | deviceList | array | - | 是 | 设备列表,元素格式:{ dk, pk } | | type | number | 2 | 是 | 控制类型(1 透传,2 属性,3 服务) | | dataFormat | number | 2 | 否 | 数据格式(1 Hex,2 Text;透传时建议指定) | | isCache | number | 2 | 否 | 是否启用缓存(1 启用,2 不启用) | | isCover | number | 2 | 否 | 是否覆盖同命令缓存(1 覆盖,2 不覆盖) | | cacheTime | number | 86400 | 否 | 缓存时间,范围 1-7776000 秒 | | qos | number | 1 | 否 | QoS 等级(0 或 1) | | success | function | - | 是 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |

返回数据

  • success(res):接口成功响应,res.data 为批量控制结果。

示例代码

plugin.deviceGroup.batchControlDevice({
  type: 2,
  data: '{"switch":true}',
  dataFormat: 2,
  deviceList: [{ dk: 'device_key', pk: 'product_key' }],
  qos: 1,
  success(res) {
    console.log(res)
  },
  fail(err) {
    console.log(JSON.stringify(err))
  },
  complete() {}
})