mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fix for invalid value error when using UI editor for Litter-Robot's set_wait_time service (#50269)
This commit is contained in:
parent
6a2d6e2046
commit
9ec0b0a8da
@ -69,7 +69,8 @@ class LitterRobotControlEntity(LitterRobotEntity):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await action(*args, **kwargs)
|
await action(*args, **kwargs)
|
||||||
except InvalidCommandException as ex:
|
except InvalidCommandException as ex: # pragma: no cover
|
||||||
|
# this exception should only occur if the underlying API for commands changes
|
||||||
_LOGGER.error(ex)
|
_LOGGER.error(ex)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
SERVICE_SET_WAIT_TIME,
|
SERVICE_SET_WAIT_TIME,
|
||||||
{vol.Required("minutes"): vol.In(VALID_WAIT_TIMES)},
|
{vol.Required("minutes"): vol.All(vol.Coerce(int), vol.In(VALID_WAIT_TIMES))},
|
||||||
"async_set_wait_time",
|
"async_set_wait_time",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from voluptuous.error import MultipleInvalid
|
||||||
|
|
||||||
from homeassistant.components.litterrobot import DOMAIN
|
from homeassistant.components.litterrobot import DOMAIN
|
||||||
from homeassistant.components.litterrobot.entity import REFRESH_WAIT_TIME_SECONDS
|
from homeassistant.components.litterrobot.entity import REFRESH_WAIT_TIME_SECONDS
|
||||||
@ -92,6 +93,11 @@ async def test_vacuum_with_error(hass: HomeAssistant, mock_account_with_error):
|
|||||||
"set_wait_time",
|
"set_wait_time",
|
||||||
{"minutes": 3},
|
{"minutes": 3},
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
SERVICE_SET_WAIT_TIME,
|
||||||
|
"set_wait_time",
|
||||||
|
{"minutes": "15"},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_commands(hass: HomeAssistant, mock_account, service, command, extra):
|
async def test_commands(hass: HomeAssistant, mock_account, service, command, extra):
|
||||||
@ -117,21 +123,19 @@ async def test_commands(hass: HomeAssistant, mock_account, service, command, ext
|
|||||||
getattr(mock_account.robots[0], command).assert_called_once()
|
getattr(mock_account.robots[0], command).assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_commands(
|
async def test_invalid_wait_time(hass: HomeAssistant, mock_account):
|
||||||
hass: HomeAssistant, caplog, mock_account_with_side_effects
|
"""Test an attempt to send an invalid wait time to the vacuum."""
|
||||||
):
|
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
||||||
"""Test sending invalid commands to the vacuum."""
|
|
||||||
await setup_integration(hass, mock_account_with_side_effects, PLATFORM_DOMAIN)
|
|
||||||
|
|
||||||
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
||||||
assert vacuum
|
assert vacuum
|
||||||
assert vacuum.state == STATE_DOCKED
|
assert vacuum.state == STATE_DOCKED
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(MultipleInvalid):
|
||||||
DOMAIN,
|
await hass.services.async_call(
|
||||||
SERVICE_SET_WAIT_TIME,
|
DOMAIN,
|
||||||
{ATTR_ENTITY_ID: VACUUM_ENTITY_ID, "minutes": 15},
|
SERVICE_SET_WAIT_TIME,
|
||||||
blocking=True,
|
{ATTR_ENTITY_ID: VACUUM_ENTITY_ID, "minutes": 10},
|
||||||
)
|
blocking=True,
|
||||||
mock_account_with_side_effects.robots[0].set_wait_time.assert_called_once()
|
)
|
||||||
assert "Invalid command: oops" in caplog.text
|
assert not mock_account.robots[0].set_wait_time.called
|
||||||
|
Loading…
x
Reference in New Issue
Block a user