Skip to content

Add Renault odometer - #3254

Merged
LKuemmel merged 4 commits into
openWB:masterfrom
seaspotter:renault_odometer
Mar 31, 2026
Merged

LKuemmel merged 4 commits into
openWB:masterfrom
seaspotter:renault_odometer

Conversation

@seaspotter

Copy link
Copy Markdown
Collaborator

Getestet mit Renault Megane E-Tech

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds odometer support to the Renault vehicle integration by retrieving cockpit data from the Kamereon API and returning it via CarState.

Changes:

  • Fetch Renault “cockpit” endpoint data in addition to battery status.
  • Map cockpit.data.attributes.totalMileage into CarState.odometer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +84 to +98
# Step 9 - cockpit data for odometer/totalMileage
data = urllib.parse.urlencode(country_data)
data = data.encode('Big5')
reg = urllib.request.Request(KAMEREON_ROOTURL + '/commerce/v1/accounts/' +
kamereonaccountid + '/kamereon/kca/car-adapter/v1/cars/'
+ vin + '/cockpit?' + data.decode("utf-8"))
reg.add_header('x-gigya-id_token', gigya_jwttoken)
reg.add_header('apikey', KAMEREON_API_KEY)
response = urllib.request.urlopen(reg)
responsetext = response.read()
cockpit = json.loads(responsetext)

return CarState(soc=float(batt['data']['attributes']['batteryLevel']),
range=float(batt['data']['attributes']['batteryAutonomy']))
range=float(batt['data']['attributes']['batteryAutonomy']),
odometer=float(cockpit['data']['attributes']['totalMileage']))

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

The new cockpit request makes fetch_soc fail entirely if the cockpit endpoint is unavailable or returns an unexpected payload (e.g., missing data.attributes.totalMileage). Consider handling errors for this optional field (e.g., catch network/JSON/key errors and set odometer=None) so SOC/range can still be returned.

Copilot uses AI. Check for mistakes.
@LKuemmel
LKuemmel merged commit 948ba69 into openWB:master Mar 31, 2026
5 checks passed
@seaspotter
seaspotter deleted the renault_odometer branch April 1, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants