UNPKG

tsvesync

Version:

A TypeScript library for interacting with VeSync smart home devices

743 lines (742 loc) 29.4 kB
"use strict"; /** * VeSync Fan Classes */ Object.defineProperty(exports, "__esModule", { value: true }); exports.VeSyncFan = exports.fanConfig = void 0; const vesyncBaseDevice_1 = require("./vesyncBaseDevice"); const logger_1 = require("./logger"); const helpers_1 = require("./helpers"); // Fan configuration exports.fanConfig = { // Core Series 'Core200S': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speed', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], // 4 levels including sleep mode, matching reference plugin modes: ['sleep', 'manual'] }, 'Core300S': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'Core400S': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'Core600S': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, // LAP Series 'LAP-C201S-AUSR': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speed', 'sleep_mode', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual'] }, 'LAP-C202S-WUSR': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speed', 'sleep_mode', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual'] }, 'LAP-C301S-WJP': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C302S-WUSB': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C301S-WAAA': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C401S-WJP': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C401S-WUSR': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C401S-WAAA': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C601S-WUS': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C601S-WUSR': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-C601S-WEU': { module: 'VeSyncAirBypass', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V102S-AASR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V102S-WUS': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V102S-WEU': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V102S-AUSR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V102S-WJP': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-AASR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-WJP': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-WEU': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-WUS': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201-AUSR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-AUSR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-V201S-AEUR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'light_detection', 'fan_speed', 'auto_mode', 'sleep_mode', 'pet_mode', 'filter_life'], levels: [1, 2, 3, 4], modes: ['sleep', 'manual', 'auto', 'pet'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-EL551S-AUS': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_rotate', 'fan_speed', 'auto_mode', 'sleep_mode', 'turbo_mode', 'light_detection', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual', 'auto', 'turbo'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-EL551S-AEUR': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_rotate', 'fan_speed', 'auto_mode', 'sleep_mode', 'turbo_mode', 'light_detection', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual', 'auto', 'turbo'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-EL551S-WEU': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_rotate', 'fan_speed', 'auto_mode', 'sleep_mode', 'turbo_mode', 'light_detection', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual', 'auto', 'turbo'], autoPreferences: ['default', 'efficient', 'quiet'] }, 'LAP-EL551S-WUS': { module: 'VeSyncAirBaseV2', features: ['display', 'child_lock', 'night_light', 'air_quality', 'timer', 'fan_rotate', 'fan_speed', 'auto_mode', 'sleep_mode', 'turbo_mode', 'light_detection', 'filter_life'], levels: [1, 2, 3], modes: ['sleep', 'manual', 'auto', 'turbo'], autoPreferences: ['default', 'efficient', 'quiet'] }, // LTF Series 'LTF-F422S-KEU': { module: 'VeSyncTowerFan', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speeds', 'tower_modes'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] }, 'LTF-F422S-WUSR': { module: 'VeSyncTowerFan', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speeds', 'tower_modes'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] }, 'LTF-F422_WJP': { module: 'VeSyncTowerFan', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speeds', 'tower_modes'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] }, 'LTF-F422S-WUS': { module: 'VeSyncTowerFan', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speeds', 'tower_modes'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] }, // Classic Series 'Classic300S': { module: 'VeSyncHumidifier', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode'] }, 'Classic200S': { module: 'VeSyncHumid200S', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode'], levels: [1, 2, 3] }, // Dual Series 'Dual200S': { module: 'VeSyncHumidifier', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode'] }, // LUH Series 'LUH-A601S-WUSB': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode', 'night_light'] }, 'LUH-A601S-AUSW': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-D301S-WUSR': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-D301S-WJP': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-D301S-WEU': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WUSR': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WUS': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WEUR': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WEU': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WJP': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-A602S-WUSC': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-O451S-WEU': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-O451S-WUS': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-O451S-WUSR': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-O601S-WUS': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-O601S-KUS': { module: 'VeSyncWarmHumidifier', features: ['display', 'humidity', 'mist', 'warm', 'timer', 'auto_mode'] }, 'LUH-M101S-WUS': { module: 'VeSyncHumid1000S', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode', 'night_light'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9] }, 'LUH-M101S-WEUR': { module: 'VeSyncHumid1000S', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode', 'night_light'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9] }, // LEH Series - Superior 6000S 'LEH-S601S-WUS': { module: 'VeSyncSuperior6000S', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode', 'drying', 'temperature'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9] }, 'LEH-S601S-WUSR': { module: 'VeSyncSuperior6000S', features: ['display', 'humidity', 'mist', 'timer', 'auto_mode', 'drying', 'temperature'], levels: [1, 2, 3, 4, 5, 6, 7, 8, 9] }, // LV Series 'LV-PUR131S': { module: 'VeSyncAir131', features: ['air_quality', 'display', 'child_lock', 'night_light', 'timer', 'fan_speed', 'auto_mode', 'filter_life'], levels: [1, 2, 3] }, 'LV-RH131S': { module: 'VeSyncAir131', features: ['display', 'child_lock', 'night_light', 'timer', 'fan_speed', 'filter_life'], levels: [1, 2, 3] } }; /** * Base class for VeSync Fans */ class VeSyncFan extends vesyncBaseDevice_1.VeSyncBaseDevice { constructor(details, manager) { super(details, manager); this.details = {}; this.mode_dict = {}; this.speed_dict = {}; this._timer = null; this.details = details; // Try exact match first let entry = exports.fanConfig[this.deviceType]; // If no exact match, try substring matching for LAP variants // This handles cases where device reports as "LAP-C401S-WUSR" but we only have "Core400S" config if (!entry) { entry = this.findConfigBySubstring(this.deviceType); } if (entry) { this.config = { ...entry, features: [...entry.features], levels: entry.levels ? [...entry.levels] : undefined, modes: entry.modes ? [...entry.modes] : undefined, autoPreferences: entry.autoPreferences ? [...entry.autoPreferences] : undefined }; } else { this.config = { module: 'VeSyncAirBypass', features: [], levels: [], modes: [], autoPreferences: [] }; } } /** * Find config entry by substring matching for variant device types * Maps LAP variants to their base model configs (e.g., LAP-C401S-WUSR → Core400S) */ findConfigBySubstring(deviceType) { // Define model number mappings const modelMappings = [ // Core series air purifiers { patterns: ['Core300S', '301S', '302S'], configKey: 'Core300S' }, { patterns: ['Core400S', '401S'], configKey: 'Core400S' }, { patterns: ['Core600S', '601S', '602S'], configKey: 'Core600S' }, { patterns: ['Core200S', '201S', '202S'], configKey: 'Core200S' }, // Vital series { patterns: ['V102S'], configKey: 'LAP-V102S-AASR' }, { patterns: ['V201S'], configKey: 'LAP-V201S-AASR' }, // LV-PUR series { patterns: ['LV-PUR131S', 'LV-RH131S'], configKey: 'LV-PUR131S' }, // Everest series { patterns: ['LAP-EL551S'], configKey: 'LAP-EL551S-AUS' }, ]; // Check each mapping for (const mapping of modelMappings) { // If device type contains any of the patterns, use the config key if (mapping.patterns.some(pattern => deviceType.includes(pattern))) { const config = exports.fanConfig[mapping.configKey]; if (config) { logger_1.logger.debug(`${deviceType}: Using fallback config from ${mapping.configKey} via substring match`); return config; } } } return undefined; } /** * Check if feature is supported */ hasFeature(feature) { return this.config.features.includes(feature); } /** * Get configured modes for the device, falling back to provided defaults. */ getConfigModes(defaultModes = []) { if (Array.isArray(this.config.modes) && this.config.modes.length > 0) { return this.config.modes; } return defaultModes; } /** * Get configured auto preferences for the device, falling back to provided defaults. */ getConfigAutoPreferences(defaultPreferences = []) { if (Array.isArray(this.config.autoPreferences) && this.config.autoPreferences.length > 0) { return this.config.autoPreferences; } return defaultPreferences; } /** * Public accessor for supported modes for consumers that need to inspect capability metadata. */ getSupportedModes(defaultModes = []) { return this.getConfigModes(defaultModes); } /** * Public accessor for supported auto preference profiles. */ getSupportedAutoPreferences(defaultPreferences = []) { return this.getConfigAutoPreferences(defaultPreferences); } /** * Check if feature is supported in current mode */ isFeatureSupportedInCurrentMode(feature) { // First check if the feature is supported at all if (!this.hasFeature(feature)) { return false; } // Check mode-specific restrictions const currentMode = this.mode; // Some features are not supported in sleep mode if (currentMode === 'sleep') { // Display and child lock are not supported in sleep mode if (feature === 'display' || feature === 'child_lock') { return false; } } // Fan speed is only supported in manual mode for some devices if (feature === 'fan_speed' && this.deviceType.startsWith('LV-')) { return currentMode === 'manual'; } // Auto mode is not supported on Core200S if (feature === 'auto_mode' && this.deviceType.includes('Core200S')) { return false; } // Feature is supported in current mode return true; } /** * Get maximum fan speed level */ getMaxFanSpeed() { if (this.config.levels && this.config.levels.length > 0) { return Math.max(...this.config.levels); } return 3; } /** * Get current mode */ get mode() { var _a; return (_a = this.details.mode) !== null && _a !== void 0 ? _a : ''; } /** * Get current speed */ get speed() { var _a; return (_a = this.details.speed) !== null && _a !== void 0 ? _a : 0; } /** * Get filter life percentage */ get filterLife() { var _a; // Handle different filter_life formats from different devices const filterLife = this.details.filter_life; // For Air131 devices, filter_life is an object with percent property if (typeof filterLife === 'object' && filterLife !== null && 'percent' in filterLife) { return (_a = filterLife.percent) !== null && _a !== void 0 ? _a : 0; } // For other devices, filter_life is a direct number return typeof filterLife === 'number' ? filterLife : 0; } /** * Get screen status */ get screenStatus() { var _a; return (_a = this.details.screen_status) !== null && _a !== void 0 ? _a : 'off'; } /** * Get child lock status */ get childLock() { var _a; return (_a = this.details.child_lock) !== null && _a !== void 0 ? _a : false; } /** * Get air quality level (if supported) */ get airQualityLevel() { var _a; return (_a = this.details.air_quality) !== null && _a !== void 0 ? _a : ''; } /** * Get air quality (alias for airQualityLevel for backward compatibility) */ get airQuality() { return this.airQualityLevel; } /** * Get air quality value - PM2.5 in μg/m³ (if supported) */ get airQualityValue() { var _a; return (_a = this.details.air_quality_value) !== null && _a !== void 0 ? _a : 0; } /** * Normalized air quality metadata aligned with pyvesync levels. */ getNormalizedAirQuality() { var _a; if (typeof this.details.air_quality_level === 'number' && this.details.air_quality_level >= 1) { const label = (_a = this.details.air_quality_label) !== null && _a !== void 0 ? _a : helpers_1.Helpers.normalizeAirQuality(this.details.air_quality_level).label; return { level: this.details.air_quality_level, label }; } const normalized = helpers_1.Helpers.normalizeAirQuality(this.details.air_quality); if (normalized.level >= 1) { this.details.air_quality_level = normalized.level; this.details.air_quality_label = normalized.label; } return normalized; } /** * Get PM1 value (if supported) */ get pm1() { var _a; return (_a = this.details.pm1) !== null && _a !== void 0 ? _a : 0; } /** * Get PM10 value (if supported) */ get pm10() { var _a; return (_a = this.details.pm10) !== null && _a !== void 0 ? _a : 0; } /** * Get air quality percentage (if supported) */ get aqPercent() { var _a; return (_a = this.details.aq_percent) !== null && _a !== void 0 ? _a : 0; } /** * Get humidity level (if supported) */ get humidity() { var _a; return (_a = this.details.humidity) !== null && _a !== void 0 ? _a : 0; } /** * Get mist level (if supported) */ get mistLevel() { var _a; return (_a = this.details.mist_level) !== null && _a !== void 0 ? _a : 0; } /** * Get warm level (if supported) */ get warmLevel() { var _a; return (_a = this.details.warm_level) !== null && _a !== void 0 ? _a : 0; } /** * Get timer status */ get timer() { return this._timer; } set timer(value) { this._timer = value; } /** * Return formatted device info to stdout */ display() { super.display(); const info = [ ['Mode: ', this.mode], ['Speed: ', this.speed], ['Filter Life: ', this.filterLife, '%'] ]; if (this.hasFeature('display')) { info.push(['Screen Status: ', this.screenStatus]); } if (this.hasFeature('child_lock')) { info.push(['Child Lock: ', this.childLock ? 'Enabled' : 'Disabled']); } if (this.hasFeature('air_quality')) { info.push(['Air Quality Level: ', this.airQualityLevel]); if (this.airQualityValue > 0) { info.push(['Air Quality Value: ', this.airQualityValue, ' μg/m³']); } if (this.pm1 > 0) { info.push(['PM1: ', this.pm1, ' μg/m³']); } if (this.pm10 > 0) { info.push(['PM10: ', this.pm10, ' μg/m³']); } if (this.aqPercent > 0) { info.push(['AQ Percent: ', this.aqPercent, '%']); } } if (this.hasFeature('humidity')) { info.push(['Humidity: ', this.humidity, '%']); } if (this.hasFeature('mist')) { info.push(['Mist Level: ', this.mistLevel]); } if (this.hasFeature('warm')) { info.push(['Warm Level: ', this.warmLevel]); } if (this.hasFeature('timer') && this.timer) { if (typeof this.timer === 'number') { info.push(['Timer: ', this.timer, 'hours']); } else { info.push(['Timer: ', this.timer.duration, 'seconds']); info.push(['Timer Action: ', this.timer.action]); } } for (const [key, value, unit = ''] of info) { logger_1.logger.info(`${key.toString().padEnd(30, '.')} ${value}${unit}`); } } /** * Return JSON details for fan */ displayJSON() { const baseInfo = JSON.parse(super.displayJSON()); const details = { 'Mode': this.mode, 'Speed': this.speed.toString(), 'Filter Life': this.filterLife.toString() }; if (this.hasFeature('display')) { details['Screen Status'] = this.screenStatus; } if (this.hasFeature('child_lock')) { details['Child Lock'] = this.childLock ? 'Enabled' : 'Disabled'; } if (this.hasFeature('air_quality')) { details['Air Quality Level'] = this.airQualityLevel.toString(); if (this.airQualityValue > 0) { details['Air Quality Value'] = this.airQualityValue.toString(); } if (this.pm1 > 0) { details['PM1'] = this.pm1.toString(); } if (this.pm10 > 0) { details['PM10'] = this.pm10.toString(); } if (this.aqPercent > 0) { details['AQ Percent'] = this.aqPercent.toString(); } } if (this.hasFeature('humidity')) { details['Humidity'] = this.humidity.toString(); } if (this.hasFeature('mist')) { details['Mist Level'] = this.mistLevel.toString(); } if (this.hasFeature('warm')) { details['Warm Level'] = this.warmLevel.toString(); } if (this.hasFeature('timer') && this.timer) { if (typeof this.timer === 'number') { details['Timer'] = this.timer.toString(); } else { details['Timer'] = this.timer.duration.toString(); details['Timer Action'] = this.timer.action; } } return JSON.stringify({ ...baseInfo, ...details }, null, 4); } } exports.VeSyncFan = VeSyncFan;