node-red-contrib-mobius-flow-thingsboard
Version:
Node-RED nodes to work with MOBiUSFlow and ThingsBoard.io
289 lines (288 loc) • 11.4 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
export interface IThingsboardHttpClient {
Ready: Promise<any>;
on(type: 'connectionError', callback: () => void): any;
/**
* Reset the token refresh timer and stop calls to Thingsboard
*/
closeHttpConnection(): any;
/**
* Get a Map containing all of the registered devices for a customer
* @param detailed Optional property. Set true to get a detailed entry for each device
* @returns A promise which resolves with a Map of all the registered devices
*/
getRegisteredDevices(detailed?: boolean): Promise<Map<string, {
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>>;
/**
* Add a new device to Thingsboard
* @param name The new device name
* @param type The new device type
* @param label The new device label
* @param description The new device description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the device details
*/
addDevice(name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Update a Thingsboard device
* @param deviceId The Thingsboard device ID of the existing device
* @param name The device name
* @param type The device type
* @param label The device label
* @param description new device description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the device details
*/
updateDevice(deviceId: string, name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Add or update a Thingsboard device's attributes
* @param deviceId The Thingsboard device Id
* @param attributes The attributes to add / update as key value pairs
* @param scope The attribute's scope (Server, Shared or Client)
* @returns A void promise
*/
updateDeviceAttributes(deviceId: string, attributes: {
[key: string]: string | number | boolean;
}, scope: 'SERVER_SCOPE' | 'SHARED_SCOPE' | 'CLIENT_SCOPE'): Promise<void>;
/**
* Add or update a Thingsboard device's telemetry
* @param deviceId The Thingsboard device Id
* @param telemetry The telemetry to add / update as key value pairs
* @returns A void promise
*/
updateDeviceTelemetry(deviceId: string, telemetry: {
[key: string]: string | number | boolean;
}): Promise<void>;
/**
* Get a Map containing all of the registered assets for a customer
* @param detailed Optional property. Set true to get a detailed entry for each asset
* @returns A promise which resolves with a Map of all the registered assets
*/
getRegisteredAssets(detailed?: boolean): Promise<Map<string, {
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>>;
/**
* Add a new asset to Thingsboard
* @param name The new asset name
* @param type The new asset type
* @param label The new asset label
* @param description The new asset description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the asset details
*/
addAsset(name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Update a Thingsboard asset
* @param deviceId The Thingsboard asset ID of the existing asset
* @param name The asset name
* @param type The asset type
* @param label The asset label
* @param description The asset description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the asset details
*/
updateAsset(assetId: string, name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Add or update a Thingsboard assets's attributes
* @param assetId The Thingsboard asset Id
* @param attributes The attributes to add / update as key value pairs
* @returns A void promise
*/
updateAssetAttributes(assetId: string, attributes: {
[key: string]: string | number | boolean;
}): Promise<void>;
/**
* Add or update a Thingsboard assets's telemetry
* @param assetId The Thingsboard asset Id
* @param telemetry The telemetry to add / update as key value pairs
* @returns A void promise
*/
updateAssetTelemetry(assetId: string, telemetry: {
[key: string]: string | number | boolean;
}): Promise<void>;
}
export declare class ThingsboardHttpClient extends EventEmitter implements IThingsboardHttpClient {
private axiosInstance;
private customerId;
private username;
private password;
thingsboardToken: string;
private httpTokenRefreshTimer;
Ready: Promise<any>;
/**
*
* @param siteURL The Thingsboard site URL without https://
* @param customerId The customer ID for this connection
* @param username The username used for auth with Thingsboard
* @param password The password used for auth with Thingsboard
*/
constructor(siteURL: string, customerId: string, username: string, password: string);
/**
* Reset the token refresh timer and stop calls to Thingsboard
*/
closeHttpConnection(): void;
/**
* Get a Thingsboard access token
* @returns A void promise
*/
private getHttpTokenFromTB;
/**
* Refresh the Thingsboard access token
*/
private refreshHttpTokenFromTB;
/**
* Get a Map containing all of the registered devices for a customer
* @param detailed Optional property. Set true to get a detailed entry for each device
* @returns A promise which resolves with a Map of all the registered devices
*/
getRegisteredDevices(detailed?: boolean): Promise<Map<string, {
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>>;
/**
* Get the access token for a Thingsboard device
* @param deviceId The Thingsboard device Id
* @returns A promise which resolves with the Thingsboard device access token
*/
private getDeviceAccessToken;
/**
* Add a new device to Thingsboard
* @param name The new device name
* @param type The new device type
* @param label The new device label
* @param description The new device description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the device details
*/
addDevice(name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Update a Thingsboard device
* @param deviceId The Thingsboard device ID of the existing device
* @param name The device name
* @param type The device type
* @param label The device label
* @param description new device description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the device details
*/
updateDevice(deviceId: string, name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Add or update a Thingsboard device's attributes
* @param deviceId The Thingsboard device Id
* @param attributes The attributes to add / update as key value pairs
* @param scope The attribute's scope (Server, Shared or Client)
* @returns A void promise
*/
updateDeviceAttributes(deviceId: string, attributes: {
[key: string]: string | number | boolean;
}, scope: 'SERVER_SCOPE' | 'SHARED_SCOPE' | 'CLIENT_SCOPE'): Promise<void>;
/**
* Add or update a Thingsboard device's telemetry
* @param deviceId The Thingsboard device Id
* @param telemetry The telemetry to add / update as key value pairs
* @returns A void promise
*/
updateDeviceTelemetry(deviceId: string, telemetry: {
[key: string]: string | number | boolean;
}): Promise<void>;
/**
* Get a Map containing all of the registered assets for a customer
* @param detailed Optional property. Set true to get a detailed entry for each asset
* @returns A promise which resolves with a Map of all the registered assets
*/
getRegisteredAssets(detailed?: boolean): Promise<Map<string, {
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>>;
/**
* Add a new asset to Thingsboard
* @param name The new asset name
* @param type The new asset type
* @param label The new asset label
* @param description The new asset description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the asset details
*/
addAsset(name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Update a Thingsboard asset
* @param deviceId The Thingsboard asset ID of the existing asset
* @param name The asset name
* @param type The asset type
* @param label The asset label
* @param description The asset description
* @param detailed Optional property. Set true to get a detailed response
* @returns A promise which resolves with the asset details
*/
updateAsset(assetId: string, name: string, type: string, label: string, description?: string, detailed?: boolean): Promise<{
id: string;
type?: string;
label?: string;
description?: string | undefined;
}>;
/**
* Add or update a Thingsboard assets's attributes
* @param assetId The Thingsboard asset Id
* @param attributes The attributes to add / update as key value pairs
* @returns A void promise
*/
updateAssetAttributes(assetId: string, attributes: {
[key: string]: string | number | boolean;
}): Promise<void>;
/**
* Add or update a Thingsboard assets's telemetry
* @param assetId The Thingsboard asset Id
* @param telemetry The telemetry to add / update as key value pairs
* @returns A void promise
*/
updateAssetTelemetry(assetId: string, telemetry: {
[key: string]: string | number | boolean;
}): Promise<void>;
}