"""Test the NMBS integration setup.""" from unittest.mock import AsyncMock from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry async def test_setup_entry( hass: HomeAssistant, mock_nmbs_client: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: """Test a config entry is set up successfully.""" 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 async def test_setup_entry_api_unavailable( hass: HomeAssistant, mock_nmbs_client: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: """Test the entry is retried when the station list cannot be fetched.""" mock_nmbs_client.get_stations.return_value = 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