core/tests/components/wled/conftest.py

79 lines
2.3 KiB
Python
Raw Normal View History

"""Fixtures for WLED integration tests."""
from collections.abc import Generator
2022-06-22 20:37:36 +00:00
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from wled import Device as WLEDDevice
from homeassistant.components.wled.const import DOMAIN
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
2023-02-20 12:00:02 +00:00
from tests.common import MockConfigEntry, load_json_object_fixture
from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: "192.168.1.123"},
unique_id="aabbccddeeff",
)
@pytest.fixture
2023-02-20 12:00:02 +00:00
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Mock setting up a config entry."""
2022-06-22 20:37:36 +00:00
with patch(
"homeassistant.components.wled.async_setup_entry", return_value=True
) as mock_setup:
yield mock_setup
@pytest.fixture
2023-02-20 12:00:02 +00:00
def mock_onboarding() -> Generator[MagicMock, None, None]:
2022-06-22 20:37:36 +00:00
"""Mock that Home Assistant is currently onboarding."""
with patch(
"homeassistant.components.onboarding.async_is_onboarded",
return_value=False,
) as mock_onboarding:
yield mock_onboarding
@pytest.fixture
2023-02-20 12:00:02 +00:00
def device_fixture() -> str:
"""Return the device fixture for a specific device."""
return "rgb"
@pytest.fixture
2023-02-20 12:00:02 +00:00
def mock_wled(device_fixture: str) -> Generator[MagicMock, None, None]:
"""Return a mocked WLED client."""
with patch(
"homeassistant.components.wled.coordinator.WLED", autospec=True
2023-02-20 12:00:02 +00:00
) as wled_mock, patch(
"homeassistant.components.wled.config_flow.WLED", new=wled_mock
):
wled = wled_mock.return_value
2023-02-20 12:00:02 +00:00
wled.update.return_value = WLEDDevice(
load_json_object_fixture(f"{device_fixture}.json", DOMAIN)
)
wled.connected = False
wled.host = "127.0.0.1"
yield wled
@pytest.fixture
async def init_integration(
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_wled: MagicMock
) -> MockConfigEntry:
"""Set up the WLED integration for testing."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
return mock_config_entry