]> git.giorgioravera.it Git - mercedes_me_api.git/commitdiff
Added support to Electric Vehicle Status (to be tested) v0.8
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 19 Dec 2020 14:35:18 +0000 (15:35 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Sat, 19 Dec 2020 14:35:18 +0000 (15:35 +0100)
README.md
config.py
const.py
custom_components/mercedesmeapi/const.py
info.md
mercedes_me_api.sh

index bf648c72415083fbc3c125bfc0f9b4bb3fb05103..c8c62674a68f31519aa6a86f0f63072541922eb2 100644 (file)
--- 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).
index a728330323cc3218fa144fec0d067ccb70398d4d..75071dbd3873e3f2d26a0cb832c0ef902566c9b8 100644 (file)
--- 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 = ""
index 75e0fade065f44d99339e65c35f647415fb6a4d9..5c9902b45558958ac3b825ccbf6319f5152a7d1f 100644 (file)
--- 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
index a0c371a1197d84d2bb941debeaee741c5ddfdc8c..ddfb2cfe2c181af42c227e993a66cbb245b728f0 100644 (file)
@@ -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 66b84c2e2effad4a6bd7bf8b2b714c7a555d24a6..e6786cd9ec6df0f64172aad48e9547d01cfa1c39 100644 (file)
--- 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
index 31028982a0bad0ab1858b9a34015344e5d2911e6..cfa7dfeb5e0cc2630754c08eeceb6e3a0431a3eb 100755 (executable)
@@ -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