"""Tests for Vodafone Station init.""" from unittest.mock import AsyncMock from homeassistant.components.device_tracker import CONF_CONSIDER_HOME from homeassistant.components.vodafone_station.const import ( CONF_DEVICE_DETAILS, DEVICE_TYPE, DEVICE_URL, DOMAIN, ) from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from . import setup_integration from .const import TEST_HOST, TEST_PASSWORD, TEST_TYPE, TEST_URL, TEST_USERNAME from tests.common import MockConfigEntry async def test_reload_config_entry_with_options( hass: HomeAssistant, mock_vodafone_station_router: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: """Test the the config entry is reloaded with options.""" await setup_integration(hass, mock_config_entry) result = await hass.config_entries.options.async_init(mock_config_entry.entry_id) result = await hass.config_entries.options.async_configure( result["flow_id"], user_input={ CONF_CONSIDER_HOME: 37, }, ) assert result["type"] is FlowResultType.CREATE_ENTRY assert result["data"] == { CONF_CONSIDER_HOME: 37, } async def test_unload_entry( hass: HomeAssistant, mock_vodafone_station_router: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: """Test unloading the config entry.""" await setup_integration(hass, mock_config_entry) assert len(hass.config_entries.async_entries(DOMAIN)) == 1 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 assert not hass.data.get(DOMAIN) async def test_migrate_entry( hass: HomeAssistant, mock_vodafone_station_router: AsyncMock, mock_config_entry: MockConfigEntry, ) -> None: """Test successful migration of entry data.""" config_entry = MockConfigEntry( domain=DOMAIN, title=TEST_HOST, data={ CONF_HOST: TEST_HOST, CONF_USERNAME: TEST_USERNAME, CONF_PASSWORD: TEST_PASSWORD, }, unique_id="vodafone", version=1, minor_version=1, ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert config_entry.state is ConfigEntryState.LOADED assert config_entry.minor_version == 2 assert config_entry.data[CONF_DEVICE_DETAILS] == { DEVICE_TYPE: TEST_TYPE, DEVICE_URL: TEST_URL, }