From 012e8ce61e5053a0e6961cd4a521d75731fe52cd Mon Sep 17 00:00:00 2001 From: rleidner Date: Tue, 14 Jan 2025 18:00:32 +0100 Subject: [PATCH] soc_bmwbc: fix session_id, rename to BMW & Mini --- packages/modules/vehicles/bmwbc/api.py | 18 ++++++++++++++---- packages/modules/vehicles/bmwbc/config.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/modules/vehicles/bmwbc/api.py b/packages/modules/vehicles/bmwbc/api.py index c7843a0ab9..7a54d1b188 100755 --- a/packages/modules/vehicles/bmwbc/api.py +++ b/packages/modules/vehicles/bmwbc/api.py @@ -34,8 +34,9 @@ def init_store(): store['refresh_token'] = None store['access_token'] = None store['expires_at'] = None - if 'captcha_token' not in store: - store['captcha_token'] = None + store['gcid'] = None + store['session_id'] = None + store['captcha_token'] = None return store @@ -82,7 +83,7 @@ async def _fetch_soc(user_id: str, password: str, vin: str, captcha_token: str, log.error("init: dataPath creation failed, dataPath: " + str(DATA_PATH) + ", error=" + str(e)) store = init_store() - return store + return 0, 0.0 storeFile = str(DATA_PATH) + '/soc_bmwbc_vh_' + str(vnum) + '.json' try: @@ -104,6 +105,8 @@ async def _fetch_soc(user_id: str, password: str, vin: str, captcha_token: str, store['expires_at'] = None store['access_token'] = None store['refresh_token'] = None + store['session_id'] = None + store['gcid'] = None else: log.info("captcha token unchanged") @@ -124,6 +127,11 @@ async def _fetch_soc(user_id: str, password: str, vin: str, captcha_token: str, Regions.REST_OF_WORLD, hcaptcha_token=captcha_token) + if store['session_id'] is not None: + auth.session_id = store['session_id'] + if store['gcid'] is not None: + auth.gcid = store['gcid'] + clconf = MyBMWClientConfiguration(auth) # account = MyBMWAccount(user_id, password, Regions.REST_OF_WORLD, config=clconf) # user, password and region already set in BMWAuthentication/ClientConfiguration! @@ -154,10 +162,12 @@ async def _fetch_soc(user_id: str, password: str, vin: str, captcha_token: str, # store token and expires_at if changed expires_at = datetime.datetime.isoformat(auth.expires_at) - if store['expires_at'] != expires_at: + if store['expires_at'] != expires_at or store['session_id'] != auth.session_id: store['refresh_token'] = auth.refresh_token store['access_token'] = auth.access_token store['captcha_token'] = captcha_token + store['session_id'] = auth.session_id + store['gcid'] = auth.gcid store['expires_at'] = datetime.datetime.isoformat(auth.expires_at) write_store(store) diff --git a/packages/modules/vehicles/bmwbc/config.py b/packages/modules/vehicles/bmwbc/config.py index 20a8143da9..0862772f64 100755 --- a/packages/modules/vehicles/bmwbc/config.py +++ b/packages/modules/vehicles/bmwbc/config.py @@ -17,7 +17,7 @@ def __init__(self, class BMWbc: def __init__(self, - name: str = "BMW (Bimmer)", + name: str = "BMW & Mini ", type: str = "bmwbc", configuration: BMWbcConfiguration = None) -> None: self.name = name