UNPKG

homebridge-lg-ac

Version:

A Homebridge plugin for controlling/monitoring LG AirConditioning device via LG ThinQ platform.

80 lines 3.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FanUnit = void 0; const events_1 = __importDefault(require("events")); class FanUnit extends events_1.default { constructor(controller, platform, accessory) { super(); this.controller = controller; this.platform = platform; this.accessory = accessory; this.fanSpeeds = [2 /* FanSpeed.LOW */, 3 /* FanSpeed.LOW_MEDIUM */, 4 /* FanSpeed.MEDIUM */, 5 /* FanSpeed.MEDIUM_HIGH */, 6 /* FanSpeed.HIGH */]; const { Service: { Fanv2 }, Characteristic, } = this.platform; this.ThinQ = this.platform.ThinQ; this.device = this.accessory.context.device; this.service = this.accessory.getService(Fanv2) || this.accessory.addService(Fanv2, this.device.name); this.service.updateCharacteristic(Characteristic.Name, 'Fan'); this.lastSpeed = this.controller.windStrength !== 8 /* FanSpeed.AUTO */ ? this.controller.windStrength : undefined; this.service.updateCharacteristic(Characteristic.CurrentFanState, this.controller.isPowerOn ? Characteristic.CurrentFanState.BLOWING_AIR : Characteristic.CurrentFanState.INACTIVE); this.service.getCharacteristic(Characteristic.TargetFanState) .onSet((value) => { var _a; switch (value) { case Characteristic.TargetFanState.AUTO: this.controller.setFanSpeed(8 /* FanSpeed.AUTO */); break; case Characteristic.TargetFanState.MANUAL: this.controller.setFanSpeed((_a = this.lastSpeed) !== null && _a !== void 0 ? _a : 4 /* FanSpeed.MEDIUM */); break; } }); this.service.getCharacteristic(Characteristic.RotationSpeed) .setProps({ minValue: 0, maxValue: this.fanSpeeds.length - 1, minStep: 1, }) .onSet((value) => { this.throttle(() => { this.controller.setFanSpeed(this.fanSpeeds[value]); }); }); this.service.getCharacteristic(Characteristic.SwingMode) .onSet((value) => { this.controller.setSwingMode(!!value); }); } throttle(callback, waitingTime = 1000) { if (this.fanSpeedTimeout) { clearTimeout(this.fanSpeedTimeout); this.fanSpeedTimeout = undefined; } this.fanSpeedTimeout = setTimeout(() => { callback(); }, waitingTime); } update(device) { const { Characteristic, Characteristic: { TargetFanState, }, } = this.platform; this.service.updateCharacteristic(Characteristic.CurrentFanState, this.controller.isPowerOn ? Characteristic.CurrentFanState.BLOWING_AIR : Characteristic.CurrentFanState.INACTIVE); if (this.controller.windStrength === 8 /* FanSpeed.AUTO */) { this.service.updateCharacteristic(Characteristic.TargetFanState, TargetFanState.AUTO); } else { this.lastSpeed = this.controller.windStrength; this.service.updateCharacteristic(Characteristic.TargetFanState, TargetFanState.MANUAL); this.service.updateCharacteristic(Characteristic.RotationSpeed, this.fanSpeeds.indexOf(this.controller.windStrength)); } this.service.updateCharacteristic(Characteristic.SwingMode, this.controller.isSwingOn ? Characteristic.SwingMode.SWING_ENABLED : Characteristic.SwingMode.SWING_DISABLED); } remove() { this.accessory.removeService(this.service); } } exports.FanUnit = FanUnit; //# sourceMappingURL=FanUnit.js.map