---
name: "validDeviceOnlineType"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "1.2.6" }
  - { name: "@ray-js/ray", version: "0.6.23" }
platform:
  - "iOS"
  - "Android"
async: true
title: "validDeviceOnlineType - 判断设备上网类型是否与 deviceModel 物模型一致"
---

## validDeviceOnlineType

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

> [PLATFORM] iOS, Android

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

### 描述

判断指定在线类型（onlineType）是否与设备物模型定义的上网方式一致

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `deviceId` | `string` | 是 | - | `1.2.6` | 设备id |
| `onlineType` | `number` | 是 | - | `1.2.6` | 设备网络在线类型，位运算方式表示，多种在线状态复合，定义如下： bit 0 (1 << 0): Wi-Fi online，(云端在线 \|\| 局域网在线)，若只想判断云端在线，建议使用 bit:7 bit 1 (1 << 1): Local online，局域网在线 bit 2 (1 << 2): BLE online，蓝牙在线 bit 3 (1 << 3): BLEMesh online，蓝牙mesh在线 bit 4 (1 << 4): beacon online，beacon在线 bit 5 (1 << 5): Dayu online，大禹在线 bit 6 (1 << 6): System BT Online，系统蓝牙在线 bit 7 (1 << 7): Cloud online，云端在线 bit 8 (1 << 8): Matter online，Matter 本地在线 |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `(params: boolean) => void` | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### fail 回调参数

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

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

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


### 示例代码

#### 基础调用

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

const { validDeviceOnlineType } = device;

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