Treat temporary errors as warnings for Tesla (#54515)

* Treat temporary errors as warnings for Tesla
closes #53391

* Apply suggestions from code review

Co-authored-by: J. Nick Koston <nick@koston.org>

* Black

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Alan Tse 2021-08-15 06:09:06 -07:00 committed by GitHub
parent 54da424507
commit ee7116d0e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -177,6 +177,15 @@ async def async_setup_entry(hass, config_entry):
await async_client.aclose()
if ex.code == HTTP_UNAUTHORIZED:
raise ConfigEntryAuthFailed from ex
if ex.message in [
"VEHICLE_UNAVAILABLE",
"TOO_MANY_REQUESTS",
"SERVICE_MAINTENANCE",
"UPSTREAM_TIMEOUT",
]:
raise ConfigEntryNotReady(
f"Temporarily unable to communicate with Tesla API: {ex.message}"
) from ex
_LOGGER.error("Unable to communicate with Tesla API: %s", ex.message)
return False

View File

@ -175,7 +175,7 @@ async def validate_input(hass: core.HomeAssistant, data):
if ex.code == HTTP_UNAUTHORIZED:
_LOGGER.error("Invalid credentials: %s", ex)
raise InvalidAuth() from ex
_LOGGER.error("Unable to communicate with Tesla API: %s", ex)
_LOGGER.error("Unable to communicate with Tesla API: %s", ex.message)
raise CannotConnect() from ex
finally:
await async_client.aclose()