Skip to content

Commit 440dfae

Browse files
authored
Merge pull request #122 from neoPix/feat/setNavigationRoute
feat(eu): navigation route
2 parents 74ad78e + b82926e commit 440dfae

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

debug.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,22 @@ async function performCommand(command) {
174174
console.log('targets : ' + JSON.stringify(targets, null, 2));
175175
break;
176176
case 'setChargeTargets':
177-
await vehicle.setChargeTargets({ fast: 80, slow: 80 });
177+
const { fast, slow } = await inquirer
178+
.prompt([
179+
{
180+
type: 'list',
181+
name: 'fast',
182+
message: 'What fast charge limit do you which to set?',
183+
choices: [50, 60, 70, 80, 90, 100],
184+
},
185+
{
186+
type: 'list',
187+
name: 'slow',
188+
message: 'What slow charge limit do you which to set?',
189+
choices: [50, 60, 70, 80, 90, 100],
190+
}
191+
]);
192+
await vehicle.setChargeTargets({ fast, slow });
178193
console.log('targets : OK');
179194
break;
180195
}

src/interfaces/common.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,4 @@ export interface VehicleDayTrip {
493493
};
494494
distance: number;
495495
}[];
496-
}
496+
}

src/interfaces/european.interfaces.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@ export interface EuropeanEndpoints {
44
redirect_uri: string;
55
token: string;
66
}
7+
8+
export interface EUPOIInformation {
9+
phone: string;
10+
waypointID: number;
11+
lang: 1;
12+
src: 'HERE';
13+
coords: {
14+
lat: number;
15+
alt: number;
16+
long: number;
17+
type: 0;
18+
},
19+
addr: string;
20+
zip: string;
21+
placeid: string;
22+
name: string;
23+
}

src/vehicles/european.vehicle.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { EuropeanController } from '../controllers/european.controller';
2323
import { celciusToTempCode, tempCodeToCelsius } from '../util';
2424
import { manageBluelinkyError, ManagedBluelinkyError } from '../tools/common.tools';
2525
import { addMinutes, parse as parseDate } from 'date-fns';
26+
import { EUPOIInformation } from '../interfaces/european.interfaces';
2627

2728
type ChargeTarget = 50 | 60 | 70 | 80 | 90 | 100;
2829
const POSSIBLE_CHARGE_LIMIT_VALUES = [50, 60, 70, 80, 90, 100];
@@ -637,6 +638,35 @@ export default class EuropeanVehicle extends Vehicle {
637638
throw manageBluelinkyError(err, 'EuropeVehicle.setChargeTargets');
638639
}
639640
}
641+
642+
/**
643+
* Define a navigation route
644+
* @param poiInformations The list of POIs and waypoint to go through
645+
*/
646+
public async setNavigation(poiInformations: EUPOIInformation[]): Promise<void> {
647+
await this.checkControlToken();
648+
try {
649+
await got(
650+
`${this.controller.environment.baseUrl}/api/v2/spa/vehicles/${this.vehicleConfig.id}/location/routes`,
651+
{
652+
method: 'POST',
653+
headers: {
654+
'Authorization': this.controller.session.controlToken,
655+
'ccsp-device-id': this.controller.session.deviceId,
656+
'Content-Type': 'application/json',
657+
'Stamp': this.controller.environment.stamp(),
658+
},
659+
body: {
660+
deviceID: this.controller.session.deviceId,
661+
poiInfoList: poiInformations,
662+
},
663+
json: true,
664+
}
665+
);
666+
} catch (err) {
667+
throw manageBluelinkyError(err, 'EuropeVehicle.setNavigation');
668+
}
669+
}
640670
}
641671

642672
function toMonthDate(month: { year: number; month: number; }) {

0 commit comments

Comments
 (0)