Skip to content

Commit

Permalink
soc_bmwbc: fix session_id, rename to BMW & Mini
Browse files Browse the repository at this point in the history
  • Loading branch information
rleidner committed Jan 14, 2025
1 parent f46779d commit 012e8ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions packages/modules/vehicles/bmwbc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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")

Expand All @@ -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!
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion packages/modules/vehicles/bmwbc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 012e8ce

Please sign in to comment.