Adjust litterrobot tests and code to match guidelines (#47060)
* Use SwitchEntity instead of ToggleEntity and adjust test patches as recommended * Move async_create_entry out of try block in config_flow * Patch pypi package instead of HA code * Bump pylitterbot to 2021.2.6, fix tests, and implement other code review suggestions * Bump pylitterbot to 2021.2.8, remove sleep mode start/end time from vacuum, adjust and add sensors for sleep mode start/end time * Move icon helper back to Litter-Robot component and isoformat times on time sensors
This commit is contained in:
parent
14f85d8731
commit
e9052233a6
14 changed files with 277 additions and 142 deletions
|
@ -1,20 +1,48 @@
|
|||
"""Test Litter-Robot setup process."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import litterrobot
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.config_entries import (
|
||||
ENTRY_STATE_SETUP_ERROR,
|
||||
ENTRY_STATE_SETUP_RETRY,
|
||||
)
|
||||
|
||||
from .common import CONFIG
|
||||
from .conftest import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_unload_entry(hass):
|
||||
async def test_unload_entry(hass, mock_account):
|
||||
"""Test being able to unload an entry."""
|
||||
entry = await setup_integration(hass, mock_account)
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[litterrobot.DOMAIN] == {}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect,expected_state",
|
||||
(
|
||||
(LitterRobotLoginException, ENTRY_STATE_SETUP_ERROR),
|
||||
(LitterRobotException, ENTRY_STATE_SETUP_RETRY),
|
||||
),
|
||||
)
|
||||
async def test_entry_not_setup(hass, side_effect, expected_state):
|
||||
"""Test being able to handle config entry not setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await async_setup_component(hass, litterrobot.DOMAIN, {}) is True
|
||||
assert await litterrobot.async_unload_entry(hass, entry)
|
||||
assert hass.data[litterrobot.DOMAIN] == {}
|
||||
with patch(
|
||||
"pylitterbot.Account.connect",
|
||||
side_effect=side_effect,
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert entry.state == expected_state
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue