From 3af270c6b0d48cfeffc523f2d734b1937320c9d3 Mon Sep 17 00:00:00 2001 From: coreywillwhat <104224685+coreywillwhat@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:51:21 -0600 Subject: [PATCH 1/3] fix: 502 Logging --- .../audiconnect/audi_connect_account.py | 87 ++++++++++++++----- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/custom_components/audiconnect/audi_connect_account.py b/custom_components/audiconnect/audi_connect_account.py index c70f5ee1..ba00c38e 100644 --- a/custom_components/audiconnect/audi_connect_account.py +++ b/custom_components/audiconnect/audi_connect_account.py @@ -185,15 +185,22 @@ async def refresh_vehicle_data(self, vin: str): except ClientResponseError as cre: if cre.status in (403, 404): _LOGGER.debug( - "ClientResponseError with status %s while refreshing vehicle data for VIN: %s. Disabling refresh vehicle data support.", + "VEHICLE REFRESH: ClientResponseError with status %s while refreshing vehicle data for VIN: %s. Disabling refresh vehicle data support.", cre.status, redacted_vin, ) self._support_vehicle_refresh = False return "disabled" + elif cre.status == 502: + _LOGGER.debug( + "VEHICLE REFRESH: ClientResponseError with status %s while refreshing vehicle data for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) + return False elif cre.status != 204: _LOGGER.debug( - "ClientResponseError with status %s while refreshing vehicle data for VIN: %s. Error: %s", + "VEHICLE REFRESH: ClientResponseError with status %s while refreshing vehicle data for VIN: %s. Error: %s", cre.status, redacted_vin, cre, @@ -201,14 +208,14 @@ async def refresh_vehicle_data(self, vin: str): return False else: _LOGGER.debug( - "Refresh vehicle data currently not available for VIN: %s. Received 204 status.", + "VEHICLE REFRESH: Refresh vehicle data currently not available for VIN: %s. Received 204 status.", redacted_vin, ) return False except Exception as e: _LOGGER.error( - "An unexpected error occurred while refreshing vehicle data for VIN: %s. Error: %s", + "VEHICLE REFRESH: An unexpected error occurred while refreshing vehicle data for VIN: %s. Error: %s", redacted_vin, e, ) @@ -663,6 +670,12 @@ async def update_vehicle_position(self): redacted_vin, ) self.support_position = False + elif cre.status == 502: + _LOGGER.debug( + "POSITION: ClientResponseError with status %s while updating vehicle position for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) elif cre.status != 204: _LOGGER.error( "POSITION: ClientResponseError with status %s for VIN: %s. Error: %s", @@ -756,6 +769,12 @@ async def update_vehicle_climater(self): redacted_vin, ) self.support_climater = False + elif cre.status == 502: + _LOGGER.debug( + "CLIMATER: ClientResponseError with status %s while updating climater for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) elif cre.status != 204: _LOGGER.debug( "ClientResponseError with status %s while updating climater for VIN: %s. Error: %s", @@ -777,6 +796,7 @@ async def update_vehicle_climater(self): ) async def update_vehicle_preheater(self): + redacted_vin = "*" * (len(self._vehicle.vin) - 4) + self._vehicle.vin[-4:] if not self.support_preheater: return @@ -790,14 +810,20 @@ async def update_vehicle_preheater(self): except TimeoutError: raise - except ClientResponseError as resp_exception: - if resp_exception.status in (403, 404): - # _LOGGER.error( - # "support_preheater set to False: {status}".format( - # status=resp_exception.status - # ) - # ) + except ClientResponseError as cre: + if cre.status in (403, 404): + _LOGGER.debug( + "PREHEATER: ClientResponseError with status %s while updating preheater for VIN: %s. Disabling preheater support.", + cre.status, + redacted_vin, + ) self.support_preheater = False + elif cre.status == 502: + _LOGGER.debug( + "PREHEATER: ClientResponseError with status %s while updating preheater for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) else: self.log_exception_once( resp_exception, @@ -814,6 +840,7 @@ async def update_vehicle_preheater(self): ) async def update_vehicle_charger(self): + redacted_vin = "*" * (len(self._vehicle.vin) - 4) + self._vehicle.vin[-4:] if not self.support_charger: return @@ -890,14 +917,20 @@ async def update_vehicle_charger(self): except TimeoutError: raise - except ClientResponseError as resp_exception: - if resp_exception.status in (403, 404): - # _LOGGER.error( - # "support_charger set to False: {status}".format( - # status=resp_exception.status - # ) - # ) + except ClientResponseError as cre: + if cre.status in (403, 404): + _LOGGER.debug( + "CHARGER: ClientResponseError with status %s while updating charger for VIN: %s. Disabling charger support.", + cre.status, + redacted_vin, + ) self.support_charger = False + elif cre.status == 502: + _LOGGER.debug( + "CHARGER: ClientResponseError with status %s while updating charger for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) else: self.log_exception_once( resp_exception, @@ -923,7 +956,7 @@ async def update_vehicle_tripdata(self, kind: str): redacted_vin = "*" * (len(self._vehicle.vin) - 4) + self._vehicle.vin[-4:] if not self.support_trip_data: _LOGGER.debug( - "Trip data support is disabled for VIN: %s. Exiting update process.", + "TRIP DATA: Trip data support is disabled for VIN: %s. Exiting update process.", redacted_vin, ) return @@ -958,34 +991,40 @@ async def update_vehicle_tripdata(self, kind: str): except TimeoutError: _LOGGER.debug( - "TimeoutError encountered while updating trip data for VIN: %s.", + "TRIP DATA: TimeoutError encountered while updating trip data for VIN: %s.", redacted_vin, ) raise except ClientResponseError as cre: if cre.status in (403, 404): _LOGGER.debug( - "ClientResponseError with status %s while updating trip data for VIN: %s. Disabling trip data support.", + "TRIP DATA: ClientResponseError with status %s while updating trip data for VIN: %s. Disabling trip data support.", cre.status, redacted_vin, ) self.support_trip_data = False + elif cre.status == 502: + _LOGGER.debug( + "TRIP DATA: ClientResponseError with status %s while updating trip data for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", + cre.status, + redacted_vin, + ) elif cre.status != 204: _LOGGER.debug( - "ClientResponseError with status %s while updating trip data for VIN: %s. Error: %s", + "TRIP DATA: ClientResponseError with status %s while updating trip data for VIN: %s. Error: %s", cre.status, redacted_vin, cre, ) else: _LOGGER.debug( - "Trip data currently not available for VIN: %s. Received 204 status.", + "TRIP DATA: Trip data currently not available for VIN: %s. Received 204 status.", redacted_vin, ) except Exception as e: _LOGGER.error( - "An unexpected error occurred while updating trip data for VIN: %s. Error: %s", + "TRIP DATA: An unexpected error occurred while updating trip data for VIN: %s. Error: %s", redacted_vin, e, ) From 12f1e0a8f283dd5ab9a890aa054b43e589d00952 Mon Sep 17 00:00:00 2001 From: coreywillwhat <104224685+coreywillwhat@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:53:39 -0600 Subject: [PATCH 2/3] Update audi_connect_account.py --- custom_components/audiconnect/audi_connect_account.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/audiconnect/audi_connect_account.py b/custom_components/audiconnect/audi_connect_account.py index ba00c38e..660373b3 100644 --- a/custom_components/audiconnect/audi_connect_account.py +++ b/custom_components/audiconnect/audi_connect_account.py @@ -826,7 +826,7 @@ async def update_vehicle_preheater(self): ) else: self.log_exception_once( - resp_exception, + cre, "Unable to obtain the vehicle preheater state for {}".format( self._vehicle.vin ), @@ -933,7 +933,7 @@ async def update_vehicle_charger(self): ) else: self.log_exception_once( - resp_exception, + cre, "Unable to obtain the vehicle charger state for {}".format( self._vehicle.vin ), From 26952d9737d5a12978de135ff25f7dc51aa01d52 Mon Sep 17 00:00:00 2001 From: coreywillwhat <104224685+coreywillwhat@users.noreply.github.com> Date: Sat, 27 Jul 2024 11:15:13 -0600 Subject: [PATCH 3/3] Update audi_connect_account.py --- .../audiconnect/audi_connect_account.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/audiconnect/audi_connect_account.py b/custom_components/audiconnect/audi_connect_account.py index 660373b3..a40b05a8 100644 --- a/custom_components/audiconnect/audi_connect_account.py +++ b/custom_components/audiconnect/audi_connect_account.py @@ -192,7 +192,7 @@ async def refresh_vehicle_data(self, vin: str): self._support_vehicle_refresh = False return "disabled" elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "VEHICLE REFRESH: ClientResponseError with status %s while refreshing vehicle data for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin, @@ -671,7 +671,7 @@ async def update_vehicle_position(self): ) self.support_position = False elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "POSITION: ClientResponseError with status %s while updating vehicle position for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin, @@ -770,7 +770,7 @@ async def update_vehicle_climater(self): ) self.support_climater = False elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "CLIMATER: ClientResponseError with status %s while updating climater for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin, @@ -819,7 +819,7 @@ async def update_vehicle_preheater(self): ) self.support_preheater = False elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "PREHEATER: ClientResponseError with status %s while updating preheater for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin, @@ -926,7 +926,7 @@ async def update_vehicle_charger(self): ) self.support_charger = False elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "CHARGER: ClientResponseError with status %s while updating charger for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin, @@ -1004,7 +1004,7 @@ async def update_vehicle_tripdata(self, kind: str): ) self.support_trip_data = False elif cre.status == 502: - _LOGGER.debug( + _LOGGER.warning( "TRIP DATA: ClientResponseError with status %s while updating trip data for VIN: %s. This issue may resolve in time. If it persists, please open an issue.", cre.status, redacted_vin,