homebridge-levoit-humidifiers
Version:
Homebridge plugin for Levoit Humidifiers
64 lines • 2.67 kB
TypeScript
import { DynamicPlatformPlugin, PlatformAccessory, PlatformConfig, Characteristic, Service, Logger, API, UnknownContext } from 'homebridge';
import VeSyncAccessory from './VeSyncAccessory';
import VeSyncFan from './api/VeSyncFan';
import DebugMode from './debugMode';
export interface VeSyncContext {
name: string;
device: VeSyncFan;
}
export type VeSyncPlatformAccessory = PlatformAccessory<VeSyncContext>;
/**
* Platform class that manages the Levoit Humidifiers Homebridge plugin.
* Handles device discovery, accessory registration, and lifecycle management.
*/
export default class Platform implements DynamicPlatformPlugin {
readonly log: Logger;
readonly config: PlatformConfig;
readonly api: API;
readonly Service: typeof Service;
readonly Characteristic: typeof Characteristic;
/** Cached accessories loaded from Homebridge's persistent storage */
readonly cachedAccessories: VeSyncPlatformAccessory[];
/** Currently registered and active device accessories */
readonly registeredDevices: VeSyncAccessory[];
readonly debugger: DebugMode;
private readonly client;
constructor(log: Logger, config: PlatformConfig, api: API);
/**
* Called by Homebridge when it loads cached accessories from persistent storage.
* These accessories will be restored if they're still present during device discovery.
*/
configureAccessory(accessory: PlatformAccessory<UnknownContext>): void;
/**
* Discovers and loads all Levoit humidifier devices from VeSync.
* Called automatically when Homebridge finishes launching.
*
* Process:
* 1. Validates credentials
* 2. Authenticates with VeSync API
* 3. Fetches device list
* 4. Loads/restores each device as an accessory
* 5. Removes accessories for devices that no longer exist
*/
discoverDevices(): Promise<void>;
/**
* Loads a single device as a Homebridge accessory.
* Either restores an existing cached accessory or creates a new one.
*
* @param device The VeSync device to load
*/
private loadDevice;
/**
* Removes accessories for devices that no longer exist.
* Compares cached accessories against currently registered devices
* and unregisters any that are no longer present.
*
* Note: When accessories are unregistered, their polling intervals
* will be cleaned up automatically when the VeSyncAccessory instances
* are garbage collected.
*
* @param loadedDeviceUUIDs - Set of UUIDs for devices that were successfully loaded
*/
private checkOldDevices;
}
//# sourceMappingURL=platform.d.ts.map