mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
65c4b21ac4
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Test the Harman Luxury integration setup."""
|
|
|
|
from dataclasses import replace
|
|
from unittest.mock import AsyncMock
|
|
|
|
from aioharmanluxury import HarmanLuxuryError
|
|
import pytest
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import setup_integration
|
|
from .conftest import DEVICE_INFO
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
@pytest.mark.usefixtures("mock_client")
|
|
async def test_setup_and_unload(
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
|
) -> None:
|
|
"""Test a config entry loads and unloads cleanly."""
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
|
|
|
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_cannot_connect(
|
|
hass: HomeAssistant, mock_client: AsyncMock, mock_config_entry: MockConfigEntry
|
|
) -> None:
|
|
"""Test the config entry retries setup when the device is unreachable."""
|
|
mock_client.async_get_info.side_effect = HarmanLuxuryError
|
|
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
|
|
|
|
|
async def test_setup_unexpected_device(
|
|
hass: HomeAssistant, mock_client: AsyncMock, mock_config_entry: MockConfigEntry
|
|
) -> None:
|
|
"""Test setup fails when the host answers as a different device."""
|
|
mock_client.async_get_info.return_value = replace(DEVICE_INFO, serial="different")
|
|
|
|
await setup_integration(hass, mock_config_entry)
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|