UNPKG

matterbridge-xiaomi-roborock

Version:
48 lines (47 loc) 2.15 kB
import { MatterbridgeDynamicPlatform } from 'matterbridge'; import { VacuumDeviceAccessory } from './vacuum_device_accessory.js'; export class XiaomiRoborockVacuumPlatform extends MatterbridgeDynamicPlatform { config; constructor(matterbridge, log, config) { super(matterbridge, log, config); this.config = config; log.logLevel = this.config.debug ? "debug" : "info"; if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.0.7')) { throw new Error(`This plugin requires Matterbridge version >= "3.0.7". Please update Matterbridge from ${this.matterbridge.matterbridgeVersion} to the latest version in the frontend."`); } this.log.info(`Initializing Platform...`); } async onStart(reason) { this.log.info(`onStart called with reason: ${reason ?? 'none'}`); await this.ready; await this.clearSelect(); await this.discoverDevices(); } async onConfigure() { await super.onConfigure(); this.log.info('onConfigure called'); for (const device of this.getDevices()) { this.log.info(`Configuring device: ${device.uniqueId}`); } } async onChangeLoggerLevel(logLevel) { this.log.info(`onChangeLoggerLevel called with: ${logLevel}`); } async onShutdown(reason) { await super.onShutdown(reason); this.log.info(`onShutdown called with reason: ${reason ?? 'none'}`); if (this.config.unregisterOnShutdown === true) await this.unregisterAllDevices(); } async discoverDevices() { this.log.info('Discovering devices...'); const devices = this.config.devices ?? []; this.log.info(`Found ${devices.length} devices`); await Promise.all(devices.map(async (cfg) => { const vacuumDevice = new VacuumDeviceAccessory(cfg, this.log); const vacuum = await vacuumDevice.initializeMatterbridgeEndpoint(); await this.registerDevice(vacuum); vacuumDevice.postRegister(); })); } }