"""Freedompro component tests."""
import logging
from unittest.mock import patch

from homeassistant.components.freedompro.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState

from tests.common import MockConfigEntry

LOGGER = logging.getLogger(__name__)

ENTITY_ID = f"{DOMAIN}.fake_name"


async def test_async_setup_entry(hass, init_integration):
    """Test a successful setup entry."""
    entry = init_integration
    assert entry is not None
    state = hass.states
    assert state is not None


async def test_config_not_ready(hass):
    """Test for setup failure if connection to Freedompro is missing."""
    entry = MockConfigEntry(
        domain=DOMAIN,
        title="Feedompro",
        unique_id="0123456",
        data={
            "api_key": "<KEY>",
        },
    )

    with patch(
        "homeassistant.components.freedompro.get_list",
        return_value={
            "state": False,
        },
    ):
        entry.add_to_hass(hass)
        await hass.config_entries.async_setup(entry.entry_id)
        assert entry.state == ConfigEntryState.SETUP_RETRY


async def test_unload_entry(hass, init_integration):
    """Test successful unload of entry."""
    entry = init_integration

    assert len(hass.config_entries.async_entries(DOMAIN)) == 1
    assert entry.state == ConfigEntryState.LOADED

    assert await hass.config_entries.async_unload(entry.entry_id)
    await hass.async_block_till_done()

    assert entry.state == ConfigEntryState.NOT_LOADED

"""Freedompro component tests."""
import logging
from unittest.mock import patch

from homeassistant.components.freedompro.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState

from tests.common import MockConfigEntry

LOGGER = logging.getLogger(__name__)

ENTITY_ID = f"{DOMAIN}.fake_name"


async def test_async_setup_entry(hass, init_integration):
    """Test a successful setup entry."""
    entry = init_integration
    assert entry is not None
    state = hass.states
    assert state is not None


async def test_config_not_ready(hass):
    """Test for setup failure if connection to Freedompro is missing."""
    entry = MockConfigEntry(
        domain=DOMAIN,
        title="Feedompro",
        unique_id="0123456",
        data={
            "api_key": "<KEY>",
        },
    )

    with patch(
        "homeassistant.components.freedompro.get_list",
        return_value={
            "state": False,
        },
    ):
        entry.add_to_hass(hass)
        await hass.config_entries.async_setup(entry.entry_id)
        assert entry.state == ConfigEntryState.SETUP_RETRY


async def test_unload_entry(hass, init_integration):
    """Test successful unload of entry."""
    entry = init_integration

    assert len(hass.config_entries.async_entries(DOMAIN)) == 1
    assert entry.state == ConfigEntryState.LOADED

    assert await hass.config_entries.async_unload(entry.entry_id)
    await hass.async_block_till_done()

    assert entry.state == ConfigEntryState.NOT_LOADED

Freedompro component tests. Test a successful setup entry. Test for setup failure if connection to Freedompro is missing. Test successful unload of entry.