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

Commit

Permalink
Getting there
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Van den Abeele committed Jun 2, 2020
1 parent 8f1b223 commit b95b631
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/lg-airco-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
private handleActiveSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {
console.log('Setting ACTIVE: ' + value);
if (!this.powerStateWillChange) {
console.log('POWERING UP BY COMMAND!')
//TODO: Implement!
console.log('POWERING UP BY COMMAND!');

this.controller.setPowerState(value === this.hap.Characteristic.Active.ACTIVE);
} else {
this.powerStateWillChange = false;
}
callback(null);
}
Expand Down Expand Up @@ -197,7 +200,17 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
this.powerStateWillChange = true;
}

//TODO: Implement!
switch (value) {
case this.hap.Characteristic.TargetHeaterCoolerState.COOL:
this.controller.setMode(Mode.COOL);
break;
case this.hap.Characteristic.TargetHeaterCoolerState.HEAT:
this.controller.setMode(Mode.HEAT);
break;
case this.hap.Characteristic.TargetHeaterCoolerState.AUTO:
break;
}

callback(null);
}

Expand Down Expand Up @@ -277,7 +290,18 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
this.powerStateWillChange = true;
}

//TODO: Implement!
setTimeout(async () => {
if (value === this.hap.Characteristic.SwingMode.SWING_ENABLED) {
await this.controller.setHorizontalSwingMode(HSwingMode.ALL);
await AsyncUtils.sleep(2000);
await this.controller.setVerticalSwingMode(VSwingMode.ALL);
} else {
await this.controller.setHorizontalSwingMode(HSwingMode.OFF);
await AsyncUtils.sleep(2000);
await this.controller.setVerticalSwingMode(VSwingMode.OFF);
}
});

callback(null);
}
}
4 changes: 4 additions & 0 deletions src/lg/lg-airco-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class LgAircoController {
private mode: Mode;
private currentTemperatureInCelsius: number;
private targetTemperatureInCelsius: number;

private targetCoolingTemperatureInCelsius: number;
private targetHeatingTemperatureInCelsius: number;

private swingModeH: HSwingMode;
private swingModeV: VSwingMode;
private fanSpeed: FanSpeed;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/async-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export class AsyncUtils {

return debounced as (...args: Parameters<F>) => ReturnType<F>;
};

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

0 comments on commit b95b631

Please sign in to comment.