UNPKG

homebridge-lg-ac

Version:

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

232 lines 8.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ACController = void 0; const events_1 = __importDefault(require("events")); class ACController extends events_1.default { constructor(ThinQ, device) { super(); this.ThinQ = ThinQ; this.device = device; } get isPowerOn() { return !!this.data['airState.operation']; } get isLightOn() { return !!this.data['airState.lightingState.displayControl']; } // fan service get windStrength() { return this.data['airState.windStrength']; } get isSwingOn() { const vStep = Math.floor((this.data['airState.wDir.vStep'] || 0) / 100), hStep = Math.floor((this.data['airState.wDir.hStep'] || 0) / 100); return !!(vStep + hStep); } get currentTemperature() { return this.data['airState.tempState.current']; } get targetTemperature() { return this.data['airState.tempState.target']; } get comfortMode() { return this.data['airState.reservation.sleepTime'] > 0; } get jetMode() { return !!this.data['airState.wMode.jet']; } get opMode() { return this.data['airState.opMode']; } get currentMode() { if (!this.isPowerOn) { return 2 /* CurrentMode.OFF */; } let opMode = this.opMode; if (![4 /* OpMode.HEAT */, 0 /* OpMode.COOL */].includes(opMode)) { opMode = this.currentTemperature <= this.targetTemperature ? 0 /* OpMode.COOL */ : 4 /* OpMode.HEAT */; } switch (opMode) { case 4 /* OpMode.HEAT */: return 1 /* CurrentMode.HEAT */; case 0 /* OpMode.COOL */: return 0 /* CurrentMode.COOL */; } throw new Error('Unreachable'); } get targetTemperatureRange() { let targetTemperatureValue = this.device.deviceModel.value('airState.tempState.limitMin'); if (!targetTemperatureValue) { targetTemperatureValue = this.device.deviceModel.value('airState.tempState.target'); } return targetTemperatureValue; } get windDirectionAllowed() { let allowedDirections = 0 /* WindMode.NONE */; const racSubMode = this.device.deviceModel.value('support.racSubMode').options; for (const value of Object.values(racSubMode)) { if (value.match(/WIND_DIRECTION_STEP_LEFT_RIGHT/)) { allowedDirections |= 2 /* WindMode.HORIZONTAL */; } if (value.match(/WIND_DIRECTION_STEP_UP_DOWN/)) { allowedDirections |= 1 /* WindMode.VERTICAL */; } } return allowedDirections; } async setActive(isOn) { if (this.isPowerOn && isOn) { return; // don't send same status } await this.ThinQ.deviceControl(this.device.id, { dataKey: 'airState.operation', dataValue: isOn, }, 'Operation').then(() => { this.device.snapshot['airState.operation'] = isOn; this.emit('UPDATE', this.device); }); if (isOn) { await this.setOpMode(6 /* OpMode.AUTO */); } } async setTargetTemperature(temperature) { if (!this.isPowerOn) { return; } if (temperature === this.targetTemperature) { return; } await this.ensureAutoMode(); return this.ThinQ.deviceControl(this.device.id, { dataKey: 'airState.tempState.target', dataValue: temperature, }).then(() => { this.device.snapshot['airState.tempState.target'] = temperature; this.emit('UPDATE', this.device); }); } async setFanSpeed(level) { var _a; if (!this.isPowerOn) { return; } if (this.windStrength === level) { return; } return (_a = this.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.device.id, { dataKey: 'airState.windStrength', dataValue: level, }).then(() => { this.device.snapshot['airState.windStrength'] = level; this.emit('UPDATE', this.device); }); } async setLight(isOn) { var _a; if (!this.isPowerOn) { return; } if (isOn === this.isLightOn) { return; } (_a = this.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.device.id, { dataKey: 'airState.lightingState.displayControl', dataValue: isOn ? 1 : 0, }).then(() => { this.device.snapshot['airState.lightingState.displayControl'] = isOn ? 1 : 0; this.emit('UPDATE', this.device); }); } async setSwingMode(isOn) { if (!this.isPowerOn) { return; } const swingValue = isOn ? 100 : 0; switch (this.windDirectionAllowed) { case 3 /* WindMode.BOTH */: return this.ThinQ.deviceControl(this.device.id, { dataKey: null, dataValue: null, dataSetList: { 'airState.wDir.vStep': swingValue, 'airState.wDir.hStep': swingValue, }, dataGetList: null, }, 'Set', 'favoriteCtrl').then(() => { this.device.snapshot['airState.wDir.vStep'] = swingValue; this.device.snapshot['airState.wDir.hStep'] = swingValue; this.emit('UPDATE', this.device); }); case 1 /* WindMode.VERTICAL */: return this.ThinQ.deviceControl(this.device.id, { dataKey: 'airState.wDir.vStep', dataValue: swingValue, }).then(() => { this.device.snapshot['airState.wDir.vStep'] = swingValue; this.emit('UPDATE', this.device); }); case 2 /* WindMode.HORIZONTAL */: return this.ThinQ.deviceControl(this.device.id, { dataKey: 'airState.wDir.hStep', dataValue: swingValue, }).then(() => { this.device.snapshot['airState.wDir.hStep'] = swingValue; this.emit('UPDATE', this.device); }); } } async setComfortSleep(isOn) { var _a; const sleepTime = isOn ? 420 : 0; const vStep = isOn ? 1 : 0; return (_a = this.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.device.id, { dataKey: null, dataValue: null, dataSetList: { 'airState.reservation.sleepTime': sleepTime, 'airState.wDir.vStep': vStep, }, dataGetList: null, }, 'Set', 'favoriteCtrl').then(() => { this.device.snapshot['airState.reservation.sleepTime'] = sleepTime; this.device.snapshot['airState.wDir.vStep'] = vStep; this.emit('UPDATE', this.device); }); } async setJetMode(isOn) { var _a; return (_a = this.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.device.id, { dataKey: 'airState.wMode.jet', dataValue: isOn ? 1 : 0, }).then(() => { this.device.snapshot['airState.wMode.jet'] = isOn ? 1 : 0; this.emit('UPDATE', this.device); }); } async setOpMode(opMode) { var _a; if (this.opMode === opMode) { return; } await ((_a = this.ThinQ) === null || _a === void 0 ? void 0 : _a.deviceControl(this.device.id, { dataKey: 'airState.opMode', dataValue: opMode, }).then(() => { this.device.snapshot['airState.opMode'] = opMode; this.emit('UPDATE', this.device); })); await this.setLight(false); } async ensureAutoMode() { if (this.opMode !== 6 /* OpMode.AUTO */) { await this.setOpMode(6 /* OpMode.AUTO */); } } get data() { return this.device.snapshot; } } exports.ACController = ACController; //# sourceMappingURL=ACController.js.map