UNPKG

homebridge-levoit-humidifiers

Version:
72 lines 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const debounce_1 = require("../utils/debounce"); /** * WarmMistLevel characteristic handler for the Warm Mist service. * Controls the warm mist level (0-3 typically, device-specific). * * HomeKit displays this as a percentage (0-100%), which we convert to/from * device-specific levels (e.g., 0-3 for most models). * * Features: * - Returns 0 if device is off. * - Only updates if value actually changed * * Note: Uses cached device state from background polling to avoid slow read warnings. */ const characteristic = { /** * Gets the current warm mist level as a percentage (0-100). * Converts from device level (0-3) to percentage. * Returns 0 if the device is off. * Uses cached state to ensure fast response times. */ get: async function () { var _a; // Use cached state - background polling keeps this fresh if (!this.device.isOn) { return 0; } // Convert device level (0-3) to percentage (0-100) const maxLevel = (_a = this.device.deviceType.warmMistLevels) !== null && _a !== void 0 ? _a : 0; if (maxLevel === 0) { return 0; } return Math.round((this.device.warmLevel / maxLevel) * 100); }, /** * Sets the warm mist level from a percentage (0-100) with debouncing. * Implements 300ms debounce to batch rapid slider changes from HomeKit. * * Logic: * - Converts percentage to device level (0-3) * - Clamps value to device-specific range (0 to warmMistLevels) * - Only updates if value actually changed to avoid unnecessary API calls */ set: async function (value) { const device = this.device; (0, debounce_1.debounceSet)(device.uuid, value, async (finalValue) => { var _a; const maxLevel = (_a = device.deviceType.warmMistLevels) !== null && _a !== void 0 ? _a : 0; // Convert percentage (0-100) to device level (0-3) // Round to nearest level const deviceLevel = Math.round((finalValue / 100) * maxLevel); // Clamp to valid range const clamped = Math.max(0, Math.min(maxLevel, deviceLevel)); try { // Avoid no-op - only update if value actually changed if (device.warmLevel !== clamped) { await device.changeWarmMistLevel(clamped); } // Update all HomeKit characteristics immediately this.updateAllCharacteristics(); } catch (err) { const message = err instanceof Error ? err.message : String(err); this.platform.log.debug(`[WARM] debounced set failed: ${message}`); } }, (message) => this.platform.log.debug(message)); }, }; exports.default = characteristic; //# sourceMappingURL=WarmMistLevel.js.map