Skip to content

Commit

Permalink
fix: improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 6, 2024
1 parent fb6a752 commit 4380902
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Porsche Taycan",
"name": "homebridge-porsche-taycan",
"version": "1.19.0",
"version": "1.20.0",
"description": "Control your Porsche Taycan through the home app",
"license": "Apache-2.0",
"author": "Jasper Seinhorst",
Expand Down
46 changes: 30 additions & 16 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
public PorscheConnectAuth: PorscheConnect | undefined;
private platformVehicles: PlatformVehicle[] = [];
private heartBeatInterval: number;
private readonly updateErrorText: string = 'You vehicle seems to be in privacy mode.';
private readonly authenticationErrorText: string = `Please log in to your Porsche account on my.porsche.com or via
the official Porsche app on your mobile device to access this feature. Once in a while Porsche needs you to fill
in the captscha. Logging in on my.porsche.com or the official Porsche app on your mobile resets the need for a
log in with captscha. If the error persist double check your username and password.`;

constructor(public readonly log: Logger, public readonly config: PlatformConfig, public readonly api: API) {
this.heartBeatInterval = (config.pollInterval || 15) * 60 * 1000;
Expand All @@ -28,22 +33,23 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {

private async initialise() {
if (!this.validateConfig()) {
this.log.warn('Please specify your Porsche Connect username and password in your config file');
this.log.error('Please specify your Porsche Connect username and password in your config file');
return;
}

try {
this.log.info('Authentication');
this.PorscheConnectAuth = new PorscheConnect({ username: this.config.username, password: this.config.password});
this.log.info('Retrieving available vehicles');
await this.discoverVehicles();
await this.heartBeat();
} catch (error) {
this.log.error('Porsche Connect connection failed');
this.log.debug('Reason: ', error);
this.log.info(this.authenticationErrorText);
this.log.debug('Debug info: ', error);
return;
}

this.log.info('Retrieving available vehicles');
await this.discoverVehicles();
await this.heartBeat();

setInterval(() => {
this.heartBeat();
}, this.heartBeatInterval);
Expand Down Expand Up @@ -171,18 +177,26 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
this.platformVehicles.forEach(async (platformVehicle: PlatformVehicle) => {
this.log.debug(`Updating vehicle data for ${platformVehicle.vehicle.nickname}`);
const vehicle = platformVehicle.vehicle;
const emobilityInfo = await vehicle.getEmobilityInfo();
const positionInfo = await vehicle.getPosition();

if (emobilityInfo.batteryChargeStatus === null) {
this.log.error('Your PCM seems to be in private mode');
this.log.debug('Reason: ', emobilityInfo);
return;
}
try {
const emobilityInfo = await vehicle.getEmobilityInfo();
const positionInfo = await vehicle.getPosition();

platformVehicle.accessories.forEach((accessory: PorscheAccessory) => {
accessory.beat(emobilityInfo, positionInfo, vehicle);
});
if (emobilityInfo.batteryChargeStatus === null) {
this.log.error('Your PCM seems to be in private mode');
this.log.info(this.updateErrorText);
this.log.debug('Reason: ', emobilityInfo);
return;
}

platformVehicle.accessories.forEach((accessory: PorscheAccessory) => {
accessory.beat(emobilityInfo, positionInfo, vehicle);
});
} catch(error){
this.log.error('Updating vehicle data failed');
this.log.info(this.updateErrorText);
this.log.debug('Debug info: ', error);
}
});
}
}

0 comments on commit 4380902

Please sign in to comment.