---
name: "getDeviceInfo"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "1.2.6" }
  - { name: "@ray-js/ray", version: "0.6.23" }
platform:
  - "iOS"
  - "Android"
async: true
title: "getDeviceInfo - 获取设备的设备信息"
summary: "getDeviceInfo 用于获取涂鸦智能设备的完整信息，支持跨面板查询任意设备。返回数据涵盖：设备基础信息（设备名称、devId、uuid、productId、category、icon、固件版本 verSw、激活时间 activeTime）、在线状态（isOnline、isLocalOnline、isCloudOnline、connectionStatus）、功能点数据（dps、dpCodes、dpName、schema 功能定义）、产品能力标志（capability、attribute、baseAttribute、devAttribute、bizAttribute、protocolAttribute）、网络与位置信息（ip、latitude、longitude、mac、hasWifi）、设备类型判断（isGW 网关、isMatter、isTripartiteMatter、isZigBeeSubDev、isShare 分享设备、isVirtualDevice 虚拟设备）、蓝牙 Mesh 信息（meshId、nodeId、parentId、pcc、bluetoothCapability）、面板配置（panelConfig、configMetas、meta）及扩展能力（isSupportGroup、isSupportOTA、isSupportLink、isSupportAppleHomeKit、extModuleType）。适用场景：读取设备状态、判断设备类型和能力、获取产品 schema、跨面板查询设备信息。需引入 DeviceKit，版本 >=1.2.6。"
question:
  - "如何获取设备在线状态? 可以通过getDeviceInfo的 isOnline (设备总的在线情况) / isCloudOnline (设备云端在线情况) / isLocalOnline (本地局域网是否在线) 字段进行判断"
---

## getDeviceInfo

> [VERSION] DeviceKit >= 1.2.6 | @ray-js/ray >= 0.6.23

> [PLATFORM] iOS, Android

> ⚡ **支持 Promise 调用** — 不传 success / fail / complete 回调时，该方法返回 Promise。

### 描述

获取设备的设备信息

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `deviceId` | `string` | 是 | - | `4.11.0` | deviceId 设备id 支持跨面板获取其他的设备信息，当前面板可以传当前设备的 id 来进行获取 |
| `dps` | `Record<string, Record<string, any>>` | 否 | - | `4.11.0` | dps |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### success 回调参数

| 属性 | 类型 | 最低版本 | 描述 |
| --- | --- | --- | --- |
| `roomName` | `string` | `3.6.0` | 设备所处房间名 |
| `schema` | `Record<string, any>[]` | `3.3.0` | 产品信息，schema，功能定义都在里面 |
| `dps` | `Record<string, Record<string, any>>` | `3.3.0` | dps 设备的功能点状态，可以根据对应的 dpid 拿到具体的状态值去做业务逻辑 |
| `attribute` | `number` | `3.3.0` | attribute 产品属性定义，在 backend-ng 平台上可查到对应配置，使用二进制位运算的方式进行管理 |
| `baseAttribute` | `number` | `3.5.0` | baseAttribute 基础产品属性定义 |
| `capability` | `number` | `3.3.0` | capability 产品能力值，在 backend-ng 平台上可以查询对应的勾选项，整体业务逻辑会根据该数据进行划分 区分设备类型也可以根据该属性进行调整，按二进制位运算的方式进行管理 |
| `dpName` | `Record<string, string>` | `3.3.0` | dpName 自定义 dp 的名字，通常在面板里会使用到 |
| `ability` | `number` | `3.3.0` | ability 目前业务很少使用，用于区分特殊类型的设备 |
| `icon` | `string` | `3.3.0` | icon 设备的 icon url |
| `devId` | `string` | `3.3.0` | devId 设备的唯一 id |
| `verSw` | `string` | `3.3.0` | verSw 设备固件版本号 |
| `isShare` | `boolean` | `3.3.0` | isShare 是否为分享设备，true 则是分享设备 |
| `bv` | `string` | `3.3.0` | bv 设备的基线版本号 |
| `uuid` | `string` | `3.3.0` | uuid 设备的固件唯一标识 |
| `panelConfig` | `Record<string, Record<string, any>>` | `3.3.0` | panelConfig 产品面板里的配置项，通常在 IoT 平台上可以查看到对应的配置 |
| `activeTime` | `number` | `3.3.0` | activeTime 设备激活时间，时间戳 |
| `devAttribute` | `number` | `3.3.0` | devAttribute 设备的业务能力拓展，二进制位的方式进行运算 |
| `pcc` | `string` | `3.3.0` | pcc Thing自研蓝牙 mesh 产品的分类标识 |
| `nodeId` | `string` | `3.3.0` | nodeId 子设备的短地址 |
| `parentId` | `string` | `3.3.0` | parentId 上级节点 id，子设备/或蓝牙 mesh 设备通常会有该字段，用于内部寻找相关的网关或上级模型来进行业务处理 |
| `category` | `string` | `3.3.0` | category 产品的分类 |
| `standSchemaModel` | `Record<string, any>` | `3.3.0` | standSchemaModel 标准产品功能集定义模型 |
| `productId` | `string` | `3.3.0` | productId 设备对应的产品 id |
| `productVer` | `string` | `4.3.6` | productVer 设备对应的产品的版本号 |
| `bizAttribute` | `number` | `3.3.0` | bizAttribute 业务属性能力 |
| `meshId` | `string` | `3.3.0` | meshId 当前设备对应的蓝牙 mesh id |
| `sigmeshId` | `string` | `3.3.0` | 【废弃】sigmeshId 当前设备所属行业属性对应的蓝牙 mesh id |
| `meta` | `Record<string, Record<string, any>>` | `3.3.0` | meta 设备自定义配置元属性，用于存放业务数据 |
| `isLocalOnline` | `boolean` | `3.3.0` | isLocalOnline 本地局域网是否在线 |
| `isCloudOnline` | `boolean` | `3.3.0` | 设备云端在线情况 |
| `isOnline` | `boolean` | `3.3.0` | isOnline 设备总的在线情况，只要一个情况在线，就是在线，复合在线情况 |
| `name` | `string` | `3.3.0` | name 设备名称 |
| `groupId` | `string` | `3.3.0` | groupId 设备所属群组 id，非群组场景下为空字符串 |
| `dpCodes` | `Record<string, Record<string, any>>` | `3.3.0` | dpCodes 标准功能集 code |
| `devTimezoneId` | `string` | `3.3.0` | 时区信息 |
| `dpsTime` | `Record<string, Record<string, any>>` | `3.3.0` | 设备的功能点执行的时间 |
| `latitude` | `string` | `3.3.0` | 设备纬度 |
| `longitude` | `string` | `3.3.0` | 设备经度 |
| `ip` | `string` | `3.3.0` | 设备ip地址 |
| `isVirtualDevice` | `boolean` | `3.3.0` | 是否为虚拟设备 |
| `isZigbeeInstallCode` | `boolean` | `3.3.0` | 是否为 Zigbee 安装码网关 |
| `protocolAttribute` | `number` | `3.3.0` | 子设备激活能力标志位 |
| `connectionStatus` | `number` | `3.3.0` | 连接状态，nearby状态 |
| `mac` | `string` | `3.3.0` | 部分设备需要用mac进行唯一识别 ，比如mesh |
| `bluetoothCapability` | `string` | `3.3.0` | 蓝牙的设备能力值，由设备进行上报 |
| `isTripartiteMatter` | `boolean` | `3.6.0` | 是否三方matter设备 |
| `isGW` | `boolean` | `3.6.0` | 是否网关设备 |
| `isSupportGroup` | `boolean` | `3.6.0` | 是否支持群组 |
| `isZigBeeSubDev` | `boolean` | `3.6.0` | 是否zigbee子设备 |
| `cadv` | `string` | `3.6.0` | cadv版本号 |
| `isSupportOTA` | `boolean` | `3.6.0` | 设备是否支持OTA |
| `iconUrl` | `string` | `3.6.0` | 设备图标 |
| `hasWifi` | `boolean` | `3.6.0` | 设备是否有Wi-Fi模块 |
| `switchDp` | `number` | `3.7.0` | 快捷控制dp |
| `switchDps` | `number[]` | `3.7.0` | 快捷控制dp |
| `wifiEnableState` | `number` | `4.0.0` | 设备Wi-Fi模块的状态：1:不可用 2:可用 |
| `configMetas` | `Record<string, Record<string, any>>` | `4.0.0` | 设备产品配置 |
| `isMatter` | `boolean` | `4.0.0` | 是否为matter设备 |
| `isSupportLink` | `boolean` | `4.0.0` | 设备是否支持双控 |
| `isSupportAppleHomeKit` | `boolean` | `4.0.0` | 是否支持将设备添加到苹果家庭中 |
| `attributeString` | `string` | `4.0.0` | attribute 格式化的二进制字符串 产品属性定义，在 backend-ng 平台上可查到对应配置，使用二进制位运算的方式进行管理 |
| `extModuleType` | `number` | `4.3.4` | 设备的扩展模块的类型 0：无扩展模块 1：表示存在扩展模块，即设备为ble+x的设备 2：扩展模块为Wi-Fi模块。即设备为ble+Wi-Fi的设备 |
| `isRelayOpen` | `boolean` | `4.6.1` | mesh设备的relay功能是否开启 |
| `isProxyOpen` | `boolean` | `4.6.1` | mesh设备的proxy功能是否开启 |
| `isSupportProxyAndRelay` | `boolean` | `4.6.1` | mesh设备是否支持proxy和relay功能 |
| `yuNetState` | `number` | `4.11.0` | 设备大禹通道用户启用状态，0-不启用，1-启用 |

#### fail 回调参数

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorMsg` | `string` | 错误信息 |
| `errorCode` | `string \| number` | 错误码 |
| `innerError` | `Object` | 错误扩展 |

##### fail(params).innerError 的属性

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `string \| number` | 错误扩展码 |
| `errorMsg` | `string` | 错误扩展信息 |


### 示例代码

#### 基础调用

```tsx
import { device } from '@ray-js/ray'

const { getDeviceInfo } = device;

getDeviceInfo({
  deviceId: 'device_001',
  success: (result) => {
    console.log('getDeviceInfo success', result);
  },
  fail: (error) => {
    console.log('getDeviceInfo fail', error.errorMsg);
  },
});
```
