From 822a358dd10097bdc8b5346663f64ad66e2b1f79 Mon Sep 17 00:00:00 2001 From: Daniel Rheinbay Date: Thu, 24 Dec 2020 00:04:11 +0100 Subject: [PATCH] Add PayAsYouDrive API Add support for PayAsYouDrive API to get odometer readings. --- const.py | 2 +- custom_components/mercedesmeapi/const.py | 2 +- mercedes_me_api.sh | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/const.py b/const.py index 5c9902b..e03ee93 100644 --- a/const.py +++ b/const.py @@ -16,7 +16,7 @@ CREDENTIALS_FILE = ".mercedesme_credentials" RESOURCES_FILE = ".mercedesme_resources" # Mercedes me Application Parameters REDIRECT_URL = "https://localhost" -SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20offline_access" +SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20mb:vehicle:mbdata:payasyoudrive%20offline_access" URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2" # File Parameters diff --git a/custom_components/mercedesmeapi/const.py b/custom_components/mercedesmeapi/const.py index ddfb2cf..c937c2d 100644 --- a/custom_components/mercedesmeapi/const.py +++ b/custom_components/mercedesmeapi/const.py @@ -16,7 +16,7 @@ CREDENTIALS_FILE = ".mercedesme_credentials" RESOURCES_FILE = ".mercedesme_resources" # Mercedes me Application Parameters REDIRECT_URL = "https://localhost" -SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20offline_access" +SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20mb:vehicle:mbdata:payasyoudrive%20offline_access" URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2" #UPDATE_SIGNAL = "mercedesmeapi_update" diff --git a/mercedes_me_api.sh b/mercedes_me_api.sh index cfa7dfe..e9e0d9b 100755 --- a/mercedes_me_api.sh +++ b/mercedes_me_api.sh @@ -10,6 +10,7 @@ # 03/12/2020 - 0.3 - Fix in resources list # 18/12/2020 - 0.4 - Added macOS support (robert@klep.name) # 19/12/2020 - 0.5 - Added Electric Vehicle Status support +# 23/12/2020 - 0.6 - Added PayAsYouDrive support (danielrheinbay@gmail.com) # Script Name & Version NAME="mercedes_me_api.sh" @@ -20,7 +21,7 @@ TOKEN_FILE=".mercedesme_token" CREDENTIALS_FILE=".mercedesme_credentials" # Mercedes me Application Parameters REDIRECT_URL="https://localhost" -SCOPE="mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20offline_access" +SCOPE="mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20mb:vehicle:mbdata:payasyoudrive%20offline_access" URL_RES_PREFIX="https://api.mercedes-benz.com/vehicledata/v2" # Resources RES_FUEL=(rangeliquid tanklevelpercent) @@ -31,6 +32,7 @@ RES_STAT=(decklidstatus doorstatusfrontleft doorstatusfrontright doorstatusrearl windowstatusfrontleft windowstatusfrontright windowstatusrearleft windowstatusrearright ) RES_ELECTRIC=(soc rangeelectric) +RES_ODO=(odo) # set "extended regular expression" argument for sed based on OS if [ "X$(uname -s)" = "XDarwin" ] @@ -53,7 +55,6 @@ if [ -z $CLIENT_ID ] | [ -z $CLIENT_ID ] | [ -z $CLIENT_ID ]; then exit fi -# Formatting RES_URL # Formatting RES_URL RES_URL="$URL_RES_PREFIX/vehicles/$VEHICLE_ID/resources" @@ -71,6 +72,7 @@ function usage () echo " -l, --lock Retrieve the Lock Status of your Vehicle" echo " -s, --status Retrieve the General Status of your Vehicle" echo " -e, --electric-status Retrieve the General Electric Status of your Vehicle" + echo " -o, --odometer Retrieve the Odometer reading of your Vehicle" echo " -R, --resources Retrieve the list of available resources of your Vehicle" exit } @@ -78,7 +80,7 @@ function usage () function parse_options () { # Check Options - OPT=$(getopt -o trflseR --long token,refresh,fuel,lock,status,electric-status,resources -n "$NAME parse-error" -- "$@") + OPT=$(getopt -o trflseoR --long token,refresh,fuel,lock,status,electric-status,odometer,resources -n "$NAME parse-error" -- "$@") if [ $? != 0 ] || [ $# -eq 0 ]; then usage fi @@ -112,6 +114,10 @@ function parse_options () printStatus "${RES_ELECTRIC[@]}" shift ;; + -o | --odometer ) + printStatus "${RES_ODO[@]}" + shift + ;; -R | --resources ) printResources shift -- 2.47.3