From: Giorgio Ravera Date: Sat, 19 Dec 2020 14:35:18 +0000 (+0100) Subject: Added support to Electric Vehicle Status (to be tested) X-Git-Tag: v0.8^0 X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;h=9f5e0f2bc705dbfde20fd5fd2b1801d17be922f5;p=mercedes_me_api.git Added support to Electric Vehicle Status (to be tested) --- diff --git a/README.md b/README.md index bf648c7..c8c6267 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,11 @@ This repository contains a collection of scripts (including the Home Assistant C - [Fuel Status](https://developer.mercedes-benz.com/products/fuel_status) - [Vehicle Lock Status](https://developer.mercedes-benz.com/products/vehicle_lock_status) - [Vehicle Status](https://developer.mercedes-benz.com/products/vehicle_status) + - [Electric Vehicle Status](https://developer.mercedes-benz.com/products/electric_vehicle_status) Note: the APIs described above do not require any subscription in case you use them with your own car associated with the Mercedes me Account. -Note2: only one car is supported for the moment. +Note2: not all sensors may be available in your own car. +Note3: only one car is supported for the moment. ## Home Assistant Custom Component The Home Assistant Custom Component is a component to be added in Home Assistant in order to integrate the sensors of a Mercedes-Benz car using [Mercedes me API](https://developer.mercedes-benz.com/products). diff --git a/config.py b/config.py index a728330..75071db 100644 --- a/config.py +++ b/config.py @@ -22,7 +22,7 @@ class MercedesMeConfig: # Init ######################## def __init__(self): - self.credentials_file = CREDENTIAL_FILE + self.credentials_file = CREDENTIALS_FILE self.client_id = "" self.client_secret = "" self.vin = "" diff --git a/const.py b/const.py index 75e0fad..5c9902b 100644 --- a/const.py +++ b/const.py @@ -6,15 +6,17 @@ Author: G. Ravera For more details about this component, please refer to the documentation at https://github.com/xraver/mercedes_me_api/ """ -# Software Parameters +# Software Name & Version NAME = "Mercedes Me API" DOMAIN = "mercedesmeapi" -VERSION = "0.7" +VERSION = "0.8" +# Software Parameters TOKEN_FILE = ".mercedesme_token" -CREDENTIAL_FILE = ".mercedesme_credentials" +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%20offline_access" +SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%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 a0c371a..ddfb2cf 100644 --- a/custom_components/mercedesmeapi/const.py +++ b/custom_components/mercedesmeapi/const.py @@ -6,15 +6,17 @@ Author: G. Ravera For more details about this component, please refer to the documentation at https://github.com/xraver/mercedes_me_api/ """ -# Software Parameters +# Software Name & Version NAME = "Mercedes Me API" DOMAIN = "mercedesmeapi" -VERSION = "0.7" +VERSION = "0.8" +# Software Parameters TOKEN_FILE = ".mercedesme_token" -CREDENTIAL_FILE = ".mercedesme_credentials" +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%20offline_access" +SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20mb:vehicle:mbdata:evstatus%20offline_access" URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2" #UPDATE_SIGNAL = "mercedesmeapi_update" diff --git a/info.md b/info.md index 66b84c2..e6786cd 100644 --- a/info.md +++ b/info.md @@ -17,7 +17,8 @@ This component is still in development. - [Vehicle Status](https://developer.mercedes-benz.com/products/vehicle_status) Note: the APIs described above do not require any subscription in case you use them with your own car associated with the Mercedes me Account. -Note2: only one car is supported for the moment. +Note2: not all sensors may be available in your own car. +Note3: only one car is supported for the moment. ## Open Points - Complete OAUTH2 Authentication & Get the First Token diff --git a/mercedes_me_api.sh b/mercedes_me_api.sh index 3102898..cfa7dfe 100755 --- a/mercedes_me_api.sh +++ b/mercedes_me_api.sh @@ -1,7 +1,7 @@ #!/bin/bash # Author: G. Ravera -# Version 0.4 +# Version 0.5 # Creation Date: 28/09/2020 # # Change log: @@ -9,10 +9,28 @@ # 18/10/2020 - 0.2 - Added the possibility to retrieve the list of resources available # 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 # Script Name & Version NAME="mercedes_me_api.sh" -VERSION="0.4" +VERSION="0.5" + +# Script Parameters +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" +URL_RES_PREFIX="https://api.mercedes-benz.com/vehicledata/v2" +# Resources +RES_FUEL=(rangeliquid tanklevelpercent) +RES_LOCK=(doorlockstatusvehicle doorlockstatusdecklid doorlockstatusgas positionHeading) +RES_STAT=(decklidstatus doorstatusfrontleft doorstatusfrontright doorstatusrearleft doorstatusrearright \ + interiorLightsFront interiorLightsRear lightswitchposition readingLampFrontLeft readingLampFrontRight \ + rooftopstatus sunroofstatus \ + windowstatusfrontleft windowstatusfrontright windowstatusrearleft windowstatusrearright +) +RES_ELECTRIC=(soc rangeelectric) # set "extended regular expression" argument for sed based on OS if [ "X$(uname -s)" = "XDarwin" ] @@ -22,13 +40,6 @@ else SED_FLAG="-r" fi -# Static Parameters -REDIRECT_URL="https://localhost" -SCOPE="mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:vehicle:mbdata:vehiclelock%20offline_access" -STATE="12345678" -TOKEN_FILE=".mercedesme_token" -CREDENTIALS_FILE=".mercedesme_credentials" - # Credentials CLIENT_ID="" CLIENT_SECRET="" @@ -42,17 +53,9 @@ if [ -z $CLIENT_ID ] | [ -z $CLIENT_ID ] | [ -z $CLIENT_ID ]; then exit fi -# URL -RES_URL="https://api.mercedes-benz.com/vehicledata/v2/vehicles/$VEHICLE_ID/resources" - -# Resources -RES_FUEL=(rangeliquid tanklevelpercent) -RES_LOCK=(doorlockstatusvehicle doorlockstatusdecklid doorlockstatusgas positionHeading) -RES_STAT=(decklidstatus doorstatusfrontleft doorstatusfrontright doorstatusrearleft doorstatusrearright \ - interiorLightsFront interiorLightsRear lightswitchposition readingLampFrontLeft readingLampFrontRight \ - rooftopstatus sunroofstatus \ - windowstatusfrontleft windowstatusfrontright windowstatusrearleft windowstatusrearright -) +# Formatting RES_URL +# Formatting RES_URL +RES_URL="$URL_RES_PREFIX/vehicles/$VEHICLE_ID/resources" function usage () { @@ -62,19 +65,20 @@ function usage () echo " or: $NAME -l" echo echo "Arguments:" - echo " -t, --token Procedure to obtatin the Access Token (stored into $TOKEN_FILE)" - echo " -r, --refresh Procedure to refresh the Access Token (stored into $TOKEN_FILE)" - echo " -f, --fuel Retrieve the Fuel Status of your Vehicle" - echo " -l, --lock Retrieve the Lock Status of your Vehicle" - echo " -s, --status Retrieve the General Status of your Vehicle" - echo " -R, --resources Retrieve the list of available resources of your Vehicle" + echo " -t, --token Procedure to obtatin the Access Token (stored into $TOKEN_FILE)" + echo " -r, --refresh Procedure to refresh the Access Token (stored into $TOKEN_FILE)" + echo " -f, --fuel Retrieve the Fuel Status of your Vehicle" + 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 " -R, --resources Retrieve the list of available resources of your Vehicle" exit } function parse_options () { # Check Options - OPT=$(getopt -o trflsR --long token,refresh,fuel,lock,status,resources -n "$NAME parse-error" -- "$@") + OPT=$(getopt -o trflseR --long token,refresh,fuel,lock,status,electric-status,resources -n "$NAME parse-error" -- "$@") if [ $? != 0 ] || [ $# -eq 0 ]; then usage fi @@ -104,6 +108,10 @@ function parse_options () printStatus "${RES_STAT[@]}" shift ;; + -e | --electric-status ) + printStatus "${RES_ELECTRIC[@]}" + shift + ;; -R | --resources ) printResources shift