Add the ability to resume cleaning on start button (#112122)
This commit is contained in:
parent
409dc02d36
commit
74f1420410
2 changed files with 51 additions and 1 deletions
|
@ -121,7 +121,12 @@ class RoborockVacuum(RoborockCoordinatedEntity, StateVacuumEntity):
|
|||
|
||||
async def async_start(self) -> None:
|
||||
"""Start the vacuum."""
|
||||
await self.send(RoborockCommand.APP_START)
|
||||
if self._device_status.in_cleaning == 2:
|
||||
await self.send(RoborockCommand.RESUME_ZONED_CLEAN)
|
||||
elif self._device_status.in_cleaning == 3:
|
||||
await self.send(RoborockCommand.RESUME_SEGMENT_CLEAN)
|
||||
else:
|
||||
await self.send(RoborockCommand.APP_START)
|
||||
|
||||
async def async_pause(self) -> None:
|
||||
"""Pause the vacuum."""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for Roborock vacuums."""
|
||||
|
||||
|
||||
import copy
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -8,6 +9,7 @@ import pytest
|
|||
from roborock import RoborockException
|
||||
from roborock.roborock_typing import RoborockCommand
|
||||
|
||||
from homeassistant.components.roborock import DOMAIN
|
||||
from homeassistant.components.vacuum import (
|
||||
SERVICE_CLEAN_SPOT,
|
||||
SERVICE_LOCATE,
|
||||
|
@ -22,8 +24,10 @@ from homeassistant.const import ATTR_ENTITY_ID, Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.roborock.mock_data import PROP
|
||||
|
||||
ENTITY_ID = "vacuum.roborock_s7_maxv"
|
||||
DEVICE_ID = "abc123"
|
||||
|
@ -90,6 +94,47 @@ async def test_commands(
|
|||
assert mock_send_command.call_args[0][1] == called_params
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("in_cleaning_int", "expected_command"),
|
||||
[
|
||||
(0, RoborockCommand.APP_START),
|
||||
(1, RoborockCommand.APP_START),
|
||||
(2, RoborockCommand.RESUME_ZONED_CLEAN),
|
||||
(3, RoborockCommand.RESUME_SEGMENT_CLEAN),
|
||||
],
|
||||
)
|
||||
async def test_resume_cleaning(
|
||||
hass: HomeAssistant,
|
||||
bypass_api_fixture,
|
||||
mock_roborock_entry: MockConfigEntry,
|
||||
in_cleaning_int: int,
|
||||
expected_command: RoborockCommand,
|
||||
) -> None:
|
||||
"""Test resuming clean on start button when a clean is paused."""
|
||||
prop = copy.deepcopy(PROP)
|
||||
prop.status.in_cleaning = in_cleaning_int
|
||||
with patch(
|
||||
"homeassistant.components.roborock.coordinator.RoborockLocalClient.get_prop",
|
||||
return_value=prop,
|
||||
):
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
vacuum = hass.states.get(ENTITY_ID)
|
||||
assert vacuum
|
||||
|
||||
data = {ATTR_ENTITY_ID: ENTITY_ID}
|
||||
with patch(
|
||||
"homeassistant.components.roborock.coordinator.RoborockLocalClient.send_command"
|
||||
) as mock_send_command:
|
||||
await hass.services.async_call(
|
||||
Platform.VACUUM,
|
||||
SERVICE_START,
|
||||
data,
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_send_command.call_count == 1
|
||||
assert mock_send_command.call_args[0][0] == expected_command
|
||||
|
||||
|
||||
async def test_failed_user_command(
|
||||
hass: HomeAssistant,
|
||||
bypass_api_fixture,
|
||||
|
|
Loading…
Add table
Reference in a new issue