"""Test AdGuard Control Hub initialization.""" from unittest.mock import patch, AsyncMock import pytest from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.core import HomeAssistant from custom_components.adguard_control_hub.const import DOMAIN @pytest.mark.asyncio async def test_setup_entry(hass: HomeAssistant, mock_config_entry_data, mock_adguard_api) -> None: """Test successful setup of entry.""" with patch( "custom_components.adguard_control_hub.AdGuardHomeAPI" ) as mock_api_class: mock_api_class.return_value = mock_adguard_api # Create a mock config entry from homeassistant.config_entries import ConfigEntry entry = ConfigEntry( version=1, minor_version=1, domain=DOMAIN, title="Test AdGuard", data=mock_config_entry_data, options={}, source="test", unique_id="test_unique_id", ) # Add entry to hass hass.config_entries._entries[entry.entry_id] = entry with patch("custom_components.adguard_control_hub.PLATFORMS", []): result = await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert result is True assert DOMAIN in hass.data @pytest.mark.asyncio async def test_unload_entry(hass: HomeAssistant, mock_config_entry_data, mock_adguard_api) -> None: """Test successful unload of entry.""" with patch( "custom_components.adguard_control_hub.AdGuardHomeAPI" ) as mock_api_class: mock_api_class.return_value = mock_adguard_api # Create a mock config entry from homeassistant.config_entries import ConfigEntry entry = ConfigEntry( version=1, minor_version=1, domain=DOMAIN, title="Test AdGuard", data=mock_config_entry_data, options={}, source="test", unique_id="test_unique_id", ) # Add entry to hass hass.config_entries._entries[entry.entry_id] = entry with patch("custom_components.adguard_control_hub.PLATFORMS", []): # Setup first await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert DOMAIN in hass.data # Then unload result = await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert result is True