UNPKG

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

75 lines (74 loc) 2.18 kB
import { TapoCredentials } from '../types'; export declare enum ProtocolType { KLAP = "klap", PASSTHROUGH = "passthrough" } export interface ProtocolOptions { preferredProtocol?: ProtocolType; enableFallback?: boolean; connectionTimeout?: number; minRequestInterval?: number; } export interface ProtocolInfo { type: ProtocolType; isSupported: boolean; priority: number; lastUsed?: number; errorCount: number; } /** * Manages protocol selection and fallback logic * Single responsibility: Protocol detection and selection */ export declare class ProtocolSelector { protected readonly ip: string; protected readonly credentials: TapoCredentials; private protocols; private activeProtocol; private readonly options; constructor(ip: string, credentials: TapoCredentials, options?: ProtocolOptions); /** * Select the best available protocol */ selectProtocol(): Promise<ProtocolType>; /** * Get currently active protocol */ getActiveProtocol(): ProtocolType | null; /** * Test if a specific protocol works with the device */ testProtocol(protocol: ProtocolType): Promise<boolean>; /** * Record a protocol error and update its health status */ recordProtocolError(protocol: ProtocolType): void; /** * Reset protocol error counts (useful for recovery) */ resetProtocolErrors(): void; /** * Get protocol information for debugging */ getProtocolInfo(): Map<ProtocolType, ProtocolInfo>; /** * Check if a protocol is healthy (low error count, recently used) */ private isProtocolHealthy; /** * Get alternative protocols ordered by priority */ private getAlternativeProtocols; /** * Perform actual protocol test (to be implemented by subclasses or injected) */ protected performProtocolTest(_protocol: ProtocolType): Promise<boolean>; /** * Force switch to a specific protocol */ forceProtocol(protocol: ProtocolType): void; /** * Get minimum request interval for the active protocol */ getMinRequestInterval(): number; }