mirror of
https://github.com/home-assistant/core.git
synced 2026-03-01 06:16:29 +00:00
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Joostlek <joostlek@outlook.com>
93 lines
2.8 KiB
Python
93 lines
2.8 KiB
Python
"""Test the Tessie init."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from tesla_fleet_api.exceptions import TeslaFleetError
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .common import ERROR_AUTH, ERROR_CONNECTION, ERROR_UNKNOWN, setup_platform
|
|
|
|
|
|
async def test_load_unload(hass: HomeAssistant) -> None:
|
|
"""Test load and unload."""
|
|
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.LOADED
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
async def test_auth_failure(
|
|
hass: HomeAssistant, mock_get_state_of_all_vehicles
|
|
) -> None:
|
|
"""Test init with an authentication error."""
|
|
|
|
mock_get_state_of_all_vehicles.side_effect = ERROR_AUTH
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_ERROR
|
|
|
|
|
|
async def test_unknown_failure(
|
|
hass: HomeAssistant, mock_get_state_of_all_vehicles
|
|
) -> None:
|
|
"""Test init with an client response error."""
|
|
|
|
mock_get_state_of_all_vehicles.side_effect = ERROR_UNKNOWN
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_ERROR
|
|
|
|
|
|
async def test_connection_failure(
|
|
hass: HomeAssistant, mock_get_state_of_all_vehicles
|
|
) -> None:
|
|
"""Test init with a network connection error."""
|
|
|
|
mock_get_state_of_all_vehicles.side_effect = ERROR_CONNECTION
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("side_effect", "expected_state"),
|
|
[
|
|
(ERROR_AUTH, ConfigEntryState.SETUP_ERROR),
|
|
(ERROR_UNKNOWN, ConfigEntryState.SETUP_ERROR),
|
|
(ERROR_CONNECTION, ConfigEntryState.SETUP_RETRY),
|
|
],
|
|
)
|
|
async def test_battery_setup_failure(
|
|
hass: HomeAssistant,
|
|
mock_get_battery,
|
|
side_effect: Exception,
|
|
expected_state: ConfigEntryState,
|
|
) -> None:
|
|
"""Test init with a battery API error."""
|
|
|
|
mock_get_battery.side_effect = side_effect
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is expected_state
|
|
|
|
|
|
async def test_products_error(hass: HomeAssistant) -> None:
|
|
"""Test init with a fleet error on products."""
|
|
|
|
with patch(
|
|
"homeassistant.components.tessie.Tessie.products", side_effect=TeslaFleetError
|
|
):
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
async def test_scopes_error(hass: HomeAssistant) -> None:
|
|
"""Test init with a fleet error on scopes."""
|
|
|
|
with patch(
|
|
"homeassistant.components.tessie.Tessie.scopes", side_effect=TeslaFleetError
|
|
):
|
|
entry = await setup_platform(hass)
|
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|