2021-02-22 11:53:57 -07:00
|
|
|
"""Configure pytest for Litter-Robot tests."""
|
2021-02-23 19:34:25 -07:00
|
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
2021-02-22 11:53:57 -07:00
|
|
|
|
|
|
|
from pylitterbot import Robot
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.components import litterrobot
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|
|
|
|
2021-02-23 19:34:25 -07:00
|
|
|
from .common import CONFIG, ROBOT_DATA
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
2021-02-22 11:53:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
def create_mock_robot(hass):
|
|
|
|
"""Create a mock Litter-Robot device."""
|
|
|
|
robot = Robot(data=ROBOT_DATA)
|
|
|
|
robot.start_cleaning = AsyncMock()
|
|
|
|
robot.set_power_status = AsyncMock()
|
|
|
|
robot.reset_waste_drawer = AsyncMock()
|
|
|
|
robot.set_sleep_mode = AsyncMock()
|
2021-02-23 19:34:25 -07:00
|
|
|
robot.set_night_light = AsyncMock()
|
|
|
|
robot.set_panel_lockout = AsyncMock()
|
2021-02-22 11:53:57 -07:00
|
|
|
return robot
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def mock_hub(hass):
|
|
|
|
"""Mock a Litter-Robot hub."""
|
|
|
|
hub = MagicMock(
|
|
|
|
hass=hass,
|
|
|
|
account=MagicMock(),
|
|
|
|
logged_in=True,
|
|
|
|
coordinator=MagicMock(spec=DataUpdateCoordinator),
|
|
|
|
spec=litterrobot.LitterRobotHub,
|
|
|
|
)
|
|
|
|
hub.coordinator.last_update_success = True
|
|
|
|
hub.account.robots = [create_mock_robot(hass)]
|
|
|
|
return hub
|
2021-02-23 19:34:25 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def setup_hub(hass, mock_hub, platform_domain):
|
|
|
|
"""Load a Litter-Robot platform with the provided hub."""
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=litterrobot.DOMAIN,
|
|
|
|
data=CONFIG[litterrobot.DOMAIN],
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.litterrobot.LitterRobotHub",
|
|
|
|
return_value=mock_hub,
|
|
|
|
):
|
|
|
|
await hass.config_entries.async_forward_entry_setup(entry, platform_domain)
|
|
|
|
await hass.async_block_till_done()
|