airthings-consumer-api
Version:
An unofficial Node.js client library for the Airthings Consumer API.
103 lines • 4.15 kB
TypeScript
import { SensorUnits } from './schemas.js';
import type { Accounts, Devices, SensorResults, SensorResultsRateLimitMetrics } from './schemas.js';
/**
* The Airthings for Consumer API provides secure and authorized access for Airthings
* consumers to retrieve the latest data from their Airthings air quality monitors. Leveraging
* HTTPS and OAuth for enhanced security, this API empowers users to seamlessly access
* real-time information from their Airthings devices, gaining valuable insights into the air
* quality within their environments.
*/
export declare class AirthingsClient {
#private;
/**
* @param opts - The options for the Airthings client, primarily client credentials
*
* @remarks
* Create an Airthings Client ID & Secret at https://consumer-api-doc.airthings.com/dashboard
*
* @example
* ```javascript
* const client = new AirthingsClient({
* clientId: 'clientId',
* clientSecret: 'clientSecret'
* });
* ```
*/
constructor(opts: AirthingsClientOpts);
/**
* List all accounts the current user is member of
*
* @remarks
* Lists all accounts the current user is member of. The data returned by this endpoint
* changes when a user is added or removed from business accounts. It is safe to assume
* that the accountId remains constant for Consumer users. The accountId returned by this
* endpoint is used to fetch the devices and sensors from the other endpoints.
*
* @see [Airthings Consumer API: Accounts](https://consumer-api-doc.airthings.com/api-docs#tag/Accounts)
*
* @throws {@link AirthingsError} If the request fails
*/
getAccounts(): Promise<Accounts>;
/**
* Get all devices connected to a user
*
* @remarks
* List all devices (and their sensor abilities) connected to a user’s account. The data
* returned by this endpoint changes when a device is registered, unregistered or renamed.
*
* @see [Airthings Consumer API: Devices](https://consumer-api-doc.airthings.com/api-docs#tag/Device)
*
* @throws {@link AirthingsError} If the request fails
*
* @example
* ```javascript
* const devicesResponse = await client.getDevices();
* devicesResponse.devices.forEach((device) => {
* console.log(device);
* });
* ```
*/
getDevices(): Promise<Devices>;
/**
* Get sensors for a set of devices
*
* @param unit - The units type sensor values will be returned in, metric or imperial
* @param sn - An optional list of serial numbers to filter the results
*
* @remarks
* Get sensors for a set of devices. The response will contain the latest sensor values for
* the devices. The sensor values are updated depending on the device types sampling
* rate. It is recommended to poll the API at a regular interval to get the latest
* sensor values. The response will be paginated with a maximum of 50 records per page.
*
* @see [Airthings Consumer API: Sensors](https://consumer-api-doc.airthings.com/api-docs#tag/Sensor)
*
* @throws {@link AirthingsError} If the request fails
*
* @example
* ```javascript
* const sensorsResponse = await client.getSensors(SensorUnits.Imperial);
* sensorsResponse.results.forEach((sensor) => {
* console.log(sensor);
* });
* ```
*/
getSensors(unit: SensorUnits, sn?: string[]): Promise<SensorResults>;
/**
* Get rate limit metrics from the last getSensors request
*
* @see [Airthings Consumer API: Rate Limits](https://consumer-api-doc.airthings.com/docs/api/rate-limit)
*/
getSensorsRateLimitMetrics(): SensorResultsRateLimitMetrics;
}
export interface AirthingsClientOpts {
/** Override the default Account ID */
accountId?: string;
/** Client ID created via the Airthings Dashboard */
clientId: string;
/** Client Secret created via the Airthings Dashboard */
clientSecret: string;
}
export declare class AirthingsError extends Error {
}
//# sourceMappingURL=client.d.ts.map