> For the complete documentation index, see [llms.txt](https://developers.neowit.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.neowit.io/starlark/modules/devices-module.md).

# devices module

## Introduction

The device module is a collection of types and functions that enables the integration to defined Neowit devices in the database.

### Example

This snippet defines a new Device and registers it to the database.

```python
device = devices.Device(
  external_id = "myuniquedeviceid1",
  name = "Temperature room 1",
  vendor = "My sensor vendor",
  model = "My sensor model",
  status = "STATUS_CONNECTED",
  status_reason = "OK"
)
devices.upsert(device)
```

## Types

### Device

A Device represents a Neowit Device. It needs an identifier that is unique among the devices for the specific integration.

#### external\_id: str

The integration unique id of the device.

## Functions

### def Device(external\_id: str, name: str = None, status: str = None, status\_reason: str = None, vendor: str = None, model: str = None) -> Device:

Creates a new Device. External id is the only required attribute, but we recommend that you provide as much information as possible. Status can be of the following values:

* **STATUS\_CONNECTED**: The device is connected.
* **STATUS\_NOT\_CONNECTED**: The device is not connected.
* **STATUS\_UNKNOWN**: The status of the device is not known.

### def upsert(device: Device):

Will register or update the device with the provided attributes. First time this is called, a new device with external\_id will be added to the database. After this the attributes will be updated if there are any changes.
