tsvesync
Version:
A TypeScript library for interacting with VeSync smart home devices
160 lines (159 loc) • 4.78 kB
TypeScript
/**
* VeSync API Device Library
*/
import { Session, SessionStore } from './session';
import { VeSyncBaseDevice } from './vesyncBaseDevice';
import { Logger } from './logger';
/**
* Device exclusion configuration
*/
export interface ExcludeConfig {
type?: string[];
model?: string[];
name?: string[];
namePattern?: string[];
id?: string[];
}
/**
* VeSync Manager Class
*/
export declare class VeSync {
private _debug;
private _redact;
private _energyUpdateInterval;
private _energyCheck;
private _devList;
private _lastUpdateTs;
private _inProcess;
private _excludeConfig;
private _appId;
private _region;
private _countryCodeOverride;
private _apiUrlOverride;
private _sessionStore?;
private _onTokenChange?;
private _loginPromise;
username: string;
password: string;
token: string | null;
accountId: string | null;
countryCode: string | null;
devices: VeSyncBaseDevice[] | null;
enabled: boolean;
updateInterval: number;
timeZone: string;
authFlowUsed?: 'legacy' | 'new';
apiBaseUrl?: string;
fans: VeSyncBaseDevice[];
outlets: VeSyncBaseDevice[];
switches: VeSyncBaseDevice[];
bulbs: VeSyncBaseDevice[];
scales: VeSyncBaseDevice[];
/**
* Initialize VeSync Manager
* @param username - VeSync account username
* @param password - VeSync account password
* @param timeZone - Optional timezone for device operations (defaults to America/New_York)
* @param optionsOrDebug - Either options object or debug flag for backward compatibility
* @param redact - Optional redact mode flag (used when optionsOrDebug is boolean)
* @param apiUrl - Optional API base URL override (used when optionsOrDebug is boolean)
* @param customLogger - Optional custom logger implementation (used when optionsOrDebug is boolean)
* @param excludeConfig - Optional device exclusion configuration (used when optionsOrDebug is boolean)
*/
constructor(username: string, password: string, timeZone?: string, optionsOrDebug?: boolean | {
debug?: boolean;
redact?: boolean;
apiUrl?: string;
customLogger?: Logger;
excludeConfig?: ExcludeConfig;
region?: string;
countryCode?: string;
debugMode?: boolean;
sessionStore?: SessionStore;
onTokenChange?: (session: Session) => void;
}, redact?: boolean, apiUrl?: string, customLogger?: Logger, excludeConfig?: ExcludeConfig);
/**
* Hydrate manager from a previously persisted session
*/
hydrateSession(session: Session): void;
private emitTokenChange;
/**
* Get/Set debug mode
*/
get debug(): boolean;
set debug(flag: boolean);
/**
* Get/Set redact mode
*/
get redact(): boolean;
set redact(flag: boolean);
/**
* Get/Set energy update interval
*/
get energyUpdateInterval(): number;
set energyUpdateInterval(interval: number);
/**
* Get current App ID
*/
get appId(): string;
/**
* Get current region
*/
get region(): string;
/**
* Return the configured API URL override, if any.
*/
get apiUrlOverride(): string | null;
/**
* Set region and update API endpoint
*/
set region(region: string);
/**
* Test if device should be removed
*/
static removeDevTest(device: VeSyncBaseDevice, newList: any[]): boolean;
/**
* Test if new device should be added
*/
addDevTest(newDev: Record<string, any>): boolean;
/**
* Remove devices not found in device list return
*/
removeOldDevices(devices: any[]): boolean;
/**
* Correct devices without cid or uuid
*/
static setDevId(devices: any[]): any[];
/**
* Process devices from API response
*/
private processDevices;
/**
* Get list of VeSync devices
*/
getDevices(): Promise<boolean>;
/**
* Login to VeSync server with new authentication flow and backwards compatibility
*/
login(retryAttempts?: number, initialDelayMs?: number): Promise<boolean>;
/**
* Test if update interval has been exceeded
*/
deviceTimeCheck(): boolean;
/**
* Check if a device should be excluded based on configuration
*/
private shouldExcludeDevice;
/**
* Update device list and details
*/
update(): Promise<void>;
/**
* Create device instance from details
*/
createDevice(details: Record<string, any>): VeSyncBaseDevice | null;
/**
* Call API with authentication
*/
protected callApi(endpoint: string, method: string, data?: any, headers?: Record<string, string>): Promise<[any, number]>;
}