UNPKG

homebridge-roborock-vacuum-update

Version:

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

81 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PauseSwitch = void 0; const rxjs_1 = require("rxjs"); const plugin_service_class_1 = require("./plugin_service_class"); const ensure_name_1 = require("./utils/ensure_name"); class PauseSwitch extends plugin_service_class_1.PluginServiceClass { constructor(coreContext, accessory, roomsService) { super(coreContext); this.accessory = accessory; this.roomsService = roomsService; if (this.config.pause) { const name = `${this.config.name} ${this.config.pauseWord}`; this.service = this.accessory.getServiceById(this.hap.Service.Switch, "pause") || this.accessory.addService(this.hap.Service.Switch, name, "pause"); (0, ensure_name_1.ensureName)(this.hap, this.service, name); this.service .getCharacteristic(this.hap.Characteristic.On) .onGet(() => this.getPauseState()) .onSet((newState) => this.setPauseState(newState)); } } async init() { if (!this.service) return; this.deviceManager.stateChanged$ .pipe((0, rxjs_1.filter)(({ key }) => key === "state"), (0, rxjs_1.distinct)(({ value }) => value)) .subscribe(({ value }) => { this.changedPause(this.deviceManager.isCleaning); }); } get services() { return this.service ? [this.service] : []; } changedPause(isCleaning) { if (!this.service) return; this.log.debug(`Pause state changed: isCleaning=${isCleaning}`); const canBePaused = isCleaning && !this.deviceManager.isPaused; this.service .getCharacteristic(this.hap.Characteristic.On) .updateValue(canBePaused); } async getPauseState() { const isPaused = this.deviceManager.isPaused; const canBePaused = this.deviceManager.isCleaning && !isPaused; this.log.debug(`getPauseState: ${canBePaused}`); return canBePaused; } async setPauseState(state) { var _a; this.log.info(`setPauseState: ${state}`); try { if (state && this.deviceManager.isPaused) { // Resume const roomIdsToClean = (_a = this.roomsService) === null || _a === void 0 ? void 0 : _a.roomIdsToClean; if (roomIdsToClean && roomIdsToClean.size > 0) { // Resume room cleaning - Roborock doesn't have a specific resume command for rooms // So we just start cleaning again await this.roborockAPI.app_segment_clean(this.duid, Array.from(roomIdsToClean)); this.log.info(`Resumed room cleaning`); } else { await this.roborockAPI.app_start(this.duid); this.log.info(`Resumed cleaning`); } } else if (!state && this.deviceManager.isCleaning) { // Pause await this.roborockAPI.app_pause(this.duid); this.log.info(`Paused cleaning`); } } catch (err) { this.log.error(`setPauseState failed:`, err); throw err; } } } exports.PauseSwitch = PauseSwitch; //# sourceMappingURL=pause_switch.js.map