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

198 lines 5.62 kB
"use strict"; /** * Type definitions for Tapo Smart Bulbs (L510, L520, L530) * Single responsibility: Bulb-specific type definitions and utilities */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ColorUtils = exports.NAMED_COLORS = exports.BULB_CAPABILITIES = void 0; exports.supportsBrightnessControl = supportsBrightnessControl; exports.supportsColorControl = supportsColorControl; exports.supportsColorTemperature = supportsColorTemperature; exports.supportsLightEffects = supportsLightEffects; /** * Device capabilities by model */ exports.BULB_CAPABILITIES = { 'L510': { brightness: true, color: false, colorTemperature: false, effects: false, minBrightness: 1, maxBrightness: 100 }, 'L520': { brightness: true, color: false, colorTemperature: true, effects: false, minBrightness: 1, maxBrightness: 100, minColorTemp: 2500, maxColorTemp: 6500 }, 'L530': { brightness: true, color: true, colorTemperature: true, effects: true, minBrightness: 1, maxBrightness: 100, minColorTemp: 2500, maxColorTemp: 6500 } }; /** * Check if device supports brightness control (all bulb types) */ function supportsBrightnessControl(deviceType) { const bulbTypes = ['L510', 'L520', 'L530']; return bulbTypes.includes(deviceType); } /** * Check if device supports color control (only L530) */ function supportsColorControl(deviceType) { return deviceType === 'L530'; } /** * Check if device supports color temperature control */ function supportsColorTemperature(deviceType) { const colorTempTypes = ['L520', 'L530']; return colorTempTypes.includes(deviceType); } /** * Check if device supports light effects */ function supportsLightEffects(deviceType) { const effectTypes = ['L530']; return effectTypes.includes(deviceType); } /** * Predefined named colors in HSV format */ exports.NAMED_COLORS = { red: { hue: 0, saturation: 100, value: 100 }, green: { hue: 120, saturation: 100, value: 100 }, blue: { hue: 240, saturation: 100, value: 100 }, yellow: { hue: 60, saturation: 100, value: 100 }, orange: { hue: 30, saturation: 100, value: 100 }, purple: { hue: 270, saturation: 100, value: 100 }, pink: { hue: 300, saturation: 100, value: 100 }, cyan: { hue: 180, saturation: 100, value: 100 }, white: { hue: 0, saturation: 0, value: 100 }, warm_white: { hue: 30, saturation: 20, value: 100 }, cool_white: { hue: 240, saturation: 10, value: 100 } }; /** * Color conversion utilities */ class ColorUtils { /** * Convert RGB to HSV */ static rgbToHsv(rgb) { const r = rgb.red / 255; const g = rgb.green / 255; const b = rgb.blue / 255; const max = Math.max(r, g, b); const min = Math.min(r, g, b); const diff = max - min; let hue = 0; if (diff !== 0) { if (max === r) { hue = ((g - b) / diff) % 6; } else if (max === g) { hue = (b - r) / diff + 2; } else { hue = (r - g) / diff + 4; } } hue = Math.round(hue * 60); if (hue < 0) hue += 360; const saturation = max === 0 ? 0 : Math.round((diff / max) * 100); const value = Math.round(max * 100); return { hue, saturation, value }; } /** * Convert HSV to RGB */ static hsvToRgb(hsv) { const h = hsv.hue / 60; const s = hsv.saturation / 100; const v = hsv.value / 100; const c = v * s; const x = c * (1 - Math.abs((h % 2) - 1)); const m = v - c; let r = 0, g = 0, b = 0; if (0 <= h && h < 1) { r = c; g = x; b = 0; } else if (1 <= h && h < 2) { r = x; g = c; b = 0; } else if (2 <= h && h < 3) { r = 0; g = c; b = x; } else if (3 <= h && h < 4) { r = 0; g = x; b = c; } else if (4 <= h && h < 5) { r = x; g = 0; b = c; } else if (5 <= h && h < 6) { r = c; g = 0; b = x; } return { red: Math.round((r + m) * 255), green: Math.round((g + m) * 255), blue: Math.round((b + m) * 255) }; } /** * Get named color HSV values */ static getNamedColor(color) { return exports.NAMED_COLORS[color]; } /** * Validate HSV values */ static validateHSV(hsv) { if (hsv.hue < 0 || hsv.hue > 360) { throw new Error(`Invalid hue value: ${hsv.hue}. Must be between 0-360.`); } if (hsv.saturation < 0 || hsv.saturation > 100) { throw new Error(`Invalid saturation value: ${hsv.saturation}. Must be between 0-100.`); } if (hsv.value < 1 || hsv.value > 100) { throw new Error(`Invalid value/brightness: ${hsv.value}. Must be between 1-100.`); } } /** * Validate color temperature */ static validateColorTemperature(temp) { if (temp < 2500 || temp > 6500) { throw new Error(`Invalid color temperature: ${temp}K. Must be between 2500-6500K.`); } } } exports.ColorUtils = ColorUtils; //# sourceMappingURL=bulb.js.map