Skip to content

Commit

Permalink
fix: issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ghosty2004 committed Jul 1, 2024
1 parent e1fa1f3 commit 0572af9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge ConnectLife AC",
"name": "homebridge-connectlife-ac",
"version": "1.2.1",
"version": "1.3.0",
"description": "Control your ConnectLife air conditioner with Homebridge",
"license": "Apache-2.0",
"homepage": "https://github.com/ghosty2004/homebridge-connectlife-ac",
Expand Down
67 changes: 53 additions & 14 deletions src/accessory/TemperatureAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
import { ConnectLifeAcPlatformPlugin } from '../platform';
import { ConnectLifeApi } from '../lib';
import { WorkModes } from '../constants';
import { celsiusToFahrenheit, fahrenheitToCelsius } from '../utils';

export class TemperatureAccessory {
private deviceNickName: string;
Expand Down Expand Up @@ -64,6 +65,11 @@ export class TemperatureAccessory {
)
.onSet(this.setHeatingThresholdTemperature.bind(this))
.onGet(this.getHeatingThresholdTemperature.bind(this));

this.service
.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
.onSet(this.setTemperatureDisplayUnits.bind(this))
.onGet(this.getTemperatureDisplayUnits.bind(this));
}

async setActive(value: CharacteristicValue) {
Expand Down Expand Up @@ -104,14 +110,13 @@ export class TemperatureAccessory {
}

async getCurrentTemperature(): Promise<CharacteristicValue> {
const { t_temp } = await this.connectLifeApi.getDeviceProperties(
this.deviceNickName,
{
const { t_temp, t_temp_type } =
await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
},
);
t_temp_type: 'integer',
});

return t_temp;
return t_temp_type === 1 ? fahrenheitToCelsius(t_temp as number) : t_temp;
}

setSwingMode(value: CharacteristicValue) {
Expand All @@ -122,47 +127,81 @@ export class TemperatureAccessory {
return 0;
}

setCoolingThresholdTemperature(value: CharacteristicValue) {
async setCoolingThresholdTemperature(value: CharacteristicValue) {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(
this.deviceNickName,
{
t_temp_type: 'integer',
},
);

this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp: value,
t_temp: t_temp_type === 1 ? celsiusToFahrenheit(value as number) : value,
t_work_mode: WorkModes.Cool,
});
this.platform.log.info('Set CoolingThresholdTemperature', value);
}

async getCoolingThresholdTemperature(): Promise<CharacteristicValue> {
const { t_temp, t_work_mode } =
const { t_temp, t_temp_type, t_work_mode } =
await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
t_temp_type: 'integer',
t_work_mode: 'integer',
});

if (t_work_mode !== WorkModes.Cool) {
return 10;
}

return t_temp;
return t_temp_type === 1 ? fahrenheitToCelsius(t_temp as number) : t_temp;
}

setHeatingThresholdTemperature(value: CharacteristicValue) {
async setHeatingThresholdTemperature(value: CharacteristicValue) {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(
this.deviceNickName,
{
t_temp_type: 'integer',
},
);

this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp: value,
t_temp: t_temp_type === 1 ? celsiusToFahrenheit(value as number) : value,
t_work_mode: WorkModes.Heat,
});
this.platform.log.info('Set HeatingThresholdTemperature', value);
}

async getHeatingThresholdTemperature(): Promise<CharacteristicValue> {
const { t_temp, t_work_mode } =
const { t_temp, t_temp_type, t_work_mode } =
await this.connectLifeApi.getDeviceProperties(this.deviceNickName, {
t_temp: 'integer',
t_temp_type: 'integer',
t_work_mode: 'integer',
});

if (t_work_mode !== WorkModes.Heat) {
return 0;
}

return t_temp;
return t_temp_type === 1 ? fahrenheitToCelsius(t_temp as number) : t_temp;
}

setTemperatureDisplayUnits(value: CharacteristicValue) {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp_type: value,
});
this.platform.log.info('Set TemperatureDisplayUnits', value);
}

async getTemperatureDisplayUnits(): Promise<CharacteristicValue> {
const { t_temp_type } = await this.connectLifeApi.getDeviceProperties(
this.deviceNickName,
{
t_temp_type: 'integer',
},
);

return t_temp_type;
}
}
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const celsiusToFahrenheit = (celsius: number) => {
return (celsius * 9) / 5 + 32;
};

export const fahrenheitToCelsius = (fahrenheit: number) => {
return ((fahrenheit - 32) * 5) / 9;
};

0 comments on commit 0572af9

Please sign in to comment.