Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/controllers/european.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface EuropeanVehicleDescription {
vehicleName: string;
regDate: string;
vehicleId: string;
ccuCCS2ProtocolSupport: number
}

export class EuropeanController extends SessionController<EuropeBlueLinkyConfig> {
Expand Down Expand Up @@ -297,6 +298,7 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
id: v.vehicleId,
vin: vehicleProfile.vinInfo[0].basic.vin,
generation: vehicleProfile.vinInfo[0].basic.modelYear,
ccuCCS2ProtocolSupport: !!v.ccuCCS2ProtocolSupport
} as VehicleRegisterOptions;

logger.debug(`@EuropeController.getVehicles: Added vehicle ${vehicleConfig.id}`);
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/common.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export interface VehicleRegisterOptions {
regId: string;
id: string;
generation: string;
ccuCCS2ProtocolSupport?: boolean;
}

export type DeepPartial<T> = {
Expand Down
227 changes: 157 additions & 70 deletions src/vehicles/european.vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,36 @@ export default class EuropeanVehicle extends Vehicle {
const http = await this.controller.getVehicleHttpService();

try {
const cachedResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status/latest`)
);
let fullStatus;

const fullStatus = cachedResponse.body.resMsg.vehicleStatusInfo;
if (this.vehicleConfig.ccuCCS2ProtocolSupport) {

if (statusConfig.refresh) {
const statusResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status`)
const cachedResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/ccs2/carstatus/latest`)
);
fullStatus.vehicleStatus = statusResponse.body.resMsg;

const locationResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/location`)
fullStatus = cachedResponse.body.resMsg.state.Vehicle;

} else {

const cachedResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status/latest`)
);
fullStatus.vehicleLocation = locationResponse.body.resMsg.gpsDetail;

fullStatus = cachedResponse.body.resMsg.vehicleStatusInfo;

if (statusConfig.refresh) {
const statusResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status`)
);
fullStatus.vehicleStatus = statusResponse.body.resMsg;

const locationResponse = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/location`)
);
fullStatus.vehicleLocation = locationResponse.body.resMsg.gpsDetail;
}

}

this._fullStatus = fullStatus;
Expand All @@ -195,70 +209,143 @@ export default class EuropeanVehicle extends Vehicle {
const http = await this.controller.getVehicleHttpService();

try {
const cacheString = statusConfig.refresh ? '' : '/latest';

const response = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status${cacheString}`)
);
let vehicleStatus, parsedStatus: VehicleStatus;

if (this.vehicleConfig.ccuCCS2ProtocolSupport) {

vehicleStatus = await this.fullStatus(input);

const locks = [
!!vehicleStatus?.Cabin?.Door?.Row1?.Passenger?.Lock,
!!vehicleStatus?.Cabin?.Door?.Row1?.Driver?.Lock,
!!vehicleStatus?.Cabin?.Door?.Row2?.Left?.Lock,
!!vehicleStatus?.Cabin?.Door?.Row2?.Right?.Lock
];

// handles refreshing data
const vehicleStatus = statusConfig.refresh
? response.body.resMsg
: response.body.resMsg.vehicleStatusInfo.vehicleStatus;

const parsedStatus: VehicleStatus = {
chassis: {
hoodOpen: vehicleStatus?.hoodOpen,
trunkOpen: vehicleStatus?.trunkOpen,
locked: vehicleStatus.doorLock,
openDoors: {
frontRight: !!vehicleStatus?.doorOpen?.frontRight,
frontLeft: !!vehicleStatus?.doorOpen?.frontLeft,
backLeft: !!vehicleStatus?.doorOpen?.backLeft,
backRight: !!vehicleStatus?.doorOpen?.backRight,
let plugedTo: EVPlugTypes;
if (vehicleStatus?.Green?.ChargingInformation?.ConnectorFastening?.State) {
// TODO: Interpret vehicleStatus.Green.ChargingInformation.SequenceDetails
// and vehicleStatus.Green.ChargingInformation.SequenceSubcode
plugedTo = EVPlugTypes.STATION;
} else {
plugedTo = EVPlugTypes.UNPLUGED;
}

parsedStatus = {
chassis: {
hoodOpen: !!vehicleStatus?.Body?.Hood?.Open,
trunkOpen: !!vehicleStatus?.Body?.Trunk?.Open,
locked: locks.every(v => v === false),
openDoors: {
frontRight: !!vehicleStatus?.Cabin?.Door?.Row1?.Passenger?.Open,
frontLeft: !!vehicleStatus?.Cabin?.Door?.Row1?.Driver?.Open,
backLeft: !!vehicleStatus?.Cabin?.Door?.Row2?.Left?.Open,
backRight: !!vehicleStatus?.Cabin?.Door?.Row2?.Right?.Open,
},
tirePressureWarningLamp: {
rearLeft: !!vehicleStatus?.Chassis?.Axle?.Row2?.Left?.Tire?.PressureLow,
frontLeft: !!vehicleStatus?.Chassis?.Axle?.Row1?.Left?.Tire?.PressureLow,
frontRight: !!vehicleStatus?.Chassis?.Axle?.Row1?.Right?.Tire?.PressureLow,
rearRight: !!vehicleStatus?.Chassis?.Axle?.Row2?.Right?.Tire?.PressureLow,
all: !!vehicleStatus?.Chassis?.Axle?.Tire?.PressureLow,
},
},
tirePressureWarningLamp: {
rearLeft: !!vehicleStatus?.tirePressureLamp?.tirePressureLampRL,
frontLeft: !!vehicleStatus?.tirePressureLamp?.tirePressureLampFL,
frontRight: !!vehicleStatus?.tirePressureLamp?.tirePressureLampFR,
rearRight: !!vehicleStatus?.tirePressureLamp?.tirePressureLampRR,
all: !!vehicleStatus?.tirePressureLamp?.tirePressureWarningLampAll,
climate: {
active: vehicleStatus?.Cabin?.HVAC?.Row1?.Driver?.Temperature?.Value === 'ON',
steeringwheelHeat: !!vehicleStatus?.Cabin?.SteeringWheel?.Heat?.State,
sideMirrorHeat: false,
rearWindowHeat: false,
defrost: false,
temperatureSetpoint: '',
temperatureUnit: 0,
},
},
climate: {
active: vehicleStatus?.airCtrlOn,
steeringwheelHeat: !!vehicleStatus?.steerWheelHeat,
sideMirrorHeat: false,
rearWindowHeat: !!vehicleStatus?.sideBackWindowHeat,
defrost: vehicleStatus?.defrost,
temperatureSetpoint: tempCodeToCelsius(REGIONS.EU, vehicleStatus?.airTemp?.value),
temperatureUnit: vehicleStatus?.airTemp?.unit,
},
engine: {
ignition: vehicleStatus.engine,
accessory: vehicleStatus?.acc,
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,
},
lastupdate: vehicleStatus?.time ? parseDate(vehicleStatus?.time) : null,
};
engine: {
ignition: !!vehicleStatus?.Electronics?.PowerSupply?.Ignition1 || !!vehicleStatus?.Electronics?.PowerSupply?.Ignition3,
accessory: !!vehicleStatus?.Electronics?.PowerSupply?.Accessory,
rangeGas: undefined,
// EV
range: vehicleStatus?.Drivetrain?.FuelSystem?.DTE?.Total,
rangeEV: undefined,
plugedTo: plugedTo,
charging: undefined,
estimatedCurrentChargeDuration: vehicleStatus?.Green?.ChargingInformation?.Charging?.RemainTime,
estimatedFastChargeDuration: vehicleStatus?.Green?.ChargingInformation?.EstimatedTime?.Quick,
estimatedPortableChargeDuration: vehicleStatus?.Green?.ChargingInformation?.EstimatedTime?.ICCB,
estimatedStationChargeDuration: vehicleStatus?.Green?.ChargingInformation?.EstimatedTime?.Standard,
batteryCharge12v: vehicleStatus?.Electronics?.Battery?.Level,
batteryChargeHV: vehicleStatus?.Green?.BatteryManagement?.BatteryRemain?.Ratio,
},
lastupdate: vehicleStatus?.Date ? parseDate(vehicleStatus?.Date) : null,
};

} else {

const cacheString = statusConfig.refresh ? '' : '/latest';

const response = this.updateRates(
await http.get(`/api/v2/spa/vehicles/${this.vehicleConfig.id}/status${cacheString}`)
);

// handles refreshing data
vehicleStatus = statusConfig.refresh
? response.body.resMsg
: response.body.resMsg.vehicleStatusInfo.vehicleStatus;

parsedStatus = {
chassis: {
hoodOpen: vehicleStatus?.hoodOpen,
trunkOpen: vehicleStatus?.trunkOpen,
locked: vehicleStatus.doorLock,
openDoors: {
frontRight: !!vehicleStatus?.doorOpen?.frontRight,
frontLeft: !!vehicleStatus?.doorOpen?.frontLeft,
backLeft: !!vehicleStatus?.doorOpen?.backLeft,
backRight: !!vehicleStatus?.doorOpen?.backRight,
},
tirePressureWarningLamp: {
rearLeft: !!vehicleStatus?.tirePressureLamp?.tirePressureLampRL,
frontLeft: !!vehicleStatus?.tirePressureLamp?.tirePressureLampFL,
frontRight: !!vehicleStatus?.tirePressureLamp?.tirePressureLampFR,
rearRight: !!vehicleStatus?.tirePressureLamp?.tirePressureLampRR,
all: !!vehicleStatus?.tirePressureLamp?.tirePressureWarningLampAll,
},
},
climate: {
active: vehicleStatus?.airCtrlOn,
steeringwheelHeat: !!vehicleStatus?.steerWheelHeat,
sideMirrorHeat: false,
rearWindowHeat: !!vehicleStatus?.sideBackWindowHeat,
defrost: vehicleStatus?.defrost,
temperatureSetpoint: tempCodeToCelsius(REGIONS.EU, vehicleStatus?.airTemp?.value),
temperatureUnit: vehicleStatus?.airTemp?.unit,
},
engine: {
ignition: vehicleStatus.engine,
accessory: vehicleStatus?.acc,
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,
},
lastupdate: vehicleStatus?.time ? parseDate(vehicleStatus?.time) : null,
};

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

Expand Down