Skip to content

Devices

airvpn.web.services.devices

DeviceManager

Bases: ClientService

Manages the authenticated user's registered devices.

Wraps the AJAX endpoints behind https://airvpn.org/devices/ to list, edit, renew, and delete the user's devices.

Attributes:

Name Type Description
total_deprecated int

Number of deprecated devices on the account.

devices list[DeviceKey]

All devices currently registered to the account.

add() -> DeviceKey

Register a new device and refresh devices once it appears.

Returns:

Name Type Description
DeviceKey DeviceKey

The newly added device.

delete(device: DeviceKey | str)

Delete an existing device.

Parameters:

Name Type Description Default
device DeviceKey | str

DeviceKey instance or device ID to delete.

required

edit(device: DeviceKey | str, name: str | None = None, description: str | None = None)

Edit a device's name and/or description.

Parameters:

Name Type Description Default
device DeviceKey | str

DeviceKey instance or device ID to edit.

required
name str | None

New name to set for the device, if any.

None
description str | None

New description to set for the device, if any.

None

Raises:

Type Description
ValidationError

If neither name nor description is provided.

edit_request(name, value, **kwargs)

Send a generic edit_<name> action to the endpoint.

Convenience wrapper around request for the common pattern of editing a single field by name.

Parameters:

Name Type Description Default
name

Name of the field to edit; sent as the edit_{name} action.

required
value

New value to set for the field.

required
**kwargs

Additional form fields to send along with the request (e.g. an id or port identifying the target record).

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.

get(device: DeviceKey | str)

Resolve a device to a DeviceKey instance.

Parameters:

Name Type Description Default
device DeviceKey | str

DeviceKey instance or device ID to resolve.

required

Returns:

Type Description

The matching DeviceKey instance.

Raises:

Type Description
ValidationError

If device is a string ID that doesn't match any known device.

poll_update(check_callback: Callable[[list[DeviceKeyDict]], bool])

Poll the server until a condition is met, then refresh devices.

Repeatedly fetches the device manifest, sleeping one second between attempts, until check_callback returns False for the current set of keys, then applies the final result via update.

Parameters:

Name Type Description Default
check_callback Callable[[list[DeviceKeyDict]], bool]

Called with the current list of raw key data on each poll; polling continues while it returns True.

required

renew(device: DeviceKey | str)

Renew an existing device.

Parameters:

Name Type Description Default
device DeviceKey | str

DeviceKey instance or device ID to renew.

required

request(action: str, is_act: bool = False, **kwargs)

Send an AJAX action request to the endpoint.

Automatically attaches the CSRF token (fetching it first if not already known) and requests an AJAX-rendered response.

Parameters:

Name Type Description Default
action str

Name of the action to perform.

required
is_act bool

If the action param is act instead.

False
**kwargs

Additional form fields to send along with the request.

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.

update(data=None)

Refresh devices and total_deprecated from the server.

Parameters:

Name Type Description Default
data

Pre-fetched manifest data to use instead of making a new request. If falsy, the manifest is fetched from the server.

None