core/tests/components/dyson/conftest.py

47 lines
1.5 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
from homeassistant.components.dyson import CONF_LANGUAGE, DOMAIN
from homeassistant.const import CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from .common import SERIAL
from tests.common import async_setup_component
BASE_PATH = "homeassistant.components.dyson"
@pytest.fixture
async def device(hass: HomeAssistant, request) -> DysonDevice:
"""Fixture to provide Dyson 360 Eye device."""
device = request.module.get_device()
platform = request.module.PLATFORM_DOMAIN
with patch(f"{BASE_PATH}.DysonAccount.login", return_value=True), patch(
f"{BASE_PATH}.DysonAccount.devices", return_value=[device]
), patch(f"{BASE_PATH}.DYSON_PLATFORMS", [platform]):
# DYSON_PLATFORMS is patched so that only the platform being tested is set up
await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_USERNAME: "user@example.com",
CONF_PASSWORD: "password",
CONF_LANGUAGE: "US",
CONF_DEVICES: [
{
"device_id": SERIAL,
"device_ip": "0.0.0.0",
}
],
}
},
)
await hass.async_block_till_done()
return device