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, data is retrieved correctly now
Browse files Browse the repository at this point in the history
Except for fan speed, always zero at start, to be investigated
  • Loading branch information
Kevin Van den Abeele committed Jun 2, 2020
1 parent 127496f commit 01c042a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 72 deletions.
40 changes: 25 additions & 15 deletions src/lg-airco-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
this.log = log;
this.config = config;

this.informationService = new this.hap.Service.AccessoryInformation();
this.heaterCoolerService = new this.hap.Service.HeaterCooler(config.name);
this.informationService = new this.hap.Service.AccessoryInformation()
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'LG')
.setCharacteristic(this.hap.Characteristic.Model, 'AIR CONDITIONER')
.setCharacteristic(this.hap.Characteristic.SerialNumber, this.config.model);
this.heaterCoolerService = new this.hap.Service.HeaterCooler(this.config.name);

setTimeout(async () => {
console.log(this.config);
Expand All @@ -61,11 +64,6 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
//TODO: Update interval from config, default now is 30 seconds.
this.controller = new LgAircoController(this.airCooler);

this.informationService
.setCharacteristic(this.hap.Characteristic.Manufacturer, "LG")
.setCharacteristic(this.hap.Characteristic.Model, this.airCooler.deviceType)
.setCharacteristic(this.hap.Characteristic.SerialNumber, this.airCooler.modelName);

this.heaterCoolerService.getCharacteristic(this.hap.Characteristic.Active)
.on(CharacteristicEventTypes.GET, this.handleActiveGet.bind(this))
.on(CharacteristicEventTypes.SET, this.handleActiveSet.bind(this));
Expand Down Expand Up @@ -139,7 +137,9 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleActiveSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting ACTIVE: ' + value);
//TODO: Implement!
callback(null);
}

private handleCurrentHeaterCoolerStateGet(callback: CharacteristicGetCallback): void {
Expand Down Expand Up @@ -180,7 +180,9 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleTargetHeaterCoolerStateSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting TARGET STATE: ' + value);
//TODO: Implement!
callback(null);
}

private handleCurrentTemperatureGet(callback: CharacteristicGetCallback): void {
Expand All @@ -196,7 +198,9 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleCoolingThresholdTemperatureSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting COOLING TEMP: ' + value);
//TODO: Implement!
callback(null);
}

private handleHeatingThresholdTemperatureGet(callback: CharacteristicGetCallback): void {
Expand All @@ -206,17 +210,21 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleHeatingThresholdTemperatureSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting HEATING TEMP: ' + value);
//TODO: Implement!
callback(null);
}

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

private handleRotationSpeedSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting FAN SPEED: ' + value);
//TODO: Implement!
callback(null);
}

private handleSwingModeGet(callback: CharacteristicGetCallback): void {
Expand All @@ -232,6 +240,8 @@ export class LgAirCoolerAccessory implements AccessoryPlugin {
}

private handleSwingModeSet(value: CharacteristicValue, callback: CharacteristicSetCallback): void {

console.log('Setting SWING MODE: ' + value);
//TODO: Implement!
callback(null);
}
}
30 changes: 12 additions & 18 deletions src/lg/lg-airco-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,25 @@ export class LgAircoController {

constructor(airCooler: AirCooler, updateInterval: number = 30000) {
this.adapter = new WideqAdapter(airCooler.country, airCooler.language);

this.airCooler = airCooler;

//TODO: Fetch & assign initial state
this.isOn = false;
this.mode = Mode.COOL;
this.currentTemperatureInCelsius = -1;
this.targetTemperatureInCelsius = 18;
this.swingModeH = HSwingMode.ALL;
this.swingModeV = VSwingMode.ALL;
this.fanSpeed = FanSpeed.LOW;
this.powerDraw = 0;

this.update();
setInterval(async () => {
//TODO: If an action is still pending, postpone state update?
const status = await this.adapter.getStatus(this.airCooler.deviceId);
this.powerDraw = await this.adapter.getCurrentPowerUsage(this.airCooler.deviceId);
this.isOn = status.isOn;
this.mode = status.mode;
this.currentTemperatureInCelsius = status.currentTempInCelsius;
this.targetTemperatureInCelsius = status.targetTempInCelsius;
this.fanSpeed = status.fanSpeed;
await this.update();
}, updateInterval);
}

private async update(): Promise<void> {
const status = await this.adapter.getStatus(this.airCooler.deviceId);
this.powerDraw = await this.adapter.getCurrentPowerUsage(this.airCooler.deviceId);
this.isOn = status.isOn;
this.mode = status.mode;
this.currentTemperatureInCelsius = status.currentTempInCelsius;
this.targetTemperatureInCelsius = status.targetTempInCelsius;
this.fanSpeed = status.fanSpeed;
}

public isPoweredOn(): boolean {
return this.isOn;
}
Expand Down
39 changes: 0 additions & 39 deletions src/lg/wideq-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,45 +206,6 @@ export class WideqAdapter {
}
}

//TODO: Testing only!
setTimeout(async () => {
const sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
};

const airCoolers: AirCooler[] = await WideqAdapter.listAirCoolers('BE', 'en-UK');
const airCooler: AirCooler = airCoolers[0];
console.log(airCooler);

const testAdapter = new WideqAdapter('BE', 'en-UK');
let status: AirCoolerStatus = await testAdapter.getStatus(airCooler.deviceId);
console.log(status);
await sleep(2500);
console.log(await testAdapter.getCurrentPowerUsage(airCooler.deviceId) + ' watts');

let success: boolean = false;
/*
await sleep(2500);
success = await testAdapter.setMode(airCooler.deviceId, Mode.COOL);
*/

/*
await sleep(2500);
success = await testAdapter.setFanSpeed(airCooler.deviceId, FanSpeed.HIGH);
*/

/*
await sleep(2500);
success = await testAdapter.setSwingModeV(airCooler.deviceId, VSwingMode.ALL);
await sleep(2500);
success = await testAdapter.setSwingModeH(airCooler.deviceId, HSwingMode.ALL);
await sleep(2500);
success = await testAdapter.setTargetTemperature(airCooler.deviceId, 18);
await sleep(2500);
success = await testAdapter.setFanSpeed(airCooler.deviceId, FanSpeed.HIGH);
*/
});

export interface AirCooler {
deviceId: string;
deviceType: string;
Expand Down

0 comments on commit 01c042a

Please sign in to comment.