# 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.


---

# 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://developers.neowit.io/starlark/modules/devices-module.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.
