Compare commits

...
5 Commits
Author SHA1 Message Date
linus 4673f14a1c Add more logging for refresh process // renew refresh token if returned from api 2025-08-23 11:25:38 +02:00
linus 1a2f35f1b5 Add more logging for refresh process // renew refresh token if returned from api 2025-08-23 11:22:37 +02:00
Gert-Andry KäärameesandGitHub 33ee258f3f handle missing refresh_token key in token file (#306) 2025-07-28 07:39:44 +02:00
Russell StephensandGitHub 54db72df94 Update README.md (#304)
Improve readability and copy-paste functionality of docker command
2025-07-16 10:58:03 +02:00
linus 70b027fb70 Fix and unit for and 2025-07-13 20:03:27 +02:00
5 changed files with 47 additions and 13 deletions
+11 -1
View File
@@ -129,7 +129,17 @@ The following steps are required for authentication in exactly this order:
Just install this addon with the following command. Just install this addon with the following command.
Please note to fill in your settings inside the environment variables. Please note to fill in your settings inside the environment variables.
`docker run -d --pull=always -e CONF_updateInterval=300 -e CONF_babelLocale='de' -e CONF_mqtt='@json {"broker": "", "username": "", "password": "", "port": 1883}' -e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": ["key1", "key2"]}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest` <pre>
<code>docker run -d --pull=always \
-e CONF_updateInterval=300 \
-e CONF_babelLocale='de' \
-e CONF_mqtt='@json {"broker": "", "username": "", "password": "", "port": 1883}' \
-e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": ["key1", "key2"]}' \
-e TZ='Europe/Berlin' \
--name volvo2mqtt \
ghcr.io/dielee/volvo2mqtt:latest
</code>
</pre>
<b>HA Add-On:</b><br> <b>HA Add-On:</b><br>
+13
View File
@@ -1,3 +1,16 @@
## v1.12.2
### 🚀 Features:
- Add more logging for refresh process
- Update refresh token, if volvo API returns a new one
## v1.12.1
### 🐛 Bug Fixes:
- Fix `trip_speed` and `trip_distance` unit for `en_US` and `en_GB` #301
## v1.12.0 ## v1.12.0
### 🚀 Features: ### 🚀 Features:
+1 -1
View File
@@ -1,6 +1,6 @@
name: "Volvo2Mqtt" name: "Volvo2Mqtt"
description: "Volvo AAOS MQTT bridge" description: "Volvo AAOS MQTT bridge"
version: "1.12.0" version: "1.12.2"
slug: "volvo2mqtt" slug: "volvo2mqtt"
init: false init: false
url: "https://github.com/Dielee/volvo2mqtt" url: "https://github.com/Dielee/volvo2mqtt"
+7 -3
View File
@@ -1,6 +1,6 @@
from config import settings from config import settings
VERSION = "v1.12.0" VERSION = "v1.12.2"
OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2" OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2"
@@ -41,7 +41,9 @@ units = {
"odometer": {"unit": LENGTH_MILES}, "odometer": {"unit": LENGTH_MILES},
"average_speed": {"unit": SPEED_MILES_PER_HOUR}, "average_speed": {"unit": SPEED_MILES_PER_HOUR},
"distance_to_empty": {"unit": LENGTH_MILES}, "distance_to_empty": {"unit": LENGTH_MILES},
"distance_to_service": {"unit": LENGTH_MILES} "distance_to_service": {"unit": LENGTH_MILES},
"trip_distance": {"unit": LENGTH_MILES},
"trip_speed": {"unit": SPEED_MILES_PER_HOUR}
}, },
"en_US": { "en_US": {
"divider": 1.60934, "divider": 1.60934,
@@ -49,7 +51,9 @@ units = {
"odometer": {"unit": LENGTH_MILES}, "odometer": {"unit": LENGTH_MILES},
"average_speed": {"unit": SPEED_MILES_PER_HOUR}, "average_speed": {"unit": SPEED_MILES_PER_HOUR},
"distance_to_empty": {"unit": LENGTH_MILES}, "distance_to_empty": {"unit": LENGTH_MILES},
"distance_to_service": {"unit": LENGTH_MILES} "distance_to_service": {"unit": LENGTH_MILES},
"trip_distance": {"unit": LENGTH_MILES},
"trip_speed": {"unit": SPEED_MILES_PER_HOUR}
} }
} }
+15 -8
View File
@@ -48,6 +48,10 @@ def authorize(renew_tokenfile=False):
logging.warning("Detected corrupted token file, restarting auth process") logging.warning("Detected corrupted token file, restarting auth process")
authorize(True) authorize(True)
return return
except KeyError:
logging.warning("Token file missing refresh_token, restarting auth process")
authorize(True)
return
else: else:
logging.info("Starting login with OTP") logging.info("Starting login with OTP")
auth_session = requests.session() auth_session = requests.session()
@@ -171,8 +175,9 @@ def send_otp(auth_session, data):
def refresh_auth(): def refresh_auth():
logging.info("Refreshing credentials")
global refresh_token global refresh_token
logging.info("Refreshing credentials with token " + refresh_token)
headers = { headers = {
"authorization": "Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=", "authorization": "Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=",
"content-type": "application/x-www-form-urlencoded", "content-type": "application/x-www-form-urlencoded",
@@ -194,14 +199,16 @@ def refresh_auth():
token_path = util.get_token_path() token_path = util.get_token_path()
refresh_data = auth.json() refresh_data = auth.json()
f = open(token_path) if not "refresh_token" in refresh_data:
try: f = open(token_path)
data = json.load(f) try:
refresh_token = data["refresh_token"] data = json.load(f)
except ValueError: refresh_data["refresh_token"] = data["refresh_token"]
raise Exception("Cannot refresh token!") except ValueError:
raise Exception("Cannot refresh token!")
else:
logging.info("New refresh token found, updating!")
refresh_data["refresh_token"] = refresh_token
util.save_to_json(refresh_data, token_path) util.save_to_json(refresh_data, token_path)
session.headers.update({"authorization": "Bearer " + refresh_data["access_token"]}) session.headers.update({"authorization": "Bearer " + refresh_data["access_token"]})