Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Implementing & testing functions
Browse files Browse the repository at this point in the history
setting mode, v-swing & h-swing working
  • Loading branch information
Kevin Van den Abeele committed Jun 1, 2020
1 parent e3413a0 commit 5a9cc16
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 10 deletions.
30 changes: 27 additions & 3 deletions resources/wideq/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,27 @@ def set_temp(client, device_id, temp):
"""Set the configured temperature for an AC device."""

ac = wideq.ACDevice(client, _force_device(client, device_id))
ac.set_fahrenheit(int(temp))
ac.set_celsius(int(temp))


def set_mode(client, device_id, mode):
ac = wideq.ACDevice(client, _force_device(client, device_id))
ac.set_mode(wideq.ACMode[mode])


def set_fan_speed(client, device_id, speed):
ac = wideq.ACDevice(client, _force_device(client, device_id))
ac.set_fan_speed(wideq.ACFanSpeed[speed])


def set_swing_mode_v(client, device_id, swing_mode_v):
ac = wideq.ACDevice(client, _force_device(client, device_id))
ac.set_vert_swing(wideq.ACVSwingMode[swing_mode_v])


def set_swing_mode_h(client, device_id, swing_mode_h):
ac= wideq.ACDevice(client, _force_device(client, device_id))
ac.set_horz_swing(wideq.ACHSwingMode[swing_mode_h])


def turn(client, device_id, on_off):
Expand Down Expand Up @@ -162,9 +182,13 @@ def ac_config(client, device_id):
'ls': ls,
'mon': mon,
'ac-mon': ac_mon,
'set-temp': set_temp,
'turn': turn,
'ac-config': ac_config,
'turn': turn,
'set-temp': set_temp,
'set-mode': set_mode,
'set-speed': set_fan_speed,
'set-swing-v': set_swing_mode_v,
'set-swing-h': set_swing_mode_h
}


Expand Down
148 changes: 144 additions & 4 deletions src/lg/wideq-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class WideqAdapter {
}

public async listAirCoolers(): Promise<Array<AirCooler>> {
const data: string = await this.pythonUtils.executePython3(this.wideqScriptFile,['ls', '-c ' + this.country, '-l ' + this.language, '-v']);
const data: string = await this.pythonUtils.executePython3(this.wideqScriptFile, ['-c ' + this.country, '-l ' + this.language, '-v', 'ls']);

const devices = data.split('\n');

Expand All @@ -44,16 +44,156 @@ export class WideqAdapter {

return processedDevices;
}

public async getStatus(): Promise<AirCoolerStatus> {
return null;
}

public async setPowerOnOff(deviceId: string, poweredOn: boolean): Promise<boolean> {
return false;
}

public async setTargetTemperature(deviceId: string, temperatureInCelcius: number): Promise<boolean> {
return false;
}

public async setMode(deviceId: string, mode: Mode): Promise<boolean> {
try {
const data: string = await this.pythonUtils.executePython3(this.wideqScriptFile, ['-c ' + this.country, '-l ' + this.language, '-v', 'set-mode ' + deviceId + ' ' + mode]);
console.log(data);
return true;
} catch (error) {
console.error(error);
return false;
}
}

public async setFanSpeed(deviceId: string, fanSpeed: FanSpeed): Promise<boolean> {
return false;
}

public async setSwingModeV(deviceId: string, swingModeV: VSwingMode): Promise<boolean> {
try {
const data: string = await this.pythonUtils.executePython3(this.wideqScriptFile, ['-c ' + this.country, '-l ' + this.language, '-v', 'set-swing-v ' + deviceId + ' ' + swingModeV]);
console.log(data);
return true;
} catch (error) {
console.error(error);
return false;
}
}

public async setSwingModeH(deviceId: string, swingModeH: HSwingMode): Promise<boolean> {
try {
const data: string = await this.pythonUtils.executePython3(this.wideqScriptFile, ['-c ' + this.country, '-l ' + this.language, '-v', 'set-swing-h ' + deviceId + ' ' + swingModeH]);
console.log(data);
return true;
} catch (error) {
console.error(error);
return false;
}
}
}

//TODO: Testing only!
setTimeout(async () => {
const test = new WideqAdapter('BE', 'en-UK');
const result = await test.listAirCoolers();
console.log(result);
const testAdapter = new WideqAdapter('BE', 'en-UK');
const airCoolers: AirCooler[] = await testAdapter.listAirCoolers();
const airCooler: AirCooler = airCoolers[0];
console.log(airCooler);
const status: AirCoolerStatus = await testAdapter.getStatus();
console.log(status);

const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};

let success: boolean = false;
//success = await testAdapter.setMode(airCooler.deviceId, Mode.COOL);
success = await testAdapter.setSwingModeV(airCooler.deviceId, VSwingMode.ONE);
console.log(success);
await sleep(2500);
success = await testAdapter.setSwingModeH(airCooler.deviceId, HSwingMode.ONE);
console.log(success);
});

export interface AirCooler {
deviceId: string;
deviceType: string;
}

export interface AirCoolerStatus {

}

/*
* WIDEQ AC related enums
* Please check ac.py for updated values & documentation
**/

export enum HSwingMode {
OFF = "OFF",
ONE = "ONE",
TWO = "TWO",
THREE = "THREE",
FOUR = "FOUR",
FIVE = "FIVE",
LEFT_HALF = "LEFT_HALF",
RIGHT_HALF = "RIGHT_HALF",
ALL = "ALL",
}

export enum VSwingMode {
OFF = "OFF",
ONE = "ONE",
TWO = "TWO",
THREE = "THREE",
FOUR = "FOUR",
FIVE = "FIVE",
SIX = "SIX",
ALL = "ALL"
}

export enum Mode {
COOL = "COOL",
DRY = "DRY",
FAN = "FAN",
AI = "AI",
HEAT = "HEAT",
AIRCLEAN = "AIRCLEAN",
ACO = "ACO",
AROMA = "AROMA",
ENERGY_SAVING = "ENERGY_SAVING",
ENERGY_SAVER = "ENERGY_SAVER",
}

export enum FanSpeed {
SLOW = 'SLOW',
SLOW_LOW = 'SLOW_LOW',
LOW = 'LOW',
LOW_MID = 'LOW_MID',
MID = 'MID',
MID_HIGH = 'MID_HIGH',
HIGH = 'HIGH',
POWER = 'POWER',
AUTO = 'AUTO',
NATURE = 'NATURE',
R_LOW = 'R_LOW',
R_MID = 'R_MID',
R_HIGH = 'R_HIGH',
L_LOW = 'L_LOW',
L_MID = 'L_MID',
L_HIGH = 'L_HIGH',
L_LOWR_LOW = 'L_LOWR_LOW',
L_LOWR_MID = 'L_LOWR_MID',
L_LOWR_HIGH = 'L_LOWR_HIGH',
L_MIDR_LOW = 'L_MIDR_LOW',
L_MIDR_MID = 'L_MIDR_MID',
L_MIDR_HIGH = 'L_MIDR_HIGH',
L_HIGHR_LOW = 'L_HIGHR_LOW',
L_HIGHR_MID = 'L_HIGHR_MID',
L_HIGHR_HIGH = 'L_HIGHR_HIGH',
AUTO_2 = 'AUTO_2',
POWER_2 = 'POWER_2',
LONGPOWER = 'LONGPOWER'
}
6 changes: 3 additions & 3 deletions src/utils/python-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const exec = require('child_process').exec;

export class PythonUtils {

private readonly workingdDir: string;
private readonly workingDir: string;

constructor(workingDir: string) {
this.workingdDir = workingDir;
this.workingDir = workingDir;
}

public async executePython3(scriptName: string, args: string[], forceCloseProcessAfterOutput: boolean = false): Promise<string> {
Expand All @@ -18,7 +18,7 @@ export class PythonUtils {
let data: string[] = [];

console.log('python3 -u example.py ' + pythonArgs.join(' '));
const process = exec('python3 -u example.py ' + pythonArgs.join(' '), {cwd: this.workingdDir}, (error: any) => {
const process = exec('python3 -u example.py ' + pythonArgs.join(' '), {cwd: this.workingDir}, (error: any) => {
if (error) {
console.error(error);
reject(error);
Expand Down

0 comments on commit 5a9cc16

Please sign in to comment.