Skip to content

Commit

Permalink
fix: 502 Logging (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreywillwhat authored Jul 27, 2024
1 parent 5bcfd20 commit c988a2d
Showing 1 changed file with 65 additions and 26 deletions.
91 changes: 65 additions & 26 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,37 @@ 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.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,
)
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,
)
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,
)
Expand Down Expand Up @@ -663,6 +670,12 @@ async def update_vehicle_position(self):
redacted_vin,
)
self.support_position = False
elif cre.status == 502:
_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,
)
elif cre.status != 204:
_LOGGER.error(
"POSITION: ClientResponseError with status %s for VIN: %s. Error: %s",
Expand Down Expand Up @@ -756,6 +769,12 @@ async def update_vehicle_climater(self):
redacted_vin,
)
self.support_climater = False
elif cre.status == 502:
_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,
)
elif cre.status != 204:
_LOGGER.debug(
"ClientResponseError with status %s while updating climater for VIN: %s. Error: %s",
Expand All @@ -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

Expand All @@ -790,17 +810,23 @@ 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.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,
)
else:
self.log_exception_once(
resp_exception,
cre,
"Unable to obtain the vehicle preheater state for {}".format(
self._vehicle.vin
),
Expand All @@ -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

Expand Down Expand Up @@ -890,17 +917,23 @@ 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.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,
)
else:
self.log_exception_once(
resp_exception,
cre,
"Unable to obtain the vehicle charger state for {}".format(
self._vehicle.vin
),
Expand All @@ -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
Expand Down Expand Up @@ -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.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,
)
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,
)
Expand Down

0 comments on commit c988a2d

Please sign in to comment.