UNPKG

homebridge-levoit-humidifiers

Version:
187 lines 7.47 kB
import { DeviceType } from './deviceTypes'; import VeSync from './VeSync'; export declare enum Mode { Manual = "manual", Sleep = "sleep", Auto = "auto", AutoPro = "autoPro", Humidity = "humidity" } /** * VeSyncFan represents a single Levoit humidifier device. * Manages device state, API communication, and provides methods to control the device. */ export default class VeSyncFan { private readonly client; readonly name: string; private _mode; private _isOn; private _mistLevel; private _warmLevel; private _warmEnabled; private _brightnessLevel; private _humidityLevel; private _targetHumidity; private _targetReached; private _lightOn; private _lightSpeed; private _red; private _blue; private _green; private _colorMode; private _colorSliderLocation; readonly configModule: string; readonly cid: string; readonly region: string; readonly model: string; readonly mac: string; readonly uuid: string; private readonly lock; readonly deviceType: DeviceType; /** * Timestamp of the last successful device info update. * Used to implement a 5-second cache to prevent excessive API calls. */ private lastCheck; private _displayOn; readonly manufacturer = "Levoit"; /** * Resets all device state values to their "off" state. * Used when device is turned off or becomes unreachable. */ private resetStateToOff; get humidityLevel(): number; get targetHumidity(): number; get displayOn(): boolean; get brightnessLevel(): number; get mistLevel(): number; get warmLevel(): number; get warmEnabled(): boolean; get lightOn(): string; get mode(): Mode; get targetReached(): boolean; get isOn(): boolean; constructor(client: VeSync, name: string, _mode: Mode, _isOn: boolean, _mistLevel: number, _warmLevel: number, _warmEnabled: boolean, _brightnessLevel: number, _humidityLevel: number, _targetHumidity: number, _targetReached: boolean, _lightOn: string, _lightSpeed: number, _red: number, _blue: number, _green: number, _colorMode: string, _colorSliderLocation: number, configModule: string, cid: string, region: string, model: string, mac: string, uuid: string); /** * Stores the last non-zero target humidity to restore when device is turned back on. * This preserves user preferences across power cycles. */ private _lastTargetHumidity; /** * Sets the device power state (on/off). * When turning off, resets related state values to 0. * When turning on, restores the last known target humidity from memory. * * @param power - true to turn on, false to turn off * @returns true if successful, false otherwise */ setPower(power: boolean): Promise<boolean>; /** * Sets the target humidity percentage for Auto/Humidity mode. * Handles different JSON field names for new vs old device formats. * * @param level - Target humidity percentage (device-specific range, typically 30-80% or 40-80%) * @returns true if successful, false otherwise */ setTargetHumidity(level: number): Promise<boolean>; /** * Changes the device operating mode. * Automatically maps Auto mode to the appropriate mode for the device: * - LV600S models use "Humidity" mode instead of "Auto" * - Models with AutoPro support use "AutoPro" mode instead of "Auto" * Skips API call if already in the requested mode. * * @param mode - The mode to switch to * @returns true if successful, false otherwise */ changeMode(mode: Mode): Promise<boolean>; /** * Sets the night light brightness level. * For non-RGB devices only. RGB devices should use setLightStatus(). * * @param brightness - Brightness level (0-100) * @returns true if successful, false otherwise */ setBrightness(brightness: number): Promise<boolean>; /** * Sets the device display screen state (on/off). * Handles different JSON field names for new vs old device formats. * * @param power - true to turn display on, false to turn off * @returns true if successful, false otherwise */ setDisplay(power: boolean): Promise<boolean>; /** * Changes the cool mist level. * Validates the level is within device limits (1 to mistLevels). * Handles different JSON field names for new vs old device formats. * * @param mistLevel - Mist level (1 to device-specific maximum, typically 9) * @returns true if successful, false if level is out of range */ changeMistLevel(mistLevel: number): Promise<boolean>; /** * Changes the warm mist level. * Only available on devices with warm mist capability. * Validates the level is within device limits (0 to warmMistLevels). * Updates warmEnabled state based on level (0 = disabled, >0 = enabled). * * @param warmMistLevel - Warm mist level (0 to device-specific maximum, typically 3) * @returns true if successful, false if device doesn't support warm mist or level is out of range */ changeWarmMistLevel(warmMistLevel: number): Promise<boolean>; /** * Sets the RGB night light status and brightness. * Only for RGB-capable devices. Calculates RGB color values proportionally * when brightness changes to maintain color appearance. * * @param action - Light action: 'on' or 'off' * @param brightness - Brightness level (0-100) * @returns true if successful, false otherwise */ setLightStatus(action: string, brightness: number): Promise<boolean>; /** * Updates device state from the VeSync API. * Implements a 15-second cache to prevent excessive API calls. * This cache works in conjunction with background polling (30-second interval) * to ensure fresh data while minimizing API load and respecting quota limits. * * Thread-safe: Uses AsyncLock to prevent concurrent updates. * * @throws Error if device is unreachable and showOffWhenDisconnected is false */ updateInfo(): Promise<void>; /** * Factory method to create a VeSyncFan instance from VeSync API response data. * Used during device discovery to instantiate devices from the device list. * * @param client - The VeSync client instance for API communication * @returns A function that takes device data and returns a VeSyncFan instance */ static readonly fromResponse: (client: VeSync) => ({ deviceName, mode, deviceStatus, mistLevel, warmLevel, warmEnabled, brightnessLevel, humidity, targetHumidity, targetReached, lightOn, lightSpeed, red, blue, green, colorMode, colorSliderLocation, configModule, cid, deviceRegion, deviceType, macID, uuid, }: { deviceName: any; mode: any; deviceStatus: any; mistLevel: any; warmLevel: any; warmEnabled: any; brightnessLevel: any; humidity: any; targetHumidity: any; targetReached: any; lightOn: any; lightSpeed: any; red: any; blue: any; green: any; colorMode: any; colorSliderLocation: any; configModule: any; cid: any; deviceRegion: any; deviceType: any; macID: any; uuid: any; }) => VeSyncFan; } //# sourceMappingURL=VeSyncFan.d.ts.map