Skip to content

Commit

Permalink
feat: debugMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ghosty2004 committed Jul 2, 2024
1 parent ca876a0 commit 4dd929f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ This is a homebridge plugin which allow to send commands to your <a href="https:
- `Device Nickname` - the nickname of your AC device (this should be the nickname of your AC which can be found in ConnectLife app, see <a href="https://i.imgur.com/sR6uY3u.png">this</a>)
- `Login ID` - your E-Mail from ConnectLife
- `Password` - your password from ConnectLife
- `Debug Mode` - you want to see more informations about what't going on ?
6 changes: 6 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"title": "Password",
"type": "string",
"required": true
},
"debugMode": {
"title": "Debug Mode",
"type": "integer",
"required": true,
"default": 0
}
}
}
Expand Down
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.3.1",
"version": "1.3.2",
"description": "Control your ConnectLife air conditioner with Homebridge",
"license": "Apache-2.0",
"homepage": "https://github.com/ghosty2004/homebridge-connectlife-ac",
Expand Down
36 changes: 29 additions & 7 deletions src/accessory/TemperatureAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WorkModes } from '../constants';
import { celsiusToFahrenheit, fahrenheitToCelsius } from '../utils';

export class TemperatureAccessory {
private debugMode: boolean;
private deviceNickName: string;
private connectLifeApi: ConnectLifeApi;
private service: Service;
Expand All @@ -19,8 +20,12 @@ export class TemperatureAccessory {
throw new Error('Missing required config');
}

this.debugMode = !!platform.config?.debugMode;
this.deviceNickName = deviceNickName;
this.connectLifeApi = new ConnectLifeApi(loginID, password);
this.connectLifeApi = new ConnectLifeApi(loginID, password, {
debugMode: this.debugMode,
log: platform.log,
});

this.accessory
.getService(this.platform.Service.AccessoryInformation)!
Expand Down Expand Up @@ -88,7 +93,9 @@ export class TemperatureAccessory {
t_power: value,
});

this.platform.log.info('Set Active', value);
if (this.debugMode) {
this.platform.log.info('Set Active', value);
}
}

async getActive(): Promise<CharacteristicValue> {
Expand All @@ -106,7 +113,10 @@ export class TemperatureAccessory {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_work_mode: WorkModes.Auto,
});
this.platform.log.info('Set CurrentTemperature', _value);

if (this.debugMode) {
this.platform.log.info('Set CurrentTemperature', _value);
}
}

async getCurrentTemperature(): Promise<CharacteristicValue> {
Expand All @@ -123,7 +133,10 @@ export class TemperatureAccessory {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_up_down: value,
});
this.platform.log.info('Set SwingMode', value);

if (this.debugMode) {
this.platform.log.info('Set SwingMode', value);
}
}

async getSwingMode(): Promise<CharacteristicValue> {
Expand All @@ -149,7 +162,10 @@ export class TemperatureAccessory {
t_temp: t_temp_type === 1 ? celsiusToFahrenheit(value as number) : value,
t_work_mode: WorkModes.Cool,
});
this.platform.log.info('Set CoolingThresholdTemperature', value);

if (this.debugMode) {
this.platform.log.info('Set CoolingThresholdTemperature', value);
}
}

async getCoolingThresholdTemperature(): Promise<CharacteristicValue> {
Expand Down Expand Up @@ -179,7 +195,10 @@ export class TemperatureAccessory {
t_temp: t_temp_type === 1 ? celsiusToFahrenheit(value as number) : value,
t_work_mode: WorkModes.Heat,
});
this.platform.log.info('Set HeatingThresholdTemperature', value);

if (this.debugMode) {
this.platform.log.info('Set HeatingThresholdTemperature', value);
}
}

async getHeatingThresholdTemperature(): Promise<CharacteristicValue> {
Expand All @@ -201,7 +220,10 @@ export class TemperatureAccessory {
this.connectLifeApi.changeDeviceProperties(this.deviceNickName, {
t_temp_type: value,
});
this.platform.log.info('Set TemperatureDisplayUnits', value);

if (this.debugMode) {
this.platform.log.info('Set TemperatureDisplayUnits', value);
}
}

async getTemperatureDisplayUnits(): Promise<CharacteristicValue> {
Expand Down
13 changes: 12 additions & 1 deletion src/lib/ConnectLifeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import NodeCache from 'node-cache';
import { Appliance } from '../interfaces';
import { CharacteristicValue } from 'homebridge';
import { ConnectLifeAcPlatformPlugin } from '../platform';

axios.defaults.headers['User-Agent'] = 'connectlife-api-connector 2.1.11';

Expand All @@ -11,6 +12,10 @@ export class ConnectLifeApi {
constructor(
private readonly loginID: string,
private readonly password: string,
private readonly options: {
debugMode?: boolean;
log?: ConnectLifeAcPlatformPlugin['log'];
} = {},
) {}

async getAccessToken() {
Expand Down Expand Up @@ -138,7 +143,7 @@ export class ConnectLifeApi {
deviceNickname: string,
properties: T,
) {
return axios
const result = await axios
.get<Appliance[]>('https://connectlife.bapi.ovh/appliances', {
headers: {
'X-Token': await this.getAccessToken(),
Expand Down Expand Up @@ -173,5 +178,11 @@ export class ConnectLifeApi {
]),
),
}));

if (this.options.debugMode) {
this.options.log?.info('getDeviceProperties', result);
}

return result;
}
}

0 comments on commit 4dd929f

Please sign in to comment.