krauskopf / node-red-contrib-car-bmw

Node-RED nodes for BMW ConnectedDrive
Other
11 stars 8 forks source link

Use vehicles v4 endpoint #31

Closed jkellerer closed 1 year ago

jkellerer commented 1 year ago

Fix for #30: Returns vehicles data using the supported V4 endpoints.

The structure differs and as far as I could see it doesn't make much sense to map that internally. Most data is similar but not all is the same.

This PR is a breaking change, but the only option to get the car status again (as far as I'm aware).

Example of the structural changes:

New data path (V4) Old path (V1)
attributes.brand brand
attributes.model model
attributes.softwareVersionCurrent.iStep iStep
attributes.softwareVersionCurrent.puStep puStep
attributes.softwareVersionExFactory.iStep exFactoryILevel
attributes.softwareVersionExFactory.puStep exFactoryPUStep
attributes.year year
state.chargingProfile.chargingSettings.targetSoc status.chargingProfile.chargingSettings.targetSoc
state.currentMileage status.currentMileage.mileage
state.doorsState.combinedSecurityState (properties.areDoorsLocked ? "SECURED" : "OPEN")
state.doorsState.hood properties.doorsAndWindows.trunk
state.doorsState.leftFront properties.doorsAndWindows.doors.driverFront
state.doorsState.leftRear properties.doorsAndWindows.doors.driverRear
state.doorsState.rightFront properties.doorsAndWindows.doors.passengerFront
state.doorsState.rightRear properties.doorsAndWindows.doors.passengerRear
state.doorsState.trunk properties.doorsAndWindows.doors.hood
state.electricChargingState.chargingLevelPercent properties.chargingState.chargePercentage
state.electricChargingState.chargingStatus properties.chargingState.state
state.electricChargingState.chargingTarget status.chargingProfile.chargingSettings.targetSoc
state.electricChargingState.isChargerConnected properties.chargingState.isChargerConnected
state.electricChargingState.range properties.electricRange.distance.value
state.isLeftSteering ?
state.lastUpdatedAt status.lastUpdatedAt
state.location.address.formatted properties.vehicleLocation.address.formatted
state.location.coordinates.latitude properties.vehicleLocation.coordinates.latitude
state.location.coordinates.longitude properties.vehicleLocation.coordinates.longitude
state.location.heading properties.vehicleLocation.heading
state.roofState.roofState properties.doorsAndWindows.moonroof
state.windowsState.leftFront properties.doorsAndWindows.windows.driverFront
state.windowsState.leftRear properties.doorsAndWindows.windows.driverRear
state.windowsState.rightFront properties.doorsAndWindows.windows.passengerFront
state.windowsState.rightRear properties.doorsAndWindows.windows.passengerRear
vin vin
jkellerer commented 1 year ago

@krauskopf: You had been faster as I thought :). Please check my update.

The /vehicles/state endpoint doesn't return valid JSON and needs an extra step in parsing.

Splitting vehicles and state into 2 calls may make sense though.

krauskopf commented 1 year ago

Thanks again @jkellerer for the contribution. I finally took some time to look a little bit deeper into the v4 endpoint but could not find the invalid json, that you mentioned. Tried it with both of my cars (330e, M2) but did not get any invalid or tagged json string. Can you please elaborate a little bit about what you are getting? Thanks!

jkellerer commented 1 year ago

Maybe it isn't needed, anymore. I got a response that looked like the following, initially when changing the code that causes JSON parse errors:

state={...JSON...} capabilities={...JSON...}

Not sure where it came from and whether it is still needed. Have not yet updated to the latest release since I'm running my patched version.

Will close the PR for now, as it seems this isn't an issue. I can open a separate PR if needed later.