Socket
Socket
Sign inDemoInstall

homebridge-lg-airco

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-lg-airco - npm Package Compare versions

Comparing version 0.1.0-beta2 to 0.1.0-beta3

2

package.json
{
"name": "homebridge-lg-airco",
"version": "0.1.0-beta2",
"version": "0.1.0-beta3",
"description": "Homebridge plugin to control a Smart Thinq enabled LG airco unit. Makes use of WideQ => https://github.com/sampsyo/wideq",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -20,3 +20,5 @@ # Homebridge Smart Thinq LG Airco

"minHeatingTemp": 5,
"updateInterval": 60000
"updateInterval": 60000,
"debug": false,
"dummy": false
}

@@ -36,2 +38,4 @@ ```

The `updateInterval` field is the interval that is used to fetch new state data from the AC unit. In milliseconds!
The `debug` field is the boolean that enables or disables debug logging, set this to false unless collecting logs.
The `dummy` field is the boolean that enables mocking out the LG API and will instead use a dummy AC unit with no network calls, only for development & testing!

@@ -52,12 +56,10 @@ The initial state will be fetched shortly after booting your Homebridge instance.

- Enter the folder of the plugin to where the wideq files are: `cd homebridge-lg-airco/resources/wideq`
- Execute the command `sudo python3 example.py -c country-code -l language-code` where you should replace `country-code` and `language-code` with the respective values.
For example: `sudo python3 example.py -c BE -l en-UK`
- Execute the command `python3 example.py -c country-code -l language-code -p path-to-homebridge-folder` where you should replace `country-code`, `language-code` and `path-to-homebridge-folder` with the respective values.
For example: `python3 example.py -c BE -l en-UK -p /home/pi/.homebridge`
- Follow the instructions on the screen, and paste the resulting URL back into the terminal.
The command will now print out a list of all known devices for your account. If wanted select the one you want and paste the value in the `config.json` file at the `deviceId` field of the corresponding accessory definition.
It will also generate a file in which the session is stored.
- Set the file permissions on the state file with this command (osx/linux): `sudo chmod a+rw wideq_state.json`
It will also generate a file in which the session is stored in the Homebridge folder.
- The plugin is now fully ready to be used in Homebridge!
- Note! If you update the plugin, make sure to re-execute the command above with your specific parameters! (because updating the plugin removes the file in which the session is stored!)
This code makes use of the `WideQ` library, more information [here](https://github.com/sampsyo/wideq).
Some changes have been made to the included version of the WideQ library.

@@ -7,2 +7,4 @@ "use strict";

const async_utils_1 = require("./utils/async-utils");
const dummy_controller_1 = require("./lg/dummy-controller");
const python_utils_1 = require("./utils/python-utils");
class LgAirCoolerAccessory {

@@ -14,2 +16,5 @@ constructor(log, config, api) {

this.config = config;
this.storagePath = api.user.storagePath() + '/wideq_state.json';
this.logDebug = this.config.debug ? this.log : () => { };
python_utils_1.PythonUtils.logDebug = this.logDebug;
this.informationService = new this.hap.Service.AccessoryInformation()

@@ -21,4 +26,3 @@ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'LG')

setTimeout(async () => {
console.log(this.config);
const airCoolers = await wideq_adapter_1.WideqAdapter.listAirCoolers(this.config.country, this.config.language);
const airCoolers = await wideq_adapter_1.WideqAdapter.listAirCoolers(this.config.country, this.config.language, this.storagePath);
if (airCoolers.length === 1) {

@@ -43,3 +47,8 @@ this.airCooler = airCoolers[0];

}
this.controller = new lg_airco_controller_1.LgAircoController(this.airCooler, config.updateInterval);
if (this.config.dummy) {
this.controller = new dummy_controller_1.DummyController(this.airCooler, this.config.updateInterval, this.config.debug ? this.log : () => { });
}
else {
this.controller = new lg_airco_controller_1.LgAircoController(this.airCooler, this.config.updateInterval, this.storagePath, this.config.debug, this.logDebug);
}
this.handleRotationSpeedSetWithDebounce = async_utils_1.AsyncUtils.debounce((newFanSpeed) => {

@@ -46,0 +55,0 @@ this.controller.setFanSpeed(wideq_adapter_1.WideqAdapter.percentageToFanSpeed(newFanSpeed));

@@ -22,2 +22,3 @@ import {

import {Controller} from "./lg/controller";
import {PythonUtils} from "./utils/python-utils";

@@ -29,2 +30,4 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {

private readonly config: AccessoryConfig;
private readonly storagePath: string;
private readonly logDebug: Function;

@@ -44,2 +47,5 @@ private readonly informationService: Service;

this.config = config;
this.storagePath = api.user.storagePath() + '/wideq_state.json';
this.logDebug = this.config.debug ? this.log : () => {};
PythonUtils.logDebug = this.logDebug;

@@ -53,4 +59,3 @@ this.informationService = new this.hap.Service.AccessoryInformation()

setTimeout(async () => {
console.log(this.config);
const airCoolers: AirCooler[] = await WideqAdapter.listAirCoolers(this.config.country, this.config.language);
const airCoolers: AirCooler[] = await WideqAdapter.listAirCoolers(this.config.country, this.config.language, this.storagePath);

@@ -75,4 +80,8 @@ if (airCoolers.length === 1) {

this.controller = new LgAircoController(this.airCooler, config.updateInterval);
//this.controller = new DummyController(this.airCooler, config.updateInterval);
if (this.config.dummy) {
this.controller = new DummyController(this.airCooler, this.config.updateInterval, this.config.debug ? this.log : () => {});
} else {
this.controller = new LgAircoController(this.airCooler, this.config.updateInterval, this.storagePath, this.config.debug, this.logDebug);
}
this.handleRotationSpeedSetWithDebounce = AsyncUtils.debounce((newFanSpeed: number) => {

@@ -79,0 +88,0 @@ this.controller.setFanSpeed(WideqAdapter.percentageToFanSpeed(newFanSpeed));

@@ -7,3 +7,3 @@ "use strict";

class DummyController extends controller_1.Controller {
constructor(airCooler, updateInterval = 30000) {
constructor(airCooler, updateInterval, debugLogger) {
super();

@@ -20,2 +20,3 @@ this.airCooler = airCooler;

this.targetHeatingTemperatureInCelsius = 21;
this.logDebug = debugLogger;
}

@@ -28,7 +29,7 @@ isPoweredOn() {

this.isOn = powerOn;
console.log('Setting power value: ' + (powerOn ? 'ON' : 'OFF'));
this.logDebug('Setting power value: ' + (powerOn ? 'ON' : 'OFF'));
}
}
getMode() {
console.log('Getting mode value: ' + this.mode);
this.logDebug('Getting mode value: ' + this.mode);
return this.mode;

@@ -40,3 +41,3 @@ }

this.mode = newTargetMode;
console.log('Setting mode value: ' + newTargetMode);
this.logDebug('Setting mode value: ' + newTargetMode);
await this.setTargetTemperatureInCelsius(this.mode === wideq_adapter_1.Mode.COOL ? this.targetCoolingTemperatureInCelsius : this.targetHeatingTemperatureInCelsius);

@@ -49,7 +50,7 @@ }

getCurrentTemperatureInCelsius() {
console.log('Getting current temperature value: ' + this.currentTemperatureInCelsius);
this.logDebug('Getting current temperature value: ' + this.currentTemperatureInCelsius);
return this.currentTemperatureInCelsius;
}
getTargetCoolingTemperatureInCelsius() {
console.log('Getting target temperature value: ' + this.targetCoolingTemperatureInCelsius);
this.logDebug('Getting target temperature value: ' + this.targetCoolingTemperatureInCelsius);
return this.targetCoolingTemperatureInCelsius;

@@ -67,3 +68,3 @@ }

getTargetHeatingTemperatureInCelsius() {
console.log('Getting target heating temperature value: ' + this.targetHeatingTemperatureInCelsius);
this.logDebug('Getting target heating temperature value: ' + this.targetHeatingTemperatureInCelsius);
return this.targetHeatingTemperatureInCelsius;

@@ -84,7 +85,7 @@ }

this.targetTemperatureInCelsius = newTargetTemperatureInCelsius;
console.log('Setting temperature value: ' + newTargetTemperatureInCelsius);
this.logDebug('Setting temperature value: ' + newTargetTemperatureInCelsius);
}
}
getVerticalSwingMode() {
console.log('Getting v-swing value: ' + this.swingModeV);
this.logDebug('Getting v-swing value: ' + this.swingModeV);
return this.swingModeV;

@@ -96,7 +97,7 @@ }

this.swingModeV = newVerticalSwingMode;
console.log('Setting swing V value: ' + newVerticalSwingMode);
this.logDebug('Setting swing V value: ' + newVerticalSwingMode);
}
}
getHorizontalSwingMode() {
console.log('Getting h-swing value: ' + this.swingModeH);
this.logDebug('Getting h-swing value: ' + this.swingModeH);
return this.swingModeH;

@@ -108,7 +109,7 @@ }

this.swingModeH = newHorizontalSwingMode;
console.log('Setting swing H value: ' + newHorizontalSwingMode);
this.logDebug('Setting swing H value: ' + newHorizontalSwingMode);
}
}
getFanSpeed() {
console.log('Getting fan speed value: ' + this.fanSpeed);
this.logDebug('Getting fan speed value: ' + this.fanSpeed);
return this.fanSpeed;

@@ -120,3 +121,3 @@ }

this.fanSpeed = newFanSpeed;
console.log('Setting fan speed value: ' + newFanSpeed);
this.logDebug('Setting fan speed value: ' + newFanSpeed);
}

@@ -123,0 +124,0 @@ }

@@ -6,3 +6,5 @@ import {AirCooler, FanSpeed, HSwingMode, Mode, VSwingMode} from "./wideq-adapter";

constructor(airCooler: AirCooler, updateInterval: number = 30000) {
private logDebug: Function;
constructor(airCooler: AirCooler, updateInterval: number, debugLogger: Function) {
super();

@@ -23,2 +25,4 @@

this.targetHeatingTemperatureInCelsius = 21;
this.logDebug = debugLogger;
}

@@ -33,3 +37,3 @@

this.isOn = powerOn;
console.log('Setting power value: ' + (powerOn ? 'ON' : 'OFF'));
this.logDebug('Setting power value: ' + (powerOn ? 'ON' : 'OFF'));
}

@@ -39,3 +43,3 @@ }

public getMode(): Mode {
console.log('Getting mode value: ' + this.mode);
this.logDebug('Getting mode value: ' + this.mode);
return this.mode;

@@ -48,3 +52,3 @@ }

this.mode = newTargetMode;
console.log('Setting mode value: ' + newTargetMode);
this.logDebug('Setting mode value: ' + newTargetMode);
await this.setTargetTemperatureInCelsius(this.mode === Mode.COOL ? this.targetCoolingTemperatureInCelsius : this.targetHeatingTemperatureInCelsius);

@@ -57,3 +61,3 @@ } else {

public getCurrentTemperatureInCelsius(): number {
console.log('Getting current temperature value: ' + this.currentTemperatureInCelsius);
this.logDebug('Getting current temperature value: ' + this.currentTemperatureInCelsius);
return this.currentTemperatureInCelsius;

@@ -63,3 +67,3 @@ }

public getTargetCoolingTemperatureInCelsius(): number {
console.log('Getting target temperature value: ' + this.targetCoolingTemperatureInCelsius);
this.logDebug('Getting target temperature value: ' + this.targetCoolingTemperatureInCelsius);
return this.targetCoolingTemperatureInCelsius;

@@ -80,3 +84,3 @@ }

public getTargetHeatingTemperatureInCelsius(): number {
console.log('Getting target heating temperature value: ' + this.targetHeatingTemperatureInCelsius);
this.logDebug('Getting target heating temperature value: ' + this.targetHeatingTemperatureInCelsius);
return this.targetHeatingTemperatureInCelsius;

@@ -100,3 +104,3 @@ }

this.targetTemperatureInCelsius = newTargetTemperatureInCelsius;
console.log('Setting temperature value: ' + newTargetTemperatureInCelsius);
this.logDebug('Setting temperature value: ' + newTargetTemperatureInCelsius);
}

@@ -106,3 +110,3 @@ }

public getVerticalSwingMode(): VSwingMode {
console.log('Getting v-swing value: ' + this.swingModeV);
this.logDebug('Getting v-swing value: ' + this.swingModeV);
return this.swingModeV;

@@ -115,3 +119,3 @@ }

this.swingModeV = newVerticalSwingMode;
console.log('Setting swing V value: ' + newVerticalSwingMode);
this.logDebug('Setting swing V value: ' + newVerticalSwingMode);
}

@@ -121,3 +125,3 @@ }

public getHorizontalSwingMode(): HSwingMode {
console.log('Getting h-swing value: ' + this.swingModeH);
this.logDebug('Getting h-swing value: ' + this.swingModeH);
return this.swingModeH;

@@ -130,3 +134,3 @@ }

this.swingModeH = newHorizontalSwingMode;
console.log('Setting swing H value: ' + newHorizontalSwingMode);
this.logDebug('Setting swing H value: ' + newHorizontalSwingMode);
}

@@ -136,3 +140,3 @@ }

public getFanSpeed(): FanSpeed {
console.log('Getting fan speed value: ' + this.fanSpeed);
this.logDebug('Getting fan speed value: ' + this.fanSpeed);
return this.fanSpeed;

@@ -145,5 +149,5 @@ }

this.fanSpeed = newFanSpeed;
console.log('Setting fan speed value: ' + newFanSpeed);
this.logDebug('Setting fan speed value: ' + newFanSpeed);
}
}
}

@@ -7,5 +7,5 @@ "use strict";

class LgAircoController extends controller_1.Controller {
constructor(airCooler, updateInterval = 30000) {
constructor(airCooler, updateInterval, storagePath, debugEnabled, debugLogger) {
super();
this.adapter = new wideq_adapter_1.WideqAdapter(airCooler.country, airCooler.language);
this.adapter = new wideq_adapter_1.WideqAdapter(airCooler.country, airCooler.language, storagePath, debugEnabled, debugLogger);
this.airCooler = airCooler;

@@ -12,0 +12,0 @@ this.update();

@@ -8,6 +8,6 @@ import {AirCooler, FanSpeed, HSwingMode, Mode, VSwingMode, WideqAdapter} from "./wideq-adapter";

constructor(airCooler: AirCooler, updateInterval: number = 30000) {
constructor(airCooler: AirCooler, updateInterval: number, storagePath: string, debugEnabled: boolean, debugLogger: Function) {
super();
this.adapter = new WideqAdapter(airCooler.country, airCooler.language);
this.adapter = new WideqAdapter(airCooler.country, airCooler.language, storagePath, debugEnabled, debugLogger);
this.airCooler = airCooler;

@@ -14,0 +14,0 @@

@@ -8,8 +8,11 @@ "use strict";

class WideqAdapter {
constructor(country, language) {
constructor(country, language, storagePath, debug, debugLogger) {
this.country = country;
this.language = language;
this.storagePath = storagePath;
this.logDebug = debugLogger;
}
static async listAirCoolers(country, language) {
const data = await python_utils_1.PythonUtils.executePython3(this.wideqFolder, this.wideqScriptFile, ['-c', country, '-l', language, '-v', 'ls']);
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');

@@ -37,6 +40,6 @@ const processedDevices = [];

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'ac-mon', deviceId], true);
console.log(data);
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], true);
this.logDebug(data);
const dataPieces = data.split(';').map(s => s.trim());
console.log(dataPieces);
this.logDebug(dataPieces);
return {

@@ -51,3 +54,3 @@ isOn: dataPieces[0].toLowerCase() === 'on',

catch (error) {
console.error(error);
this.logDebug(error);
return null;

@@ -58,8 +61,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'get-power-draw', deviceId]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return null;

@@ -70,8 +73,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'turn', deviceId, (poweredOn ? 'on' : 'off')]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -82,8 +85,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-temp', deviceId, (temperatureInCelsius + '')]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -94,8 +97,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-mode', deviceId, mode]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -106,8 +109,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-speed', deviceId, fanSpeed]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -118,8 +121,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-swing-v', deviceId, swingModeV]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -130,8 +133,8 @@ }

try {
const data = await python_utils_1.PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-swing-h', deviceId, swingModeH]);
console.log(data);
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) {
console.error(error);
this.logDebug(error);
return false;

@@ -138,0 +141,0 @@ }

@@ -12,12 +12,16 @@ import {PythonUtils} from "../utils/python-utils";

private readonly language: string;
private readonly storagePath: string;
private readonly debug: boolean;
private readonly logDebug: Function;
//TODO: Build in some kind of queue since wideq is using and updating the one state file. Multiple concurrent python instances can give issues when they are all trying to change the state file!
constructor(country: string, language: string) {
constructor(country: string, language: string, storagePath: string, debug: boolean, debugLogger: Function) {
this.country = country;
this.language = language;
this.storagePath = storagePath;
this.logDebug = debugLogger;
}
public static async listAirCoolers(country: string, language: string): Promise<Array<AirCooler>> {
const data: string = await PythonUtils.executePython3(this.wideqFolder, this.wideqScriptFile, ['-c', country, '-l', language, '-v', 'ls']);
public static async listAirCoolers(country: string, language: string, storagePath: string): Promise<Array<AirCooler>> {
console.log(storagePath);
const data: string = await PythonUtils.executePython3(this.wideqFolder, this.wideqScriptFile, ['-c', country, '-l', language, '-p', storagePath, '-v', 'ls']);

@@ -51,7 +55,7 @@ const devices = data.split('\n');

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'ac-mon', deviceId], true);
console.log(data);
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-p', this.storagePath, this.debug ? '-v' : null, 'ac-mon', deviceId], true);
this.logDebug(data);
const dataPieces: string[] = data.split(';').map(s => s.trim());
console.log(dataPieces);
this.logDebug(dataPieces);
return {

@@ -65,3 +69,3 @@ isOn: dataPieces[0].toLowerCase() === 'on',

} catch (error) {
console.error(error);
this.logDebug(error);
return null;

@@ -73,7 +77,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'get-power-draw', deviceId]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return null;

@@ -85,7 +89,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'turn', deviceId, (poweredOn ? 'on': 'off')]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -97,7 +101,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-temp', deviceId, (temperatureInCelsius + '')]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -109,7 +113,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-mode', deviceId, mode]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -121,7 +125,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-speed', deviceId, fanSpeed]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -133,7 +137,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-swing-v', deviceId, swingModeV]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -145,7 +149,7 @@ }

try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c', this.country, '-l', this.language, '-v', 'set-swing-h', deviceId, swingModeH]);
console.log(data);
const data: string = await 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) {
console.error(error);
this.logDebug(error);
return false;

@@ -152,0 +156,0 @@ }

@@ -9,10 +9,12 @@ "use strict";

for (const arg of args) {
pythonArgs.push(arg.trim());
if (arg) {
pythonArgs.push(arg.trim());
}
}
return new Promise((resolve, reject) => {
let data = [];
console.log('python3 -u example.py ' + pythonArgs.join(' '));
this.logDebug('python3 -u example.py ' + pythonArgs.join(' '));
const process = spawn('python3', ['-u', 'example.py'].concat(pythonArgs), { cwd: workingDir });
process.stdout.on('data', (output) => {
console.log(output.toString());
this.logDebug(output.toString());
data.push(output.toString());

@@ -19,0 +21,0 @@ if (forceCloseProcessAfterOutput) {

@@ -5,6 +5,10 @@ const {spawn} = require('child_process');

public static logDebug: Function;
public static async executePython3(workingDir: string, scriptName: string, args: string[], forceCloseProcessAfterOutput: boolean = false): Promise<string> {
const pythonArgs: string[] = [];
for (const arg of args) {
pythonArgs.push(arg.trim());
if(arg) {
pythonArgs.push(arg.trim());
}
}

@@ -15,7 +19,7 @@

console.log('python3 -u example.py ' + pythonArgs.join(' '));
this.logDebug('python3 -u example.py ' + pythonArgs.join(' '));
const process = spawn('python3', ['-u', 'example.py'].concat(pythonArgs), {cwd: workingDir});
process.stdout.on('data', (output: any) => {
console.log(output.toString());
this.logDebug(output.toString());
data.push(output.toString());

@@ -22,0 +26,0 @@ if (forceCloseProcessAfterOutput) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc