# Device

## Function

### IdentifyInfoByKey

Kiểm tra thiết bị với **key** tương ứng có tồn tại trong dự án hay không. Trả về [DeviceInfo](#deviceinfo)

{% code fullWidth="false" %}

```typescript
Device().IdentifyInfoByKey({key: string})
```

{% endcode %}

<details>

<summary>Phiên bản cũ</summary>

```typescript
try {
  let data = await Device().IdentifyInfoByKey({ key: '0000000'});
  let deviceInfo = data.toObject();
} catch (any) {
//handle error not found device
};
```

</details>

<details>

<summary>Phiên bản mới</summary>

```typescript
let res = await Device().IdentifyInfoByKey({ key: '0000000'});
if (res.success){
  // Thiết bị tồn tại 
  let deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

### IdentifyInfoByKeyWithAd

Kiểm tra thiết bị với thông tin **key**, **projectId** có tồn tại hay không. Trả về [DeviceInfo](#deviceinfo)

```typescript
Device().IdentifyInfoByKeyWithAd({key: string, projectId: string})
```

<details>

<summary>Phiên bản cũ</summary>

```typescript
try {
  let data = await Device().IdentifyInfoByKeyWithAd({ key: '0000000', projectId: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'});
  let deviceInfo = data.toObject();
} catch (any) {
  //handle error not found device
};
```

</details>

<details>

<summary>Phiên bản mới</summary>

```typescript
let res = await Device().IdentifyInfoByKeyWithAd({ key: '0000000', projectId: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'});
if (res.success){
  // Thiết bị tồn tại
  let deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

### CreateDevice

Tạo thiết bị với các thông tin tương ứng, trường **name** bắt buộc, còn lại có thể để trống. Nếu tìm thấy trả về [DeviceInfo](#deviceinfo), nếu không Throw Exception

<pre class="language-typescript"><code class="lang-typescript"><strong>Device().CreateDevice({name: string, key: string, templateId: string, orgId: string, groupId: string})
</strong></code></pre>

{% hint style="info" %}
Có thể dùng trường key để lưu định danh thiết bị (imei, serial,...)
{% endhint %}

<details>

<summary>Phiên bản cũ</summary>

```typescript
let createDevice = await Device().CreateDevice({ name: 'new_device', key: '00000');
let deviceInfo= createDevice.toObject();
return deviceInfo;
```

</details>

<details>

<summary>Phiên bản mới</summary>

```typescript
let createDevice = await Device().CreateDevice({ name: 'new_device', key: '00000');
if (createDevice.success){
  // Tạo thiết bị thành công
  let deviceInfo = createDevice.data;
}else{
  // Tạo thiết không bị thành công
}
```

</details>

### IdentifyInfo

Tìm thiết bị với id tương ứng. Nếu tìm thấy trả về [DeviceInfo](#deviceinfo), nếu không Throw Exception

<pre class="language-typescript"><code class="lang-typescript"><strong>Device().IdentifyInfo({id: string})
</strong></code></pre>

<details>

<summary>Phiên bản cũ</summary>

```typescript
let res = await Device().IdentifyInfo({id: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'})
deviceInfo = res.toObject();
return deviceInfo;
```

</details>

<details>

<summary>Phiên bản mới</summary>

```typescript
let res = await Device().IdentifyInfo({id: 'c53f1597-d04a-470f-9f76-3c40a11e43b2'})
if (res.success){
  // Thiết bị tồn tại
  deviceInfo = res.data;
}else{
  // Thiết bị không tồn tại
}
```

</details>

## Type

### DeviceInfo

```typescript
{
    id: string,
    name: string,
    owner: string,
    group: string,
    groupname: string,
    type: string,
    typename: string,
    status: string,
    metadata: Uint8Array | string,
    variablesList: Array<string>,
    orgid: string,
    orgname: string,
    createby: string,
    projectid: string,
    templateid: string,
    key: string,
    thingid: string,
    handlemsgsvc: string,
    additionalinfo: Uint8Array | string,
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://innoway.gitbook.io/innoway/release-note/25-04-2025/device.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
