mirror of
https://github.com/home-assistant/core.git
synced 2026-10-05 21:07:41 +01:00
Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Joostlek <joostlek@outlook.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""Tests for the Volkszaehler integration setup."""
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
from volkszaehler.exceptions import VolkszaehlerApiConnectionError
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_setup_and_unload_entry(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_api: AsyncMock,
|
|
) -> None:
|
|
"""Test successful setup and unload of a config entry."""
|
|
mock_api.data = {"rows": []}
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
|
assert "existing-subentry-id" in mock_config_entry.runtime_data
|
|
|
|
assert await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
async def test_setup_entry_connection_error(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_api: AsyncMock,
|
|
) -> None:
|
|
"""Test setup retry when the API cannot be reached."""
|
|
mock_api.get_data.side_effect = VolkszaehlerApiConnectionError()
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
async def test_setup_entry_no_data(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
mock_api: AsyncMock,
|
|
) -> None:
|
|
"""Test setup retry when the API returns no data."""
|
|
mock_api.data = None
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|