UNPKG

homebridge-roborock-vacuum-update

Version:

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

61 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatteryInfo = void 0; const rxjs_1 = require("rxjs"); const plugin_service_class_1 = require("./plugin_service_class"); class BatteryInfo extends plugin_service_class_1.PluginServiceClass { constructor(coreContext, accessory) { super(coreContext); this.accessory = accessory; this.service = this.accessory.getService(this.hap.Service.Battery) || this.accessory.addService(this.hap.Service.Battery); } async init() { // Subscribe to battery and charging state changes this.deviceManager.stateChanged$ .pipe((0, rxjs_1.filter)(({ key }) => key === "battery" || key === "charge_status"), (0, rxjs_1.distinct)(({ key, value }) => `${key}:${value}`)) .subscribe(({ key, value }) => { if (key === "battery") { const batteryLevel = value; this.service .getCharacteristic(this.hap.Characteristic.BatteryLevel) .updateValue(batteryLevel); this.service .getCharacteristic(this.hap.Characteristic.StatusLowBattery) .updateValue(batteryLevel < 20 ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } else if (key === "charge_status") { const chargeStatus = value; const isCharging = chargeStatus !== 0; this.service .getCharacteristic(this.hap.Characteristic.ChargingState) .updateValue(isCharging ? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING); } }); // Initial state const battery = this.deviceManager.battery; const chargeStatus = this.deviceManager.getStatus("charge_status"); this.service .getCharacteristic(this.hap.Characteristic.BatteryLevel) .updateValue(battery); this.service .getCharacteristic(this.hap.Characteristic.StatusLowBattery) .updateValue(battery < 20 ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); this.service .getCharacteristic(this.hap.Characteristic.ChargingState) .updateValue(chargeStatus !== 0 ? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING); } get services() { return [this.service]; } } exports.BatteryInfo = BatteryInfo; //# sourceMappingURL=battery_info.js.map