core/tests/components/dyson/conftest.py

39 lines
1.2 KiB
Python
Raw Normal View History

2021-01-18 14:56:54 +00:00
"""Configure pytest for Dyson tests."""
from unittest.mock import patch
from libpurecool.dyson_device import DysonDevice
import pytest
2021-01-21 18:43:52 +00:00
from homeassistant.components.dyson import DOMAIN
2021-01-18 14:56:54 +00:00
from homeassistant.core import HomeAssistant
2021-01-21 18:43:52 +00:00
from .common import BASE_PATH, CONFIG
2021-01-18 14:56:54 +00:00
from tests.common import async_setup_component
@pytest.fixture()
2021-01-18 14:56:54 +00:00
async def device(hass: HomeAssistant, request) -> DysonDevice:
"""Fixture to provide Dyson 360 Eye device."""
platform = request.module.PLATFORM_DOMAIN
2021-01-22 15:27:43 +00:00
get_device = request.module.async_get_device
if hasattr(request, "param"):
2021-01-21 18:43:52 +00:00
if isinstance(request.param, list):
device = get_device(*request.param)
else:
device = get_device(request.param)
else:
device = get_device()
2021-01-18 14:56:54 +00:00
with patch(f"{BASE_PATH}.DysonAccount.login", return_value=True), patch(
f"{BASE_PATH}.DysonAccount.devices", return_value=[device]
), patch(f"{BASE_PATH}.PLATFORMS", [platform]):
# PLATFORMS is patched so that only the platform being tested is set up
2021-01-18 14:56:54 +00:00
await async_setup_component(
hass,
DOMAIN,
2021-01-21 18:43:52 +00:00
CONFIG,
2021-01-18 14:56:54 +00:00
)
await hass.async_block_till_done()
return device