import { EventEmitter } from 'events'; import { Logger } from 'homebridge'; import { HaierEvoConfig, DeviceInfo, DeviceStatus, HaierDevice } from './types.js'; interface WebSocketMessage { event?: string; type?: string; macAddress?: string; payload?: unknown; trace?: string; errNo?: number; message?: string; errorMessage?: string; data?: unknown; [key: string]: unknown; } export declare class HaierAPI extends EventEmitter { private config; private log; private http; private ws; private accessToken; private refreshToken; private tokenExpire; private refreshExpire; private deviceCache; private deviceCacheTimestamp; private deviceCacheTTL; private devices; private reconnectTimer; private heartbeatTimer; private pendingStatusTimer; private initialStatusTimer; private pendingStatusRequest; private isConnected; private connectionEstablished; private closing; private wsState; private connectionAttempts; private maxConnectionAttempts; private refreshFailureCount; private maxRefreshFailures; private refreshInProgress; private refreshPromise; private tokenRefreshTimer; private rateLimitConfig; private requestQueue; private isProcessingQueue; private lastRequestTime; private minRequestInterval; private commandBatches; private batchTimeout; private readonly modelConfig; constructor(config: HaierEvoConfig, log: Logger); private generateDeviceId; private getStoredDeviceId; private storeDeviceId; authenticate(): Promise; /** * Sets up token refresh based on configuration */ private setupTokenRefresh; /** * Clears any existing token refresh timer */ private clearTokenRefreshTimer; refreshAccessToken(): Promise; private _refreshAccessToken; fetchDevices(): Promise; /** * Enriches basic device data with complete configuration information * @param devices Basic device data from API_DEVICES * @returns Devices with complete information including model, firmware, serial */ private enrichDevicesWithCompleteInfo; /** * Fetches device configuration without using the main getDeviceStatus cache * This is used during device discovery to build the complete cache */ private getDeviceConfigForEnrichment; /** * Utility function to recursively trim string values in objects and arrays * @param data The data to trim * @returns The trimmed data */ private trimData; private extractDevicesFromUIResponse; private extractDeviceType; private extractSerialNumber; private extractDeviceModel; private extractFirmwareVersion; private isValidDeviceData; getDeviceStatus(mac: string): Promise; processWebSocketStatus(mac: string, wsData: WebSocketMessage): DeviceStatus | null; connectWebSocket(): Promise; private handleWebSocketMessage; private handleStatusEvent; private convertPropertiesToDeviceStatus; private mapOperationMode; private mapFanMode; private mapVerticalSwingMode; private statusRequestTimer; private startHeartbeat; private startStatusRequests; private stopStatusRequests; private requestDeviceStatuses; requestAllDeviceStatuses(): Promise; private stopHeartbeat; private scheduleReconnect; sendCommand(deviceId: string, command: { commandName?: string; values?: string[]; type?: string; deviceId?: string; command?: unknown; timestamp?: number; }): Promise; /** * Set multiple device properties in a single batch request */ setDeviceProperties(macAddress: string, properties: Array<{ propertyId: string; value: string | number | boolean; }>): Promise; /** * Set a single device property with batching support * @param macAddress The MAC address of the device * @param propertyId The ID of the property to set * @param value The value to set */ setDeviceProperty(macAddress: string, propertyId: string, value: string | number | boolean): Promise; /** * Add a command to the batch queue for a device * @param macAddress The MAC address of the device * @param propertyId The ID of the property to set * @param value The value to set * @param resolve Promise resolve function * @param reject Promise reject function */ private addToBatch; /** * Process and send a batch of commands for a device * @param macAddress The MAC address of the device */ private processBatch; /** * Force immediate processing of any pending batches for a device * @param macAddress The MAC address of the device (optional - if not provided, processes all batches) */ flushBatches(macAddress?: string): Promise; /** * Get the current batch timeout setting */ getBatchTimeout(): number; /** * Set the batch timeout (time to wait before sending batched commands) * @param timeoutMs Timeout in milliseconds */ setBatchTimeout(timeoutMs: number): void; /** * Send a WebSocket message and handle the response * @param message The message to send */ private sendWebSocketMessage; disconnect(): Promise; disconnectWebSocket(): Promise; /** * Check if token needs to be refreshed soon (based on configured threshold) */ needsTokenRefresh(): boolean; /** * Check if the current access token is still valid */ isTokenValid(): boolean; /** * Ensures the token is valid and refreshes it if needed */ ensureValidToken(): Promise; isWebSocketConnected(): boolean; isRefreshTokenValid(): boolean; getDeviceMap(): Map; getDevice(deviceId: string): HaierDevice | undefined; private findDeviceIdByMac; private getModelByMac; addDevice(device: HaierDevice): void; private executeWithRateLimit; private handleRateLimitError; private handleRetryError; private getRetryAfterDelay; private calculateRetryDelay; private delay; configureRateLimit(config: Partial<{ maxRetries: number; baseDelay: number; maxDelay: number; jitter: number; respectRetryAfter: boolean; queueRetries: boolean; }>): void; getRateLimitStatus(): { queueLength: number; isProcessingQueue: boolean; lastRequestTime: number; config: { maxRetries: number; baseDelay: number; maxDelay: number; jitter: number; respectRetryAfter: boolean; queueRetries: boolean; }; }; } export {}; //# sourceMappingURL=haier-api.d.ts.map