UNPKG

homebridge-lg-airco

Version:

Homebridge plugin to control a Smart Thinq enabled LG airco unit. Makes use of WideQ => https://github.com/sampsyo/wideq

273 lines 11.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FanSpeed = exports.Mode = exports.VSwingMode = exports.HSwingMode = exports.WideqAdapter = void 0; const python_utils_1 = require("../utils/python-utils"); const { resolve } = require('path'); let WideqAdapter = (() => { class WideqAdapter { constructor(country, language, storagePath, debug, debugLogger) { this.country = country; this.language = language; this.storagePath = storagePath; this.logDebug = debugLogger; } static async listAirCoolers(country, language, storagePath) { console.log(storagePath); const data = await python_utils_1.PythonUtils.executePython3(this.wideqFolder, this.wideqScriptFile, ['-c', country, '-l', language, '-p', storagePath, '-v', 'ls']); const devices = data.split('\n'); const processedDevices = []; for (const device of devices) { const deviceInfoValues = device.split(':'); if (deviceInfoValues.length > 1) { const modelInfoValues = deviceInfoValues[1].split('('); const deviceId = deviceInfoValues[0].trim(); const deviceType = modelInfoValues[0].trim(); const modelName = modelInfoValues[1].replace(')', '').trim(); processedDevices.push({ deviceId, deviceType, modelName, country, language }); } } return processedDevices; } async getStatus(deviceId) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'ac-mon', deviceId]); this.logDebug(data); const dataPieces = data.split(';').map(s => s.trim()); this.logDebug(dataPieces); return { isOn: dataPieces[0].toLowerCase() === 'on', mode: Mode[dataPieces[1]], currentTempInCelsius: parseFloat(dataPieces[2].substring(4)), targetTempInCelsius: parseFloat(dataPieces[3].substring(4)), fanSpeed: FanSpeed[dataPieces[4].substring(10)] }; } catch (error) { this.logDebug(error); return null; } } async getCurrentPowerUsage(deviceId) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'get-power-draw', deviceId]); this.logDebug(data); return parseInt(data); } catch (error) { this.logDebug(error); return null; } } async setPowerOnOff(deviceId, poweredOn) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'turn', deviceId, (poweredOn ? 'on' : 'off')]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } async setTargetTemperature(deviceId, temperatureInCelsius) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'set-temp', deviceId, (temperatureInCelsius + '')]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } async setMode(deviceId, mode) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'set-mode', deviceId, mode]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } async setFanSpeed(deviceId, fanSpeed) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'set-speed', deviceId, fanSpeed]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } async setSwingModeV(deviceId, swingModeV) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'set-swing-v', deviceId, swingModeV]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } async setSwingModeH(deviceId, swingModeH) { try { const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'set-swing-h', deviceId, swingModeH]); this.logDebug(data); return true; } catch (error) { this.logDebug(error); return false; } } static fanSpeedToPercentage(fanSpeed) { switch (fanSpeed) { case FanSpeed.SLOW: return 12.5; case FanSpeed.SLOW_LOW: return 25; case FanSpeed.LOW: return 37.5; case FanSpeed.LOW_MID: return 50; case FanSpeed.MID: return 62.5; case FanSpeed.MID_HIGH: return 75; case FanSpeed.HIGH: return 87.5; case FanSpeed.POWER: return 100; case FanSpeed.AUTO: case FanSpeed.NATURE: case FanSpeed.R_LOW: case FanSpeed.R_MID: case FanSpeed.R_HIGH: case FanSpeed.L_LOW: case FanSpeed.L_MID: case FanSpeed.L_HIGH: case FanSpeed.L_LOWR_LOW: case FanSpeed.L_LOWR_MID: case FanSpeed.L_LOWR_HIGH: case FanSpeed.L_MIDR_LOW: case FanSpeed.L_MIDR_MID: case FanSpeed.L_MIDR_HIGH: case FanSpeed.L_HIGHR_LOW: case FanSpeed.L_HIGHR_MID: case FanSpeed.L_HIGHR_HIGH: case FanSpeed.AUTO_2: case FanSpeed.POWER_2: case FanSpeed.LONGPOWER: return 0; } } static percentageToFanSpeed(percentage) { if (percentage <= 12.5) { return FanSpeed.SLOW; } else if (percentage <= 25) { return FanSpeed.SLOW_LOW; } else if (percentage <= 37.5) { return FanSpeed.LOW; } else if (percentage <= 50) { return FanSpeed.LOW_MID; } else if (percentage <= 62.5) { return FanSpeed.MID; } else if (percentage <= 75) { return FanSpeed.MID_HIGH; } else if (percentage <= 87.5) { return FanSpeed.HIGH; } else if (percentage <= 100) { return FanSpeed.POWER; } } } WideqAdapter.wideqFolder = resolve(__dirname + '../../../resources/wideq/'); WideqAdapter.wideqScriptFile = 'example.py'; return WideqAdapter; })(); exports.WideqAdapter = WideqAdapter; var HSwingMode; (function (HSwingMode) { HSwingMode["OFF"] = "OFF"; HSwingMode["ONE"] = "ONE"; HSwingMode["TWO"] = "TWO"; HSwingMode["THREE"] = "THREE"; HSwingMode["FOUR"] = "FOUR"; HSwingMode["FIVE"] = "FIVE"; HSwingMode["LEFT_HALF"] = "LEFT_HALF"; HSwingMode["RIGHT_HALF"] = "RIGHT_HALF"; HSwingMode["ALL"] = "ALL"; })(HSwingMode = exports.HSwingMode || (exports.HSwingMode = {})); var VSwingMode; (function (VSwingMode) { VSwingMode["OFF"] = "OFF"; VSwingMode["ONE"] = "ONE"; VSwingMode["TWO"] = "TWO"; VSwingMode["THREE"] = "THREE"; VSwingMode["FOUR"] = "FOUR"; VSwingMode["FIVE"] = "FIVE"; VSwingMode["SIX"] = "SIX"; VSwingMode["ALL"] = "ALL"; })(VSwingMode = exports.VSwingMode || (exports.VSwingMode = {})); var Mode; (function (Mode) { Mode["COOL"] = "COOL"; Mode["DRY"] = "DRY"; Mode["FAN"] = "FAN"; Mode["AI"] = "AI"; Mode["HEAT"] = "HEAT"; Mode["AIRCLEAN"] = "AIRCLEAN"; Mode["ACO"] = "ACO"; Mode["AROMA"] = "AROMA"; Mode["ENERGY_SAVING"] = "ENERGY_SAVING"; Mode["ENERGY_SAVER"] = "ENERGY_SAVER"; })(Mode = exports.Mode || (exports.Mode = {})); var FanSpeed; (function (FanSpeed) { FanSpeed["SLOW"] = "SLOW"; FanSpeed["SLOW_LOW"] = "SLOW_LOW"; FanSpeed["LOW"] = "LOW"; FanSpeed["LOW_MID"] = "LOW_MID"; FanSpeed["MID"] = "MID"; FanSpeed["MID_HIGH"] = "MID_HIGH"; FanSpeed["HIGH"] = "HIGH"; FanSpeed["POWER"] = "POWER"; FanSpeed["AUTO"] = "AUTO"; FanSpeed["NATURE"] = "NATURE"; FanSpeed["R_LOW"] = "R_LOW"; FanSpeed["R_MID"] = "R_MID"; FanSpeed["R_HIGH"] = "R_HIGH"; FanSpeed["L_LOW"] = "L_LOW"; FanSpeed["L_MID"] = "L_MID"; FanSpeed["L_HIGH"] = "L_HIGH"; FanSpeed["L_LOWR_LOW"] = "L_LOWR_LOW"; FanSpeed["L_LOWR_MID"] = "L_LOWR_MID"; FanSpeed["L_LOWR_HIGH"] = "L_LOWR_HIGH"; FanSpeed["L_MIDR_LOW"] = "L_MIDR_LOW"; FanSpeed["L_MIDR_MID"] = "L_MIDR_MID"; FanSpeed["L_MIDR_HIGH"] = "L_MIDR_HIGH"; FanSpeed["L_HIGHR_LOW"] = "L_HIGHR_LOW"; FanSpeed["L_HIGHR_MID"] = "L_HIGHR_MID"; FanSpeed["L_HIGHR_HIGH"] = "L_HIGHR_HIGH"; FanSpeed["AUTO_2"] = "AUTO_2"; FanSpeed["POWER_2"] = "POWER_2"; FanSpeed["LONGPOWER"] = "LONGPOWER"; })(FanSpeed = exports.FanSpeed || (exports.FanSpeed = {})); //# sourceMappingURL=wideq-adapter.js.map