Skip to content

Commit 81214c0

Browse files
authored
soc_vwid: support more than 1 account (#2989)
1 parent 47c83b9 commit 81214c0

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

packages/modules/vehicles/vwid/libvwid.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,39 +1419,41 @@ async def get_status(self):
14191419
data['charging']['batteryStatus']['value']['carCapturedTimestamp'] = _now
14201420

14211421
if 'connection' not in globals() or connection is None:
1422+
connection = {}
1423+
if self.username not in connection or connection[self.username] != self.username:
14221424
_LOGGER.debug("create new connection")
1423-
connection = Connection(session, self.username, self.password)
1424-
connection._session_tokens['identity'] = {}
1425-
connection._session_tokens['Legacy'] = {}
1425+
connection[self.username] = Connection(session, self.username, self.password)
1426+
connection[self.username]._session_tokens['identity'] = {}
1427+
connection[self.username]._session_tokens['Legacy'] = {}
14261428
for token in self.tokens:
1427-
connection._session_tokens['identity'][token] = self.tokens[token]
1428-
connection._session_tokens['Legacy'][token] = self.tokens[token]
1429+
connection[self.username]._session_tokens['identity'][token] = self.tokens[token]
1430+
connection[self.username]._session_tokens['Legacy'][token] = self.tokens[token]
14291431
_conn_reuse = False
14301432
else:
14311433
_LOGGER.debug("reuse existing connection")
1432-
connection._session = session
1434+
connection[self.username]._session = session
14331435
_conn_reuse = True
14341436
try:
14351437
if not _conn_reuse:
1436-
_doLogin_result = await connection.doLogin()
1438+
_doLogin_result = await connection[self.username].doLogin()
14371439
_LOGGER.debug("after 1st doLogin, result=" + str(_doLogin_result))
14381440
if _doLogin_result:
14391441
_update_result = True
14401442
else:
1441-
_update_result = await connection.update()
1443+
_update_result = await connection[self.username].update()
14421444
_LOGGER.debug("after 1st connection.update without doLogin, result=" + str(_update_result))
14431445
if not _update_result:
1444-
_doLogin_result = await connection.doLogin()
1446+
_doLogin_result = await connection[self.username].doLogin()
14451447
_LOGGER.debug("after 2nd doLogin, result=" + str(_doLogin_result))
14461448
if _doLogin_result:
1447-
_update_result = await connection.update()
1449+
_update_result = await connection[self.username].update()
14481450
_LOGGER.debug("after 2nd connection.update, result=" + str(_update_result))
14491451
else:
14501452
_LOGGER.debug("retry doLogin failed, exit")
14511453
return data
14521454
if _update_result:
14531455
_LOGGER.debug("update/doLogin look OK, get results")
1454-
for vehicle in connection.vehicles:
1456+
for vehicle in connection[self.username].vehicles:
14551457
_LOGGER.debug("vehicle loop: " + str(vehicle) + ", self.vin=" + str(self.vin))
14561458
if str(vehicle) == str(self.vin):
14571459
_LOGGER.debug("vehicle loop match: " + str(vehicle) + ", self.vin=" + str(self.vin))
@@ -1468,8 +1470,8 @@ async def get_status(self):
14681470
data['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] = str(range)
14691471
data['charging']['batteryStatus']['value']['carCapturedTimestamp'] = str(tsxx)
14701472
_LOGGER.debug("return data =" + to_json(data, indent=4))
1471-
for token in connection._session_tokens['identity']:
1472-
self.tokens[token] = connection._session_tokens['identity'][token]
1473+
for token in connection[self.username]._session_tokens['identity']:
1474+
self.tokens[token] = connection[self.username]._session_tokens['identity'][token]
14731475
return data
14741476
else:
14751477
_LOGGER.warning("get_status rsp. update failed, return soc 0")

0 commit comments

Comments
 (0)