"""Tests for the Xbox integration.""" from unittest.mock import AsyncMock, patch from httpx import ConnectTimeout, HTTPStatusError, ProtocolError import pytest from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @pytest.mark.usefixtures("xbox_live_client") async def test_entry_setup_unload( hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test integration setup and unload.""" config_entry.add_to_hass(hass) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(config_entry.entry_id) assert config_entry.state is ConfigEntryState.NOT_LOADED @pytest.mark.parametrize( "exception", [ConnectTimeout, HTTPStatusError, ProtocolError], ) async def test_config_entry_not_ready( hass: HomeAssistant, config_entry: MockConfigEntry, xbox_live_client: AsyncMock, exception: Exception, ) -> None: """Test config entry not ready.""" xbox_live_client.smartglass.get_console_list.side_effect = exception config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.SETUP_RETRY @pytest.mark.usefixtures("xbox_live_client") async def test_config_implementation_not_available( hass: HomeAssistant, config_entry: MockConfigEntry, ) -> None: """Test implementation not available.""" config_entry.add_to_hass(hass) with patch( "homeassistant.components.xbox.coordinator.config_entry_oauth2_flow.async_get_config_entry_implementation", side_effect=ValueError("Implementation not available"), ): await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.SETUP_RETRY