Get Litter-Robot to 100% code coverage and minor code cleanup (#58704)

This commit is contained in:
Nathan Spencer 2021-10-30 08:13:03 -06:00 committed by GitHub
parent bbbbcfbb93
commit aacc009cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 18 deletions

View file

@ -23,14 +23,14 @@ async def async_setup_entry(
"""Set up Litter-Robot selects using config entry.""" """Set up Litter-Robot selects using config entry."""
hub: LitterRobotHub = hass.data[DOMAIN][config_entry.entry_id] hub: LitterRobotHub = hass.data[DOMAIN][config_entry.entry_id]
entities = [ async_add_entities(
LitterRobotSelect( [
robot=robot, entity_type=TYPE_CLEAN_CYCLE_WAIT_TIME_MINUTES, hub=hub LitterRobotSelect(
) robot=robot, entity_type=TYPE_CLEAN_CYCLE_WAIT_TIME_MINUTES, hub=hub
for robot in hub.account.robots )
] for robot in hub.account.robots
]
async_add_entities(entities) )
class LitterRobotSelect(LitterRobotControlEntity, SelectEntity): class LitterRobotSelect(LitterRobotControlEntity, SelectEntity):

View file

@ -98,4 +98,4 @@ async def async_setup_entry(
) )
) )
async_add_entities(entities, True) async_add_entities(entities)

View file

@ -76,4 +76,4 @@ async def async_setup_entry(
for switch_class, switch_type in ROBOT_SWITCHES: for switch_class, switch_type in ROBOT_SWITCHES:
entities.append(switch_class(robot=robot, entity_type=switch_type, hub=hub)) entities.append(switch_class(robot=robot, entity_type=switch_type, hub=hub))
async_add_entities(entities, True) async_add_entities(entities)

View file

@ -17,7 +17,7 @@ from homeassistant.components.vacuum import (
SUPPORT_STATUS, SUPPORT_STATUS,
SUPPORT_TURN_OFF, SUPPORT_TURN_OFF,
SUPPORT_TURN_ON, SUPPORT_TURN_ON,
StateVacuumEntity, VacuumEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF from homeassistant.const import STATE_OFF
@ -47,13 +47,12 @@ async def async_setup_entry(
"""Set up Litter-Robot cleaner using config entry.""" """Set up Litter-Robot cleaner using config entry."""
hub: LitterRobotHub = hass.data[DOMAIN][entry.entry_id] hub: LitterRobotHub = hass.data[DOMAIN][entry.entry_id]
entities = [] async_add_entities(
for robot in hub.account.robots: [
entities.append(
LitterRobotCleaner(robot=robot, entity_type=TYPE_LITTER_BOX, hub=hub) LitterRobotCleaner(robot=robot, entity_type=TYPE_LITTER_BOX, hub=hub)
) for robot in hub.account.robots
]
async_add_entities(entities, True) )
platform = entity_platform.async_get_current_platform() platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service( platform.async_register_entity_service(
@ -76,7 +75,7 @@ async def async_setup_entry(
) )
class LitterRobotCleaner(LitterRobotControlEntity, StateVacuumEntity): class LitterRobotCleaner(LitterRobotControlEntity, VacuumEntity):
"""Litter-Robot "Vacuum" Cleaner.""" """Litter-Robot "Vacuum" Cleaner."""
@property @property

View file

@ -59,6 +59,12 @@ def mock_account_with_no_robots() -> MagicMock:
return create_mock_account(skip_robots=True) return create_mock_account(skip_robots=True)
@pytest.fixture
def mock_account_with_sleeping_robot() -> MagicMock:
"""Mock a Litter-Robot account with a sleeping robot."""
return create_mock_account({"sleepModeActive": "102:00:00"})
@pytest.fixture @pytest.fixture
def mock_account_with_error() -> MagicMock: def mock_account_with_error() -> MagicMock:
"""Mock a Litter-Robot account with error.""" """Mock a Litter-Robot account with error."""

View file

@ -12,6 +12,7 @@ from homeassistant.components.litterrobot.vacuum import (
SERVICE_SET_WAIT_TIME, SERVICE_SET_WAIT_TIME,
) )
from homeassistant.components.vacuum import ( from homeassistant.components.vacuum import (
ATTR_STATUS,
DOMAIN as PLATFORM_DOMAIN, DOMAIN as PLATFORM_DOMAIN,
SERVICE_START, SERVICE_START,
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
@ -46,6 +47,17 @@ async def test_vacuum(hass: HomeAssistant, mock_account):
assert vacuum.attributes["is_sleeping"] is False assert vacuum.attributes["is_sleeping"] is False
async def test_vacuum_status_when_sleeping(
hass: HomeAssistant, mock_account_with_sleeping_robot
):
"""Tests the vacuum status when sleeping."""
await setup_integration(hass, mock_account_with_sleeping_robot, PLATFORM_DOMAIN)
vacuum = hass.states.get(VACUUM_ENTITY_ID)
assert vacuum
assert vacuum.attributes.get(ATTR_STATUS) == "Ready (Sleeping)"
async def test_no_robots(hass: HomeAssistant, mock_account_with_no_robots): async def test_no_robots(hass: HomeAssistant, mock_account_with_no_robots):
"""Tests the vacuum entity was set up.""" """Tests the vacuum entity was set up."""
await setup_integration(hass, mock_account_with_no_robots, PLATFORM_DOMAIN) await setup_integration(hass, mock_account_with_no_robots, PLATFORM_DOMAIN)