node-red-contrib-tplink-tapo-connect-api
Version:
This unofficial node-RED node allows connection to TP-Link Tapo devices. This project has been enhanced with AI support to enable new features. Starting with v0.50, we have added support for the KLAP protocol. To prioritize the operation of this node, we
46 lines (45 loc) • 1.54 kB
TypeScript
/**
* Retry utilities for Tapo device operations
* Separated from wrapper for better separation of concerns
*/
export interface RetryConfig {
maxAttempts: number;
baseDelay: number;
strategy: 'linear' | 'exponential' | 'fixed';
busyErrorPatterns: string[];
sessionErrorPatterns: string[];
onRetry?: (attempt: number, error: Error, delay: number) => void;
}
export interface RetryResult<T> {
success: boolean;
data?: T;
error?: Error;
metadata: {
attempts: number;
duration: number;
retryReasons: string[];
};
}
export declare class TapoRetryHandler {
private config;
static readonly DEFAULT_CONFIG: RetryConfig;
constructor(config?: RetryConfig);
execute<T>(operation: () => Promise<T>, operationName?: string): Promise<RetryResult<T>>;
private shouldRetry;
private getRetryReason;
private calculateDelay;
/**
* Create a pre-configured retry handler for common scenarios
*/
static forDeviceControl(): TapoRetryHandler;
static forEnergyMonitoring(): TapoRetryHandler;
static forInfoRetrieval(): TapoRetryHandler;
}
/**
* Utility function to wrap any async operation with retry logic
*/
export declare function withRetry<T>(operation: () => Promise<T>, config?: Partial<RetryConfig>): Promise<RetryResult<T>>;
/**
* Decorator for automatic retry (for class methods)
*/
export declare function retryable(config?: Partial<RetryConfig>): (_target: any, _propertyName: string, descriptor: PropertyDescriptor) => void;