Handle transient transport errors in tesla_fleet setup (#180218)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Markus Tuominen <3738613+Markus98@users.noreply.github.com>
This commit is contained in:
Aaron S. Joyner
2026-09-11 16:41:27 +03:00
committed by GitHub
co-authored by Copilot Autofix powered by AI Markus Tuominen
parent 41448c31c8
commit 96c22f9ef5
2 changed files with 23 additions and 4 deletions
@@ -3,6 +3,7 @@
import asyncio
from typing import Final
from aiohttp import ClientError
import jwt
from tesla_fleet_api import TeslaFleetApi, is_valid_region
from tesla_fleet_api.const import Scope
@@ -77,7 +78,12 @@ async def _async_get_products(tesla: TeslaFleetApi) -> list[dict]:
OAuth2TokenRequestReauthError,
) as e:
raise ConfigEntryAuthFailed from e
except (TeslaFleetError, OAuth2TokenRequestError) as e:
except (
TeslaFleetError,
OAuth2TokenRequestError,
ClientError,
TimeoutError,
) as e:
raise ConfigEntryNotReady from e
try:
@@ -90,7 +96,12 @@ async def _async_get_products(tesla: TeslaFleetApi) -> list[dict]:
OAuth2TokenRequestReauthError,
) as e:
raise ConfigEntryAuthFailed from e
except (TeslaFleetError, OAuth2TokenRequestError) as e:
except (
TeslaFleetError,
OAuth2TokenRequestError,
ClientError,
TimeoutError,
) as e:
raise ConfigEntryNotReady from e
try:
@@ -102,7 +113,12 @@ async def _async_get_products(tesla: TeslaFleetApi) -> list[dict]:
OAuth2TokenRequestReauthError,
) as e:
raise ConfigEntryAuthFailed from e
except (TeslaFleetError, OAuth2TokenRequestError) as e:
except (
TeslaFleetError,
OAuth2TokenRequestError,
ClientError,
TimeoutError,
) as e:
raise ConfigEntryNotReady from e
+4 -1
View File
@@ -5,6 +5,7 @@ from copy import deepcopy
from datetime import timedelta
from unittest.mock import AsyncMock, Mock, PropertyMock, patch
from aiohttp import ClientError
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -57,6 +58,8 @@ SETUP_ERRORS = [
(OAuthExpired, ConfigEntryState.SETUP_ERROR),
(LoginRequired, ConfigEntryState.SETUP_ERROR),
(TeslaFleetError, ConfigEntryState.SETUP_RETRY),
(ClientError, ConfigEntryState.SETUP_RETRY),
(TimeoutError, ConfigEntryState.SETUP_RETRY),
]
RUNTIME_ERRORS = [InvalidToken, OAuthExpired, LoginRequired, TeslaFleetError]
@@ -87,7 +90,7 @@ async def test_init_error(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_products: AsyncMock,
side_effect: type[TeslaFleetError],
side_effect: type[Exception],
state: ConfigEntryState,
) -> None:
"""Test init with errors."""