2021-02-17 05:37:56 +00:00
|
|
|
"""Common fixtures for smarttub tests."""
|
|
|
|
|
|
|
|
from unittest.mock import create_autospec, patch
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import smarttub
|
|
|
|
|
|
|
|
from homeassistant.components.smarttub.const import DOMAIN
|
|
|
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
2021-02-19 00:18:02 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2021-02-17 05:37:56 +00:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def config_data():
|
|
|
|
"""Provide configuration data for tests."""
|
|
|
|
return {CONF_EMAIL: "test-email", CONF_PASSWORD: "test-password"}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def config_entry(config_data):
|
|
|
|
"""Create a mock config entry."""
|
|
|
|
return MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=config_data,
|
|
|
|
options={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-02-19 00:18:02 +00:00
|
|
|
@pytest.fixture
|
|
|
|
async def setup_component(hass):
|
|
|
|
"""Set up the component."""
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {}) is True
|
|
|
|
|
|
|
|
|
2021-02-17 05:37:56 +00:00
|
|
|
@pytest.fixture(name="spa")
|
|
|
|
def mock_spa():
|
|
|
|
"""Mock a SmartTub.Spa."""
|
|
|
|
|
|
|
|
mock_spa = create_autospec(smarttub.Spa, instance=True)
|
|
|
|
mock_spa.id = "mockspa1"
|
|
|
|
mock_spa.brand = "mockbrand1"
|
|
|
|
mock_spa.model = "mockmodel1"
|
|
|
|
mock_spa.get_status.return_value = {
|
|
|
|
"setTemperature": 39,
|
|
|
|
"water": {"temperature": 38},
|
|
|
|
"heater": "ON",
|
2021-02-22 04:46:54 +00:00
|
|
|
"heatMode": "AUTO",
|
2021-02-20 22:25:02 +00:00
|
|
|
"state": "NORMAL",
|
2021-02-22 03:40:23 +00:00
|
|
|
"primaryFiltration": {
|
|
|
|
"cycle": 1,
|
|
|
|
"duration": 4,
|
|
|
|
"lastUpdated": "2021-01-20T11:38:57.014Z",
|
|
|
|
"mode": "NORMAL",
|
|
|
|
"startHour": 2,
|
|
|
|
"status": "INACTIVE",
|
|
|
|
},
|
|
|
|
"secondaryFiltration": {
|
|
|
|
"lastUpdated": "2020-07-09T19:39:52.961Z",
|
|
|
|
"mode": "AWAY",
|
|
|
|
"status": "INACTIVE",
|
|
|
|
},
|
|
|
|
"flowSwitch": "OPEN",
|
|
|
|
"ozone": "OFF",
|
|
|
|
"uv": "OFF",
|
|
|
|
"blowoutCycle": "INACTIVE",
|
|
|
|
"cleanupCycle": "INACTIVE",
|
2021-02-17 05:37:56 +00:00
|
|
|
}
|
|
|
|
return mock_spa
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="account")
|
|
|
|
def mock_account(spa):
|
|
|
|
"""Mock a SmartTub.Account."""
|
|
|
|
|
|
|
|
mock_account = create_autospec(smarttub.Account, instance=True)
|
|
|
|
mock_account.id = "mockaccount1"
|
|
|
|
mock_account.get_spas.return_value = [spa]
|
|
|
|
return mock_account
|
|
|
|
|
|
|
|
|
2021-02-20 22:25:02 +00:00
|
|
|
@pytest.fixture(name="smarttub_api", autouse=True)
|
2021-02-17 05:37:56 +00:00
|
|
|
def mock_api(account, spa):
|
|
|
|
"""Mock the SmartTub API."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.smarttub.controller.SmartTub",
|
|
|
|
autospec=True,
|
|
|
|
) as api_class_mock:
|
|
|
|
api_mock = api_class_mock.return_value
|
|
|
|
api_mock.get_account.return_value = account
|
|
|
|
yield api_mock
|
2021-02-20 22:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
async def setup_entry(hass, config_entry):
|
|
|
|
"""Initialize the config entry."""
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|