From 320f183713e2ba565f63b43e2dd1d51eff97ba8a Mon Sep 17 00:00:00 2001 From: rleidner Date: Mon, 8 Dec 2025 16:43:27 +0100 Subject: [PATCH 1/2] soc_vwid: send more detailed error info to status window --- packages/modules/vehicles/vwid/libvwid.py | 126 +++++++++++----------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/packages/modules/vehicles/vwid/libvwid.py b/packages/modules/vehicles/vwid/libvwid.py index 74ddaf5256..6df99f59a6 100755 --- a/packages/modules/vehicles/vwid/libvwid.py +++ b/packages/modules/vehicles/vwid/libvwid.py @@ -1422,70 +1422,68 @@ async def get_status(self): data['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] = str(0) data['charging']['batteryStatus']['value']['carCapturedTimestamp'] = _now - try: - _k = str(vwid.connection.keys()) - _LOGGER.info(f"libvwid.get_status connections at entry: vwid.connections.keys={_k}") - if self.username not in vwid.connection: - _LOGGER.info(f"create new connection, key={self.username}") - vwid.connection[self.username] = Connection(session, self.username, self.password) - self._connection = vwid.connection[self.username] - vwid.connection[self.username]._session_tokens['identity'] = {} - vwid.connection[self.username]._session_tokens['Legacy'] = {} - for token in self.tokens: - vwid.connection[self.username]._session_tokens['identity'][token] = self.tokens[token] - vwid.connection[self.username]._session_tokens['Legacy'][token] = self.tokens[token] - _conn_reuse = False - else: - _LOGGER.info(f"reuse existing connection, key={self.username}") - vwid.connection[self.username]._session = session - _conn_reuse = True - if not _conn_reuse: + _k = str(vwid.connection.keys()) + _LOGGER.info(f"libvwid.get_status connections at entry: vwid.connections.keys={_k}") + if self.username not in vwid.connection: + _LOGGER.info(f"create new connection, key={self.username}") + vwid.connection[self.username] = Connection(session, self.username, self.password) + self._connection = vwid.connection[self.username] + vwid.connection[self.username]._session_tokens['identity'] = {} + vwid.connection[self.username]._session_tokens['Legacy'] = {} + for token in self.tokens: + vwid.connection[self.username]._session_tokens['identity'][token] = self.tokens[token] + vwid.connection[self.username]._session_tokens['Legacy'][token] = self.tokens[token] + _conn_reuse = False + else: + _LOGGER.info(f"reuse existing connection, key={self.username}") + vwid.connection[self.username]._session = session + _conn_reuse = True + if not _conn_reuse: + _doLogin_result = await vwid.connection[self.username].doLogin() + _LOGGER.debug("after 1st doLogin, result=" + str(_doLogin_result)) + if _doLogin_result: + _update_result = True + else: + _update_result = await vwid.connection[self.username].update() + _LOGGER.debug("after 1st connection.update without doLogin, result=" + str(_update_result)) + if not _update_result: _doLogin_result = await vwid.connection[self.username].doLogin() - _LOGGER.debug("after 1st doLogin, result=" + str(_doLogin_result)) + _LOGGER.debug("after 2nd doLogin, result=" + str(_doLogin_result)) if _doLogin_result: - _update_result = True - else: - _update_result = await vwid.connection[self.username].update() - _LOGGER.debug("after 1st connection.update without doLogin, result=" + str(_update_result)) - if not _update_result: - _doLogin_result = await vwid.connection[self.username].doLogin() - _LOGGER.debug("after 2nd doLogin, result=" + str(_doLogin_result)) - if _doLogin_result: - _update_result = await vwid.connection[self.username].update() - _LOGGER.debug("after 2nd connection.update, result=" + str(_update_result)) - else: - _LOGGER.error("retry doLogin failed, exit") - raise Exception("Login failed") - if _update_result: - _LOGGER.debug("update/doLogin look OK, get results") - for vehicle in vwid.connection[self.username].vehicles: - _LOGGER.debug("vehicle loop: " + str(vehicle) + ", self.vin=" + str(self.vin)) - if str(vehicle) == str(self.vin): - _LOGGER.debug("vehicle loop match: " + str(vehicle) + ", self.vin=" + str(self.vin)) - soc = vehicle._states['charging']['batteryStatus']['value']['currentSOC_pct'] - range =\ - vehicle._states['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] - ts = vehicle._states['charging']['batteryStatus']['value']['carCapturedTimestamp'] - _LOGGER.debug("vehicle =" + str(vehicle)) - _LOGGER.debug("soc =" + str(soc)) - _LOGGER.debug("range =" + str(range)) - _LOGGER.debug("timestamp=" + str(ts)) - tsxx = ts.strftime('%Y-%m-%dT%H:%M:%SZ') - _LOGGER.debug("timestampxx=" + str(tsxx)) - data['charging']['batteryStatus']['value']['currentSOC_pct'] = str(soc) - data['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] = str(range) - data['charging']['batteryStatus']['value']['carCapturedTimestamp'] = str(tsxx) - _LOGGER.debug("return data =" + to_json(data, indent=4)) - for token in vwid.connection[self.username]._session_tokens['identity']: - self.tokens[token] =\ - vwid.connection[self.username]._session_tokens['identity'][token] - return data + _update_result = await vwid.connection[self.username].update() + _LOGGER.debug("after 2nd connection.update, result=" + str(_update_result)) + else: + _LOGGER.error(f"retry doLogin for user {self.username} failed, exit") + raise Exception(f"Login für User {self.usename} fehlgeschlagen") + if _update_result: + _LOGGER.debug("update/doLogin look OK, get results") + for vehicle in vwid.connection[self.username].vehicles: + _LOGGER.debug("vehicle loop: " + str(vehicle) + ", self.vin=" + str(self.vin)) + if str(vehicle) == str(self.vin): + _LOGGER.debug("vehicle loop match: " + str(vehicle) + ", self.vin=" + str(self.vin)) + soc = vehicle._states['charging']['batteryStatus']['value']['currentSOC_pct'] + range =\ + vehicle._states['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] + ts = vehicle._states['charging']['batteryStatus']['value']['carCapturedTimestamp'] + _LOGGER.debug("vehicle =" + str(vehicle)) + _LOGGER.debug("soc =" + str(soc)) + _LOGGER.debug("range =" + str(range)) + _LOGGER.debug("timestamp=" + str(ts)) + tsxx = ts.strftime('%Y-%m-%dT%H:%M:%SZ') + _LOGGER.debug("timestampxx=" + str(tsxx)) + data['charging']['batteryStatus']['value']['currentSOC_pct'] = str(soc) + data['charging']['batteryStatus']['value']['cruisingRangeElectric_km'] = str(range) + data['charging']['batteryStatus']['value']['carCapturedTimestamp'] = str(tsxx) + _LOGGER.debug("return data =" + to_json(data, indent=4)) + for token in vwid.connection[self.username]._session_tokens['identity']: + self.tokens[token] =\ + vwid.connection[self.username]._session_tokens['identity'][token] + return data else: - _LOGGER.error("get_status rsp. update failed, raise exception") - raise Exception("get_status: keine Daten empfangen") - except Exception as error: - _LOGGER.exception("get_status failed 1, raise exception, exception=" + str(error)) - raise Exception(error) - except Exception as error: - _LOGGER.exception("get_status failed 0, raise exception=" + str(error)) - raise Exception(error) + raise Exception(f"Fahrzeug mit VIN {self.vin} nicht gefunden.") + else: + _LOGGER.error("get_status update failed, raise exception") + raise Exception(f"Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen.") + except Exception as e: + _LOGGER.exception("get_status failed 0, raise exception=" + str(e)) + raise Exception(f"Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen. {e}") From 43ed2abd86d91ad52c02d4ce4b94787389ef44c1 Mon Sep 17 00:00:00 2001 From: rleidner Date: Tue, 9 Dec 2025 10:08:23 +0100 Subject: [PATCH 2/2] add error codes SOCERR-xx --- packages/modules/vehicles/vwid/libvwid.py | 26 +++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/modules/vehicles/vwid/libvwid.py b/packages/modules/vehicles/vwid/libvwid.py index 6df99f59a6..0209d1b761 100755 --- a/packages/modules/vehicles/vwid/libvwid.py +++ b/packages/modules/vehicles/vwid/libvwid.py @@ -1411,6 +1411,10 @@ def set_jobs(self, jobs): self.jobs_string = ','.join(jobs) async def get_status(self): + # error codes SOCERR-xx raised: + # SOCERR-00: general error + # SOCERR-01: login problem, username, password wrong, account locked, etc. + # SOCERR-02: vehicle not found in account, VIN wrong? try: async with aiohttp.ClientSession(headers={'Connection': 'keep-alive'}) as session: _now = datetime.now(UTC).strftime('%Y-%m-%dT%H:%M:%SZ') @@ -1424,6 +1428,7 @@ async def get_status(self): _k = str(vwid.connection.keys()) _LOGGER.info(f"libvwid.get_status connections at entry: vwid.connections.keys={_k}") + _update_result = False if self.username not in vwid.connection: _LOGGER.info(f"create new connection, key={self.username}") vwid.connection[self.username] = Connection(session, self.username, self.password) @@ -1443,6 +1448,8 @@ async def get_status(self): _LOGGER.debug("after 1st doLogin, result=" + str(_doLogin_result)) if _doLogin_result: _update_result = True + else: + raise Exception(f"SOCERR-01: Login für User {self.username} fehlgeschlagen") else: _update_result = await vwid.connection[self.username].update() _LOGGER.debug("after 1st connection.update without doLogin, result=" + str(_update_result)) @@ -1454,7 +1461,7 @@ async def get_status(self): _LOGGER.debug("after 2nd connection.update, result=" + str(_update_result)) else: _LOGGER.error(f"retry doLogin for user {self.username} failed, exit") - raise Exception(f"Login für User {self.usename} fehlgeschlagen") + raise Exception(f"SOCERR-01: Login für User {self.username} fehlgeschlagen") if _update_result: _LOGGER.debug("update/doLogin look OK, get results") for vehicle in vwid.connection[self.username].vehicles: @@ -1480,10 +1487,17 @@ async def get_status(self): vwid.connection[self.username]._session_tokens['identity'][token] return data else: - raise Exception(f"Fahrzeug mit VIN {self.vin} nicht gefunden.") + _LOGGER.error(f"SOCERR-02: Fahrzeug mit VIN {self.vin} nicht gefunden") + raise Exception(f"SOCERR-02: Fahrzeug mit VIN {self.vin} nicht gefunden") else: - _LOGGER.error("get_status update failed, raise exception") - raise Exception(f"Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen.") + _t = f"SOCERR-00: Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen." + _LOGGER.error(f"{_t}: get_status update failed") + raise Exception(_t) except Exception as e: - _LOGGER.exception("get_status failed 0, raise exception=" + str(e)) - raise Exception(f"Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen. {e}") + _LOGGER.exception(f"get_status failed 0, exception={e}") + # if exception is a SOCERR reraise it, otherwise raise general SOCERR-00 + if "SOCERR" in str(e): + raise e + else: + _t = f"SOCERR-00: Für User {self.username} und VIN {self.vin} wurden keine Daten empfangen" + raise Exception(f"{_t} {e}")