Table of Contents

Class AirthingsClient

Namespace
Tudormobile.Airthings
Assembly
Tudormobile.Airthings.dll

Provides a client for interacting with the Airthings Consumer API.

public sealed class AirthingsClient : IAirthingsClient, IDisposable
Inheritance
AirthingsClient
Implements
Inherited Members

Remarks

Automatically refreshes OAuth2 access tokens when requests receive unauthorized responses. Token refresh operations are serialized via a semaphore, but no double-check guard is applied. Under concurrent load, two callers may each trigger a sequential refresh. This is acceptable when an output cache limits upstream calls to a low frequency (e.g., once per 30–60 minutes).

Design constraints: This client is bound to a single ClientId / ClientSecret pair supplied at construction time. It does not support per-request credentials and is therefore suited only for single-account, single-user deployments. Pagination of multi-page API responses is not implemented; callers that expect large result sets must account for this limitation.

Constructors

AirthingsClient(HttpClient, string, string, string)

Initializes a new instance of the AirthingsClient class.

public AirthingsClient(HttpClient httpClient, string clientId, string clientSecret, string accessToken = "")

Parameters

httpClient HttpClient

The HTTP client used for API requests. Callers are responsible to dispose of this instance.

clientId string

The client ID for authentication.

clientSecret string

The client secret for authentication.

accessToken string

The optional access token. Defaults to an empty string.

Remarks

Callers can provide an optional access token from previous sessions, and also read and store refreshed tokens after successful API calls. Callers are responsible to managing the lifecycle of the provided HttpClient instance, including disposal. The client will not dispose of the provided HttpClient instance.

Properties

AccessToken

Gets the access token, which was possibly refreshed.

public string AccessToken { get; }

Property Value

string

Methods

Dispose()

public void Dispose()

ListAccounts(CancellationToken)

Lists all accounts accessible with the current credentials.

public Task<AccountsResponse> ListAccounts(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<AccountsResponse>

A task representing the asynchronous operation. The task result contains the accounts response with a list of accounts.

ListDevices(string, CancellationToken)

Lists all devices associated with the specified account.

public Task<DevicesResponse> ListDevices(string accountId, CancellationToken cancellationToken = default)

Parameters

accountId string

The unique identifier of the account.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DevicesResponse>

A task representing the asynchronous operation. The task result contains the devices response with a list of devices.

ReadSensors(string, IEnumerable<string>, UnitsType, CancellationToken)

Reads sensor data from the specified devices.

public Task<DevicesSamplesResponse> ReadSensors(string accountId, IEnumerable<string> serialNumbers, UnitsType unitsType = UnitsType.Metric, CancellationToken cancellationToken = default)

Parameters

accountId string

The unique identifier of the account.

serialNumbers IEnumerable<string>

The serial numbers of the devices to read sensor data from.

unitsType UnitsType

The units type for the sensor data (e.g., Metric or Imperial).

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DevicesSamplesResponse>

A task representing the asynchronous operation. The task result contains the sensors response with sensor data.