Skip to content

Commit

Permalink
feat(vehicle): range, plug types and charge duration
Browse files Browse the repository at this point in the history
  • Loading branch information
neoPix committed Feb 22, 2021
1 parent 4ac0606 commit c326c3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/interfaces/common.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export interface Session {
controlTokenExpiresAt?: number;
}

export enum EVPlugTypes {
UNPLUGED = 0,
FAST = 1,
PORTABLE = 2,
STATION = 3
}

// Status remapped
export interface VehicleStatus {
engine: {
Expand All @@ -32,6 +39,15 @@ export interface VehicleStatus {
charging?: boolean;
timeToFullCharge?: unknown;
range: number;
rangeGas?: number;
rangeEV?: number;
plugedTo? : EVPlugTypes;
estimatedCurrentChargeDuration?: number;
estimatedFastChargeDuration?: number;
estimatedPortableChargeDuration?: number;
estimatedStationChargeDuration?: number;
batteryCharge12v?: number;
batteryChargeHV?: number;
adaptiveCruiseControl: boolean;
};
climate: {
Expand Down
35 changes: 25 additions & 10 deletions src/vehicles/european.vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
VehicleRegisterOptions,
VehicleStatusOptions,
RawVehicleStatus,
EVPlugTypes,
} from '../interfaces/common.interfaces';
import got from 'got';

Expand Down Expand Up @@ -240,7 +241,7 @@ export default class EuropeanVehicle extends Vehicle {
? response.body.resMsg
: response.body.resMsg.vehicleStatusInfo.vehicleStatus;

const parsedStatus = {
const parsedStatus: VehicleStatus = {
chassis: {
hoodOpen: vehicleStatus?.hoodOpen,
trunkOpen: vehicleStatus?.trunkOpen,
Expand Down Expand Up @@ -271,12 +272,26 @@ export default class EuropeanVehicle extends Vehicle {
engine: {
ignition: vehicleStatus.engine,
adaptiveCruiseControl: vehicleStatus?.acc,
range: vehicleStatus?.evStatus?.drvDistance[0].rangeByFuel?.totalAvailableRange?.value,
rangeGas: vehicleStatus?.evStatus?.drvDistance[0]?.rangeByFuel?.gasModeRange?.value ?? vehicleStatus?.dte?.value,
// EV
range: vehicleStatus?.evStatus?.drvDistance[0]?.rangeByFuel?.totalAvailableRange?.value,
rangeEV: vehicleStatus?.evStatus?.drvDistance[0]?.rangeByFuel?.evModeRange?.value,
plugedTo: vehicleStatus?.evStatus?.batteryPlugin ?? EVPlugTypes.UNPLUGED,
charging: vehicleStatus?.evStatus?.batteryCharge,
estimatedCurrentChargeDuration: vehicleStatus?.evStatus?.remainTime2?.atc?.value,
estimatedFastChargeDuration: vehicleStatus?.evStatus?.remainTime2?.etc1?.value,
estimatedPortableChargeDuration: vehicleStatus?.evStatus?.remainTime2?.etc2?.value,
estimatedStationChargeDuration: vehicleStatus?.evStatus?.remainTime2?.etc3?.value,
batteryCharge12v: vehicleStatus?.battery?.batSoc,
batteryChargeHV: vehicleStatus?.evStatus?.batteryStatus,
},
} as VehicleStatus;
};

if(!parsedStatus.engine.range) {
if (parsedStatus.engine.rangeEV || parsedStatus.engine.rangeGas) {
parsedStatus.engine.range = (parsedStatus.engine.rangeEV ?? 0) + (parsedStatus.engine.rangeGas ?? 0);
}
}

this._status = statusConfig.parsed ? parsedStatus : vehicleStatus;

Expand Down Expand Up @@ -317,16 +332,16 @@ export default class EuropeanVehicle extends Vehicle {
}
);

const data = response.body.resMsg.gpsDetail ?? response.body.resMsg;
const data = response.body.resMsg.gpsDetail;
this._location = {
latitude: data?.coord?.lat,
longitude: data?.coord?.lon,
altitude: data?.coord?.alt,
latitude: data.coord.lat,
longitude: data.coord.lon,
altitude: data.coord.alt,
speed: {
unit: data?.speed?.unit,
value: data?.speed?.value,
unit: data.speed.unit,
value: data.speed.value,
},
heading: data?.head,
heading: data.head,
};

return this._location;
Expand Down

2 comments on commit c326c3f

@PierreLevres
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you undo your changes from line 320 onward from your previous commit? const data = response.body.resMsg.gpsDetail ?? response.body.resMsg; etc

@neoPix
Copy link
Contributor Author

@neoPix neoPix commented on c326c3f Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like git fail somewhere 😨. I'll Will need to PR this again 😞.

Please sign in to comment.