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
149 lines (148 loc) • 4.29 kB
TypeScript
/**
* Type definitions for Tapo Smart Bulbs (L510, L520, L530)
* Single responsibility: Bulb-specific type definitions and utilities
*/
import { TapoDeviceInfo } from './base';
import { TapoDeviceType } from './device-types';
/**
* Extended device info for smart bulbs
*/
export interface TapoBulbInfo extends TapoDeviceInfo {
/** Current brightness level (1-100) */
brightness: number;
/** Current hue value (0-360) - only for color bulbs */
hue?: number;
/** Current saturation value (0-100) - only for color bulbs */
saturation?: number;
/** Current color temperature in Kelvin (2500-6500) - for white/color bulbs */
color_temp?: number;
/** Preferred state when turning on */
preferred_state?: {
brightness: number;
hue?: number;
saturation?: number;
color_temp?: number;
};
}
/**
* HSV color representation
*/
export interface HSVColor {
/** Hue (0-360 degrees) */
hue: number;
/** Saturation (0-100 percent) */
saturation: number;
/** Value/Brightness (1-100 percent) */
value: number;
}
/**
* RGB color representation
*/
export interface RGBColor {
/** Red component (0-255) */
red: number;
/** Green component (0-255) */
green: number;
/** Blue component (0-255) */
blue: number;
}
/**
* Color temperature representation
*/
export interface ColorTemperature {
/** Temperature in Kelvin (2500-6500) */
temperature: number;
/** Brightness level (1-100) */
brightness?: number;
}
/**
* Named colors for convenience
*/
export type NamedColor = 'red' | 'green' | 'blue' | 'yellow' | 'orange' | 'purple' | 'pink' | 'cyan' | 'white' | 'warm_white' | 'cool_white';
/**
* Light effect types
*/
export type LightEffect = 'off' | 'aurora' | 'bubbling' | 'candlelight' | 'disco' | 'flicker' | 'grandmas_colors' | 'hanukkah' | 'haunted_mansion' | 'holiday' | 'icicle' | 'lightning' | 'ocean' | 'rainbow' | 'spring' | 'sunset';
/**
* Light effect configuration
*/
export interface LightEffectConfig {
/** Effect type */
effect: LightEffect;
/** Effect speed (1-10, where 1 is slowest) */
speed?: number;
/** Effect brightness (1-100) */
brightness?: number;
/** Custom colors for the effect (if supported) */
colors?: HSVColor[];
}
/**
* Bulb capabilities by model
*/
export interface BulbCapabilities {
/** Supports brightness control */
brightness: boolean;
/** Supports color control (HSV) */
color: boolean;
/** Supports color temperature control */
colorTemperature: boolean;
/** Supports light effects */
effects: boolean;
/** Minimum brightness level */
minBrightness: number;
/** Maximum brightness level */
maxBrightness: number;
/** Minimum color temperature in Kelvin */
minColorTemp?: number;
/** Maximum color temperature in Kelvin */
maxColorTemp?: number;
}
/**
* Device capabilities by model
*/
export declare const BULB_CAPABILITIES: Record<string, BulbCapabilities>;
/**
* Check if device supports brightness control (all bulb types)
*/
export declare function supportsBrightnessControl(deviceType: TapoDeviceType): boolean;
/**
* Check if device supports color control (only L530)
*/
export declare function supportsColorControl(deviceType: TapoDeviceType): boolean;
/**
* Check if device supports color temperature control
*/
export declare function supportsColorTemperature(deviceType: TapoDeviceType): boolean;
/**
* Check if device supports light effects
*/
export declare function supportsLightEffects(deviceType: TapoDeviceType): boolean;
/**
* Predefined named colors in HSV format
*/
export declare const NAMED_COLORS: Record<NamedColor, HSVColor>;
/**
* Color conversion utilities
*/
export declare class ColorUtils {
/**
* Convert RGB to HSV
*/
static rgbToHsv(rgb: RGBColor): HSVColor;
/**
* Convert HSV to RGB
*/
static hsvToRgb(hsv: HSVColor): RGBColor;
/**
* Get named color HSV values
*/
static getNamedColor(color: NamedColor): HSVColor;
/**
* Validate HSV values
*/
static validateHSV(hsv: HSVColor): void;
/**
* Validate color temperature
*/
static validateColorTemperature(temp: number): void;
}