homebridge-lg-airco
Version:
Homebridge plugin to control a Smart Thinq enabled LG airco unit. Makes use of WideQ => https://github.com/sampsyo/wideq
39 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PythonUtils = void 0;
const { spawn } = require('child_process');
class PythonUtils {
static async executePython3(workingDir, scriptName, args, forceCloseProcessAfterOutput = false) {
const pythonArgs = [];
for (const arg of args) {
if (arg) {
pythonArgs.push(arg.trim());
}
}
return new Promise((resolve, reject) => {
let data = [];
this.logDebug('python3 -u example.py ' + pythonArgs.join(' '));
const process = spawn('python3', ['-u', 'example.py'].concat(pythonArgs), { cwd: workingDir });
process.stdout.on('data', (output) => {
this.logDebug(output.toString());
data.push(output.toString());
if (forceCloseProcessAfterOutput) {
process.kill("SIGINT");
}
});
process.stderr.on('data', (output) => {
console.error(output.toString());
});
process.on('close', (exitCode) => {
if (exitCode === 0) {
resolve(data.join('\n'));
}
else {
reject('python error!');
}
});
});
}
}
exports.PythonUtils = PythonUtils;
//# sourceMappingURL=python-utils.js.map