From 1a2f35f1b55accb356de7c02e82233a3b57eab2d Mon Sep 17 00:00:00 2001 From: linus Date: Sat, 23 Aug 2025 11:22:37 +0200 Subject: [PATCH] Add more logging for refresh process // renew refresh token if returned from api --- src/config.yaml | 2 +- src/const.py | 2 +- src/volvo.py | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/config.yaml b/src/config.yaml index 5710fc1..6c144df 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.12.1" +version: "1.12.2" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index 866781e..a541ce9 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.12.1" +VERSION = "v1.12.2" OAUTH_TOKEN_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" OAUTH_AUTH_URL = "https://volvoid.eu.volvocars.com/as/authorization.oauth2" diff --git a/src/volvo.py b/src/volvo.py index deee258..004f0f5 100644 --- a/src/volvo.py +++ b/src/volvo.py @@ -175,8 +175,9 @@ def send_otp(auth_session, data): def refresh_auth(): - logging.info("Refreshing credentials") global refresh_token + logging.info("Refreshing credentials with token " + refresh_token) + headers = { "authorization": "Basic aDRZZjBiOlU4WWtTYlZsNnh3c2c1WVFxWmZyZ1ZtSWFEcGhPc3kxUENhVXNpY1F0bzNUUjVrd2FKc2U0QVpkZ2ZJZmNMeXc=", "content-type": "application/x-www-form-urlencoded", @@ -198,12 +199,13 @@ def refresh_auth(): token_path = util.get_token_path() refresh_data = auth.json() - f = open(token_path) - try: - data = json.load(f) - refresh_token = data["refresh_token"] - except ValueError: - raise Exception("Cannot refresh token!") + if not "refresh_token" in refresh_data: + f = open(token_path) + try: + data = json.load(f) + refresh_token = data["refresh_token"] + except ValueError: + raise Exception("Cannot refresh token!") refresh_data["refresh_token"] = refresh_token util.save_to_json(refresh_data, token_path)