Refactor Teslemetry integration (#112480)
* Refactor Teslemetry * Add abstractmethod * Remove unused timestamp const * Ruff * Fix * Update snapshots * ruff * Ruff * ruff * Lint * Fix tests * Fix tests and diag * Refix snapshot * Ruff * Fix * Fix bad merge * has as property * Remove _handle_coordinator_update * Test and error changes
This commit is contained in:
parent
11f5b48724
commit
1a4e416bf4
17 changed files with 562 additions and 323 deletions
|
@ -1,7 +1,5 @@
|
|||
"""Test the Tessie init."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from tesla_fleet_api.exceptions import (
|
||||
|
@ -11,13 +9,12 @@ from tesla_fleet_api.exceptions import (
|
|||
VehicleOffline,
|
||||
)
|
||||
|
||||
from homeassistant.components.teslemetry.coordinator import SYNC_INTERVAL
|
||||
from homeassistant.components.teslemetry.coordinator import VEHICLE_INTERVAL
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_platform
|
||||
from .const import WAKE_UP_ASLEEP, WAKE_UP_ONLINE
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
@ -50,48 +47,6 @@ async def test_init_error(
|
|||
|
||||
|
||||
# Vehicle Coordinator
|
||||
|
||||
|
||||
async def test_vehicle_first_refresh(
|
||||
hass: HomeAssistant,
|
||||
mock_wake_up,
|
||||
mock_vehicle_data,
|
||||
mock_products,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test first coordinator refresh but vehicle is asleep."""
|
||||
|
||||
# Mock vehicle is asleep
|
||||
mock_wake_up.return_value = WAKE_UP_ASLEEP
|
||||
entry = await setup_platform(hass)
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
mock_wake_up.assert_called_once()
|
||||
|
||||
# Reset mock and set vehicle to online
|
||||
mock_wake_up.reset_mock()
|
||||
mock_wake_up.return_value = WAKE_UP_ONLINE
|
||||
|
||||
# Wait for the retry
|
||||
freezer.tick(timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
# Verify we have loaded
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
mock_wake_up.assert_called_once()
|
||||
mock_vehicle_data.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("side_effect", "state"), ERRORS)
|
||||
async def test_vehicle_first_refresh_error(
|
||||
hass: HomeAssistant, mock_wake_up, side_effect, state
|
||||
) -> None:
|
||||
"""Test first coordinator refresh with an error."""
|
||||
mock_wake_up.side_effect = side_effect
|
||||
entry = await setup_platform(hass)
|
||||
assert entry.state is state
|
||||
|
||||
|
||||
async def test_vehicle_refresh_offline(
|
||||
hass: HomeAssistant, mock_vehicle_data, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
|
@ -102,7 +57,7 @@ async def test_vehicle_refresh_offline(
|
|||
mock_vehicle_data.reset_mock()
|
||||
|
||||
mock_vehicle_data.side_effect = VehicleOffline
|
||||
freezer.tick(timedelta(seconds=SYNC_INTERVAL))
|
||||
freezer.tick(VEHICLE_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
mock_vehicle_data.assert_called_once()
|
||||
|
@ -118,11 +73,9 @@ async def test_vehicle_refresh_error(
|
|||
assert entry.state is state
|
||||
|
||||
|
||||
# Test Energy Coordinator
|
||||
|
||||
|
||||
# Test Energy Live Coordinator
|
||||
@pytest.mark.parametrize(("side_effect", "state"), ERRORS)
|
||||
async def test_energy_refresh_error(
|
||||
async def test_energy_live_refresh_error(
|
||||
hass: HomeAssistant, mock_live_status, side_effect, state
|
||||
) -> None:
|
||||
"""Test coordinator refresh with an error."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue