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
77 lines (76 loc) • 2.13 kB
TypeScript
/**
* Unified device connection and communication manager
* Eliminates duplication between plug and bulb implementations
*/
import { TapoCredentials, TapoApiRequest, TapoApiResponse } from '../types';
export interface DeviceConnectionOptions {
maxRetries?: number;
retryDelay?: number;
minRequestInterval?: number;
enableLegacyFallback?: boolean;
}
export interface SessionErrorPatterns {
klapSessionErrors: string[];
generalSessionErrors: string[];
busyErrors: string[];
}
/**
* Centralized device communication manager
* Handles authentication, session management, and request queuing
*/
export declare class DeviceManager {
private readonly ip;
private readonly deviceType;
private auth;
private klapAuth;
private useKlap;
private requestQueue;
private lastRequestTime;
private isConnected;
private readonly options;
private readonly sessionErrorPatterns;
constructor(ip: string, credentials: TapoCredentials, deviceType: string, options?: DeviceConnectionOptions);
/**
* Check if device is reachable
*/
private checkDeviceConnectivity;
/**
* Determine if errors indicate legacy device
*/
private isLikelyLegacyDevice;
/**
* Classify error types for appropriate handling
*/
private classifyError;
/**
* Establish connection to device
*/
connect(): Promise<void>;
/**
* Disconnect from device
*/
disconnect(): Promise<void>;
/**
* Check if currently connected
*/
isDeviceConnected(): boolean;
/**
* Send request with automatic session management and rate limiting
*/
sendRequest<T>(request: TapoApiRequest): Promise<TapoApiResponse<T>>;
/**
* Execute the actual request using the appropriate protocol
*/
private executeRequest;
/**
* Handle session error by re-authenticating
*/
private reconnectAfterSessionError;
/**
* Get current protocol information
*/
getConnectionInfo(): {
protocol: 'KLAP' | 'SecurePassthrough';
connected: boolean;
};
}