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

Commit

Permalink
Fixed some issues
Browse files Browse the repository at this point in the history
first tests in homekit seem to be positive!
  • Loading branch information
Kevin Van den Abeele committed Jun 3, 2020
1 parent 2fbf4b6 commit 7c986cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
29 changes: 5 additions & 24 deletions src/lg-airco-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Units
} from "homebridge";

import {AirCooler, FanSpeed, HSwingMode, Mode, VSwingMode, WideqAdapter} from "./lg/wideq-adapter";
import {AirCooler, HSwingMode, Mode, VSwingMode, WideqAdapter} from "./lg/wideq-adapter";
import {LgAircoController} from "./lg/lg-airco-controller";
import {AsyncUtils} from "./utils/async-utils";
import {DummyController} from "./lg/dummy-controller";
Expand Down Expand Up @@ -68,10 +68,10 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
return;
}

//this.controller = new LgAircoController(this.airCooler, config.updateInterval);
this.controller = new DummyController(this.airCooler, config.updateInterval);
this.handleRotationSpeedSetWithDebounce = AsyncUtils.debounce((newFanSpeed: FanSpeed) => {
this.controller.setFanSpeed(newFanSpeed);
this.controller = new LgAircoController(this.airCooler, config.updateInterval);
//this.controller = new DummyController(this.airCooler, config.updateInterval);
this.handleRotationSpeedSetWithDebounce = AsyncUtils.debounce((newFanSpeed: number) => {
this.controller.setFanSpeed(WideqAdapter.percentageToFanSpeed(newFanSpeed));
}, 5000);

this.heaterCoolerService.getCharacteristic(this.hap.Characteristic.Active)
Expand Down Expand Up @@ -141,8 +141,6 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleActiveGet(callback: CharacteristicGetCallback): void {
console.log('Getting ACTIVE...');
console.log(this.controller.isPoweredOn() ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE);
callback(null, this.controller.isPoweredOn() ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE);
}

Expand All @@ -156,9 +154,7 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleCurrentHeaterCoolerStateGet(callback: CharacteristicGetCallback): void {
console.log('Getting CURRENT STATE...');
let currentHeaterCoolerState: any;

if (!this.controller.isPoweredOn()) {
currentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
} else {
Expand All @@ -181,13 +177,10 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
break;
}
}

console.log(currentHeaterCoolerState);
callback(null, currentHeaterCoolerState)
}

private handleTargetHeaterCoolerStateGet(callback: CharacteristicGetCallback): void {
console.log('Getting TARGET STATE...');
//This is the same in this implementation!
this.handleCurrentHeaterCoolerStateGet(callback);
}
Expand All @@ -212,14 +205,10 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleCurrentTemperatureGet(callback: CharacteristicGetCallback): void {
console.log('Getting CURRENT TEMP...');
console.log(this.controller.getCurrentTemperatureInCelsius());
callback(null, this.controller.getCurrentTemperatureInCelsius());
}

private handleCoolingThresholdTemperatureGet(callback: CharacteristicGetCallback): void {
console.log('Getting COOLING TEMP...');
console.log(this.controller.getTargetCoolingTemperatureInCelsius());
callback(null, this.controller.getTargetCoolingTemperatureInCelsius());
}

Expand All @@ -233,8 +222,6 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleHeatingThresholdTemperatureGet(callback: CharacteristicGetCallback): void {
console.log('Getting HEATING TEMP...');
console.log(this.controller.getTargetHeatingTemperatureInCelsius());
callback(null, this.controller.getTargetHeatingTemperatureInCelsius());
}

Expand All @@ -248,8 +235,6 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleRotationSpeedGet(callback: CharacteristicGetCallback): void {
console.log('Getting FAN SPEED...');
console.log(Math.round(WideqAdapter.fanSpeedToPercentage(this.controller.getFanSpeed())));
callback(null, Math.round(WideqAdapter.fanSpeedToPercentage(this.controller.getFanSpeed())));
}

Expand All @@ -263,10 +248,6 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleSwingModeGet(callback: CharacteristicGetCallback): void {
console.log('Getting SWING MODE...');
console.log(this.controller.getHorizontalSwingMode() === HSwingMode.ALL &&
this.controller.getVerticalSwingMode() === VSwingMode.ALL ?
this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED);
callback(null,
this.controller.getHorizontalSwingMode() === HSwingMode.ALL &&
this.controller.getVerticalSwingMode() === VSwingMode.ALL ?
Expand Down
22 changes: 19 additions & 3 deletions src/lg/dummy-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ export class DummyController extends Controller {
this.isOn = true;
this.mode = Mode.COOL;
this.currentTemperatureInCelsius = 24;
this.targetTemperatureInCelsius = 18;
this.fanSpeed = FanSpeed.HIGH;
this.powerDraw = 50;

this.swingModeH = HSwingMode.ALL;
this.swingModeV = VSwingMode.ALL;

this.targetCoolingTemperatureInCelsius = 18;
this.targetHeatingTemperatureInCelsius = 18;
this.targetHeatingTemperatureInCelsius = 21;
}

public isPoweredOn(): boolean {
Expand All @@ -29,11 +28,12 @@ export class DummyController extends Controller {
public async setPowerState(powerOn: boolean): Promise<void> {
if (this.isOn !== powerOn) {
this.isOn = powerOn;
console.log('Setting power value: ' + powerOn);
console.log('Setting power value: ' + (powerOn ? 'ON' : 'OFF'));
}
}

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

Expand All @@ -43,32 +43,45 @@ export class DummyController extends Controller {
this.mode = newTargetMode;
console.log('Setting mode value: ' + newTargetMode);
await this.setTargetTemperatureInCelsius(this.mode === Mode.COOL ? this.targetCoolingTemperatureInCelsius : this.targetHeatingTemperatureInCelsius);
} else {
this.setPowerState(true);
}
}

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

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

public setTargetCoolingTemperatureInCelsius(newTargetCoolingTemperatureInCelsius: number): void {
if (this.targetCoolingTemperatureInCelsius !== newTargetCoolingTemperatureInCelsius) {
this.isOn = true;
this.targetCoolingTemperatureInCelsius = newTargetCoolingTemperatureInCelsius;

if(this.mode === Mode.COOL) {
this.setTargetTemperatureInCelsius(this.targetCoolingTemperatureInCelsius);
}
}
}

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

public setTargetHeatingTemperatureInCelsius(newTargetHeatingTemperatureInCelsius: number): void {
if (this.targetHeatingTemperatureInCelsius !== newTargetHeatingTemperatureInCelsius) {
this.isOn = true;
this.targetHeatingTemperatureInCelsius = newTargetHeatingTemperatureInCelsius;

if(this.mode === Mode.HEAT) {
this.setTargetTemperatureInCelsius(this.targetHeatingTemperatureInCelsius);
}
}
}

Expand All @@ -81,6 +94,7 @@ export class DummyController extends Controller {
}

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

Expand All @@ -93,6 +107,7 @@ export class DummyController extends Controller {
}

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

Expand All @@ -105,6 +120,7 @@ export class DummyController extends Controller {
}

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

Expand Down
12 changes: 12 additions & 0 deletions src/lg/lg-airco-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class LgAircoController extends Controller {
this.mode = status.mode;
this.currentTemperatureInCelsius = status.currentTempInCelsius;
this.targetTemperatureInCelsius = status.targetTempInCelsius;
this.targetCoolingTemperatureInCelsius = status.targetTempInCelsius;
this.targetHeatingTemperatureInCelsius = status.targetTempInCelsius;
this.fanSpeed = status.fanSpeed;
}

Expand Down Expand Up @@ -58,6 +60,8 @@ export class LgAircoController extends Controller {
throw new Error('Could not change operational mode of the AC unit!');
}
await this.setTargetTemperatureInCelsius(this.mode === Mode.COOL ? this.targetCoolingTemperatureInCelsius : this.targetHeatingTemperatureInCelsius);
} else {
await this.setPowerState(true);
}
}

Expand All @@ -73,6 +77,10 @@ export class LgAircoController extends Controller {
if (this.targetCoolingTemperatureInCelsius !== newTargetCoolingTemperatureInCelsius) {
this.isOn = true;
this.targetCoolingTemperatureInCelsius = newTargetCoolingTemperatureInCelsius;

if(this.mode === Mode.COOL) {
this.setTargetTemperatureInCelsius(this.targetCoolingTemperatureInCelsius);
}
}
}

Expand All @@ -84,6 +92,10 @@ export class LgAircoController extends Controller {
if (this.targetHeatingTemperatureInCelsius !== newTargetHeatingTemperatureInCelsius) {
this.isOn = true;
this.targetHeatingTemperatureInCelsius = newTargetHeatingTemperatureInCelsius;

if(this.mode === Mode.HEAT) {
this.setTargetTemperatureInCelsius(this.targetHeatingTemperatureInCelsius);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lg/wideq-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class WideqAdapter {

public async setPowerOnOff(deviceId: string, poweredOn: boolean): Promise<boolean> {
try {
const data: string = await PythonUtils.executePython3(WideqAdapter.wideqFolder, WideqAdapter.wideqScriptFile, ['-c ' + this.country, '-l ' + this.language, '-v', 'turn ' + deviceId + ' ' + poweredOn ? 'on': 'off']);
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);
return true;
} catch (error) {
Expand Down

0 comments on commit 7c986cb

Please sign in to comment.