homebridge-roborock-vacuum-update
Version:
Comprehensive Homebridge plugin for Roborock vacuum cleaners with full HomeKit integration including mopping, dock features, and advanced controls.
70 lines • 2.81 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZonesService = 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 ZonesService extends plugin_service_class_1.PluginServiceClass {
constructor(coreContext, accessory, mainService) {
super(coreContext);
this.accessory = accessory;
this.mainService = mainService;
this.zones = {};
if (this.config.zones) {
for (const zoneDef of this.config.zones) {
this.createZone(zoneDef.name, zoneDef.zone);
}
}
}
async init() {
// Reset zone switches when cleaning stops
this.deviceManager.stateChanged$
.pipe((0, rxjs_1.filter)(({ key }) => key === "state"))
.subscribe(({ value }) => {
const isCleaning = this.deviceManager.isCleaning;
if (!isCleaning) {
this.services.forEach((zone) => {
zone
.getCharacteristic(this.hap.Characteristic.On)
.updateValue(false);
});
}
});
}
get services() {
return [...Object.values(this.zones)];
}
createZone(zoneName, zoneParams) {
this.log.info(`Creating zone switch: ${zoneName}`);
const name = `${this.config.cleanword} ${zoneName}`;
const zoneId = `zone-${zoneName}`;
this.zones[zoneName] = this.accessory.getServiceById(this.hap.Service.Switch, zoneId)
|| this.accessory.addService(this.hap.Service.Switch, name, zoneId);
(0, ensure_name_1.ensureName)(this.hap, this.zones[zoneName], name);
this.zones[zoneName]
.getCharacteristic(this.hap.Characteristic.On)
.onGet(() => this.mainService.getCleaning())
.onSet((newState) => this.setCleaningZone(newState, zoneParams));
}
async setCleaningZone(state, zone) {
this.log.info(`setCleaningZone: ${state} for zone`);
try {
if (state && !this.deviceManager.isCleaning) {
// Start zone cleaning
await this.roborockAPI.app_zoned_clean(this.duid, zone);
this.log.info(`Started zone cleaning`);
}
else if (!state) {
// Stop cleaning and return to dock
await this.roborockAPI.app_charge(this.duid);
this.log.info(`Stopped cleaning and returning to dock`);
}
}
catch (err) {
this.log.error(`setCleaningZone failed:`, err);
throw err;
}
}
}
exports.ZonesService = ZonesService;
//# sourceMappingURL=zones_service.js.map