UNPKG

homebridge-roborock-vacuum-update

Version:

Comprehensive Homebridge plugin for Roborock vacuum cleaners with full HomeKit integration including mopping, dock features, and advanced controls.

101 lines 4.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const services_1 = require("./services"); /** * Refactored Roborock Vacuum Accessory using modular services */ class RoborockVacuumAccessory { constructor(platform, accessory) { this.platform = platform; this.accessory = accessory; // Create config from platform config and device info const deviceName = this.platform.roborockAPI.getVacuumDeviceInfo(accessory.context, "name") || "Roborock Vacuum"; this.config = (0, services_1.applyConfigDefaults)({ ...this.platform.platformConfig, // Start with platform config name: deviceName, // Override with device name }); // Create DeviceManager this.deviceManager = new services_1.DeviceManager(this.platform.api.hap, this.platform.log, this.platform.roborockAPI, accessory.context); // Create CoreContext const coreContext = { hap: this.platform.api.hap, log: this.platform.log, config: this.config, deviceManager: this.deviceManager, roborockAPI: this.platform.roborockAPI, duid: accessory.context, }; // Initialize services this.pluginServices = this.initializeServices(coreContext); // Add all services to the accessory // In DynamicPlatformPlugin, services are added directly to the accessory // and Homebridge will discover them automatically Object.values(this.pluginServices).forEach((service) => { if (service) { // Services are already added to accessory in their constructors // Just initialize them if (typeof service.init === "function") { service.init().catch((err) => { this.platform.log.error(`Service init failed:`, err); }); } } }); // Set up device state notifications this.setupDeviceNotifications(); } initializeServices(coreContext) { const { config } = this; const productInfo = new services_1.ProductInfo(coreContext, this.accessory); // Create main service first (without room callback) const mainService = new services_1.MainService(coreContext, this.accessory, undefined); // Create rooms service with callback to main service const rooms = new services_1.RoomsService(coreContext, this.accessory, async (clean) => { await mainService.setCleaning(clean); }); // Update main service with room IDs getter mainService.getRoomIdsToClean = () => rooms.roomIdsToClean; return { mainService, productInfo, rooms, battery: new services_1.BatteryInfo(coreContext, this.accessory), findMe: new services_1.FindMeService(coreContext, this.accessory), pause: config.pause ? new services_1.PauseSwitch(coreContext, this.accessory, rooms) : undefined, dock: config.dock ? new services_1.DockService(coreContext, this.accessory) : undefined, zones: config.zones && config.zones.length > 0 ? new services_1.ZonesService(coreContext, this.accessory, mainService) : undefined, waterBox: config.waterBox ? new services_1.WaterBoxService(coreContext, this.accessory) : undefined, }; } setupDeviceNotifications() { // Device state changes are handled by individual services via DeviceManager.stateChanged$ // This method is kept for future use if needed } /** * Called by platform when device state changes */ notifyDeviceUpdater(id, data) { if (id === "CloudMessage" || id === "LocalMessage") { this.platform.log.debug(`Updating accessory with ${id} data: ${JSON.stringify(data)}`); if (data && Array.isArray(data) && data.length > 0) { const messages = data[0]; // Emit state changes through DeviceManager so services can react if (messages && typeof messages === "object") { Object.keys(messages).forEach((key) => { this.deviceManager.emitStateChange(key, messages[key]); }); } } } } } exports.default = RoborockVacuumAccessory; //# sourceMappingURL=vacuum_accessory_new.js.map