Skip to content

Commit

Permalink
Merge pull request #122 from neoPix/feat/setNavigationRoute
Browse files Browse the repository at this point in the history
feat(eu): navigation route
  • Loading branch information
Hacksore authored Mar 25, 2021
2 parents 74ad78e + b82926e commit 440dfae
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
17 changes: 16 additions & 1 deletion debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,22 @@ async function performCommand(command) {
console.log('targets : ' + JSON.stringify(targets, null, 2));
break;
case 'setChargeTargets':
await vehicle.setChargeTargets({ fast: 80, slow: 80 });
const { fast, slow } = await inquirer
.prompt([
{
type: 'list',
name: 'fast',
message: 'What fast charge limit do you which to set?',
choices: [50, 60, 70, 80, 90, 100],
},
{
type: 'list',
name: 'slow',
message: 'What slow charge limit do you which to set?',
choices: [50, 60, 70, 80, 90, 100],
}
]);
await vehicle.setChargeTargets({ fast, slow });
console.log('targets : OK');
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/common.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,4 @@ export interface VehicleDayTrip {
};
distance: number;
}[];
}
}
17 changes: 17 additions & 0 deletions src/interfaces/european.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@ export interface EuropeanEndpoints {
redirect_uri: string;
token: string;
}

export interface EUPOIInformation {
phone: string;
waypointID: number;
lang: 1;
src: 'HERE';
coords: {
lat: number;
alt: number;
long: number;
type: 0;
},
addr: string;
zip: string;
placeid: string;
name: string;
}
30 changes: 30 additions & 0 deletions src/vehicles/european.vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { EuropeanController } from '../controllers/european.controller';
import { celciusToTempCode, tempCodeToCelsius } from '../util';
import { manageBluelinkyError, ManagedBluelinkyError } from '../tools/common.tools';
import { addMinutes, parse as parseDate } from 'date-fns';
import { EUPOIInformation } from '../interfaces/european.interfaces';

type ChargeTarget = 50 | 60 | 70 | 80 | 90 | 100;
const POSSIBLE_CHARGE_LIMIT_VALUES = [50, 60, 70, 80, 90, 100];
Expand Down Expand Up @@ -637,6 +638,35 @@ export default class EuropeanVehicle extends Vehicle {
throw manageBluelinkyError(err, 'EuropeVehicle.setChargeTargets');
}
}

/**
* Define a navigation route
* @param poiInformations The list of POIs and waypoint to go through
*/
public async setNavigation(poiInformations: EUPOIInformation[]): Promise<void> {
await this.checkControlToken();
try {
await got(
`${this.controller.environment.baseUrl}/api/v2/spa/vehicles/${this.vehicleConfig.id}/location/routes`,
{
method: 'POST',
headers: {
'Authorization': this.controller.session.controlToken,
'ccsp-device-id': this.controller.session.deviceId,
'Content-Type': 'application/json',
'Stamp': this.controller.environment.stamp(),
},
body: {
deviceID: this.controller.session.deviceId,
poiInfoList: poiInformations,
},
json: true,
}
);
} catch (err) {
throw manageBluelinkyError(err, 'EuropeVehicle.setNavigation');
}
}
}

function toMonthDate(month: { year: number; month: number; }) {
Expand Down

0 comments on commit 440dfae

Please sign in to comment.