]> git.giorgioravera.it Git - mercedes_me_api.git/commitdiff
Minor changes and increased version number to 0.9
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Thu, 24 Dec 2020 10:00:03 +0000 (11:00 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Thu, 24 Dec 2020 10:00:03 +0000 (11:00 +0100)
README.md
config.py
const.py
custom_components/mercedesmeapi/const.py
custom_components/mercedesmeapi/oauth.py
custom_components/mercedesmeapi/query.py
info.md
query.py

index c8c62674a68f31519aa6a86f0f63072541922eb2..5fbc8386860eea3e2a68aa3dff6b741f59d6dceb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,13 +11,14 @@ This repository contains a collection of scripts (including the Home Assistant C
 1) Own a Mercedes Benz Car with Mercedes me installed and working.
 2) Create an application in https://developer.mercedes-benz.com/
 3) Register to the following APIs:
+   - [Electric Vehicle Status](https://developer.mercedes-benz.com/products/electric_vehicle_status)
    - [Fuel Status](https://developer.mercedes-benz.com/products/fuel_status)
+   - [Pay As You Drive Insurance](https://developer.mercedes-benz.com/products/pay_as_you_drive_insurance) 
    - [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: not all sensors may be available in your own car.
+Note2: not all sensors may be available in your own car; if a sensor is not available the data request returns no data.
 Note3: only one car is supported for the moment.
 
 ## Home Assistant Custom Component
index a826d36f667498bb6c21eb943973882b56352098..87e161d9beed40ce25f53a310b10ea3682d962bb 100644 (file)
--- a/config.py
+++ b/config.py
@@ -48,17 +48,17 @@ class MercedesMeConfig:
         # Client ID
         self.client_id = f.get(CONF_CLIENT_ID)
         if not self.client_id:
-            _LOGGER.error("No {CONF_CLIENT_ID} found in the configuration")
+            _LOGGER.error(f"No {CONF_CLIENT_ID} found in the configuration")
             return False
         # Client Secret
         self.client_secret = f.get(CONF_CLIENT_SECRET)
         if not self.client_secret:
-            _LOGGER.error("No {CONF_CLIENT_SECRET} found in the configuration")
+            _LOGGER.error(f"No {CONF_CLIENT_SECRET} found in the configuration")
             return False
         # Vehicle ID
         self.vin = f.get(CONF_VEHICLE_ID)
         if not self.vin:
-            _LOGGER.error("No {CONF_VEHICLE_ID} found in the configuration")
+            _LOGGER.error(f"No {CONF_VEHICLE_ID} found in the configuration")
             return False
         # Read Token
         self.token = MercedesMeOauth(self.client_id, self.client_secret)
index e03ee930b926e73909ce40f4a5e6bb59ea8944d9..da2a1f1daf4f000b4da3b2a4504578c278b4524e 100644 (file)
--- a/const.py
+++ b/const.py
@@ -9,7 +9,7 @@ https://github.com/xraver/mercedes_me_api/
 # Software Name & Version
 NAME = "Mercedes Me API"
 DOMAIN = "mercedesmeapi"
-VERSION = "0.8"
+VERSION = "0.9"
 # Software Parameters
 TOKEN_FILE = ".mercedesme_token"
 CREDENTIALS_FILE = ".mercedesme_credentials"
@@ -19,7 +19,7 @@ REDIRECT_URL = "https://localhost"
 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
+# Configuration File Parameters
 CONF_CLIENT_ID = "CLIENT_ID"
 CONF_CLIENT_SECRET = "CLIENT_SECRET"
 CONF_VEHICLE_ID = "VEHICLE_ID"
index c937c2d7346b63d9c4b9352d4432bde24a718d2f..0f028f319e0b91a290c4c55d3d40dad3526947bf 100644 (file)
@@ -9,7 +9,7 @@ https://github.com/xraver/mercedes_me_api/
 # Software Name & Version
 NAME = "Mercedes Me API"
 DOMAIN = "mercedesmeapi"
-VERSION = "0.8"
+VERSION = "0.9"
 # Software Parameters
 TOKEN_FILE = ".mercedesme_token"
 CREDENTIALS_FILE = ".mercedesme_credentials"
@@ -20,7 +20,7 @@ SCOPE = "mb:vehicle:mbdata:fuelstatus%20mb:vehicle:mbdata:vehiclestatus%20mb:veh
 URL_RES_PREFIX = "https://api.mercedes-benz.com/vehicledata/v2"
 #UPDATE_SIGNAL = "mercedesmeapi_update"
 
-# File Parameters
+# Configuration File Parameters
 CONF_CLIENT_ID = "client_id"
 CONF_CLIENT_SECRET = "client_secret"
 CONF_VEHICLE_ID = "vehicle_id"
index eafee6de4a6fb4cab0e533100806328655f9dc94..94c210bc2e3fafc996c6f368a04268c8ede43ea0 100644 (file)
@@ -42,12 +42,12 @@ class MercedesMeOauth:
         self.token_file = hass.config.path(TOKEN_FILE)\r
         # Base64\r
         b64_str = f"{client_id}:{client_secret}"\r
-        b64_bytes = base64.b64encode( b64_str.encode('ascii') )\r
-        self.base64 = b64_bytes.decode('ascii')\r
+        b64_bytes = base64.b64encode(b64_str.encode("ascii"))\r
+        self.base64 = b64_bytes.decode("ascii")\r
         # Headers\r
         self.headers = {\r
             "Authorization": f"Basic {self.base64}",\r
-            "content-type": "application/x-www-form-urlencoded"\r
+            "content-type": "application/x-www-form-urlencoded",\r
         }\r
 \r
     ########################\r
index 37e886cead622578b7076f9d00b4ac7d482c3d3a..a4be239964a4cc282dbb52091fc169e77c0fdaa0 100644 (file)
@@ -21,8 +21,8 @@ def GetResource(resourceURL, config):
 
     # Set Header
     headers = {
-        "accept": "application/json;charset=utf-8", 
-        "authorization": f"Bearer {config.token.access_token}"
+        "accept": "application/json;charset=utf-8",
+        "authorization": f"Bearer {config.token.access_token}",
     }
 
     # Send Request
@@ -30,13 +30,11 @@ def GetResource(resourceURL, config):
     try:
         data = res.json()
     except ValueError:
-        data = { "reason": "No Data",
-                 "code" : res.status_code 
-        }
+        data = {"reason": "No Data", "code": res.status_code}
 
     # Check Error
     if not res.ok:
-        if ("reason" in data):
+        if "reason" in data:
             reason = data["reason"]
         else:
             if res.status_code == 400:
@@ -50,7 +48,9 @@ def GetResource(resourceURL, config):
             elif res.status_code == 404:
                 reason = "Page not found"
             elif res.status_code == 429:
-                reason = "The service received too many requests in a given amount of time"
+                reason = (
+                    "The service received too many requests in a given amount of time"
+                )
             elif res.status_code == 500:
                 reason = "An error occurred on the server side"
             elif res.status_code == 503:
@@ -61,25 +61,24 @@ def GetResource(resourceURL, config):
         data["code"] = res.status_code
     return data
 
+
 ########################
 # GetToken
 ########################
 def GetToken(tokenURL, headers, data, refresh=True):
-    res = requests.post(tokenURL, data = data, headers = headers)
+    res = requests.post(tokenURL, data=data, headers=headers)
     try:
         data = res.json()
     except ValueError:
-        _LOGGER.error (f"Error retrieving token {res.status_code}")
-        data = { "reason": "No Data",
-                 "code" : res.status_code 
-        }
+        _LOGGER.error(f"Error retrieving token {res.status_code}")
+        data = {"reason": "No Data", "code": res.status_code}
 
     # Check Error
     if not res.ok:
-        if ("reason" in data):
+        if "reason" in data:
             reason = data["reason"]
         else:
-            if (refresh == False):
+            if refresh == False:
                 # New Token Errors
                 if res.status_code == 302:
                     reason = "The request scope is invalid"
diff --git a/info.md b/info.md
index e6786cd9ec6df0f64172aad48e9547d01cfa1c39..2080f8e988b3d6966c003b0cf35d557f3cb602a0 100644 (file)
--- a/info.md
+++ b/info.md
@@ -12,12 +12,14 @@ This component is still in development.
 1) Own a Mercedes Benz Car with Mercedes me installed and working.
 2) Create an application in https://developer.mercedes-benz.com/
 3) Register to the following APIs:
+   - [Electric Vehicle Status](https://developer.mercedes-benz.com/products/electric_vehicle_status)
    - [Fuel Status](https://developer.mercedes-benz.com/products/fuel_status)
+   - [Pay As You Drive Insurance](https://developer.mercedes-benz.com/products/pay_as_you_drive_insurance) 
    - [Vehicle Lock Status](https://developer.mercedes-benz.com/products/vehicle_lock_status)
    - [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: not all sensors may be available in your own car.
+Note2: not all sensors may be available in your own car; if a sensor is not available the data request returns no data.
 Note3: only one car is supported for the moment.
 
 ## Open Points
index 0c9569adcad3c3d48f6e4f61115d226d75a18926..1a5190cdd3ea00db7bdc0a3e14c86115a547d80b 100644 (file)
--- a/query.py
+++ b/query.py
@@ -7,7 +7,6 @@ For more details about this component, please refer to the documentation at
 https://github.com/xraver/mercedes_me_api/
 """
 import logging
-
 import requests
 
 from const import *