2023-07-25 11:29:48 +00:00
|
|
|
"""Test Roborock Time platform."""
|
2024-03-08 13:47:22 +00:00
|
|
|
|
2023-07-25 11:29:48 +00:00
|
|
|
from datetime import time
|
2025-01-28 09:54:36 +00:00
|
|
|
from unittest.mock import Mock
|
2023-07-25 11:29:48 +00:00
|
|
|
|
|
|
|
import pytest
|
2024-09-24 20:38:40 +00:00
|
|
|
import roborock
|
2023-07-25 11:29:48 +00:00
|
|
|
|
|
|
|
from homeassistant.components.time import SERVICE_SET_VALUE
|
2025-01-07 13:08:12 +00:00
|
|
|
from homeassistant.const import Platform
|
2023-07-25 11:29:48 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2024-09-24 20:38:40 +00:00
|
|
|
from homeassistant.exceptions import HomeAssistantError
|
2023-07-25 11:29:48 +00:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
2025-01-07 13:08:12 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def platforms() -> list[Platform]:
|
|
|
|
"""Fixture to set platforms used in the test."""
|
|
|
|
return [Platform.TIME]
|
|
|
|
|
|
|
|
|
2023-07-25 11:29:48 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("entity_id"),
|
|
|
|
[
|
|
|
|
("time.roborock_s7_maxv_do_not_disturb_begin"),
|
|
|
|
("time.roborock_s7_maxv_do_not_disturb_end"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_update_success(
|
|
|
|
hass: HomeAssistant,
|
2025-01-28 09:54:36 +00:00
|
|
|
mock_send_message: Mock,
|
2023-07-25 11:29:48 +00:00
|
|
|
bypass_api_fixture,
|
|
|
|
setup_entry: MockConfigEntry,
|
|
|
|
entity_id: str,
|
|
|
|
) -> None:
|
|
|
|
"""Test turning switch entities on and off."""
|
|
|
|
# Ensure that the entity exist, as these test can pass even if there is no entity.
|
|
|
|
assert hass.states.get(entity_id) is not None
|
2025-01-28 09:54:36 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
"time",
|
|
|
|
SERVICE_SET_VALUE,
|
|
|
|
service_data={"time": time(hour=1, minute=1)},
|
|
|
|
blocking=True,
|
|
|
|
target={"entity_id": entity_id},
|
|
|
|
)
|
2023-07-25 11:29:48 +00:00
|
|
|
assert mock_send_message.assert_called_once
|
2024-09-24 20:38:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("entity_id"),
|
|
|
|
[
|
|
|
|
("time.roborock_s7_maxv_do_not_disturb_begin"),
|
|
|
|
],
|
|
|
|
)
|
2025-01-28 09:54:36 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"send_message_side_effect", [roborock.exceptions.RoborockTimeout]
|
|
|
|
)
|
2024-09-24 20:38:40 +00:00
|
|
|
async def test_update_failure(
|
|
|
|
hass: HomeAssistant,
|
2025-01-28 09:54:36 +00:00
|
|
|
mock_send_message: Mock,
|
2024-09-24 20:38:40 +00:00
|
|
|
bypass_api_fixture,
|
|
|
|
setup_entry: MockConfigEntry,
|
|
|
|
entity_id: str,
|
|
|
|
) -> None:
|
|
|
|
"""Test turning switch entities on and off."""
|
|
|
|
# Ensure that the entity exist, as these test can pass even if there is no entity.
|
|
|
|
assert hass.states.get(entity_id) is not None
|
2025-01-28 09:54:36 +00:00
|
|
|
with pytest.raises(HomeAssistantError, match="Failed to update Roborock options"):
|
2024-09-24 20:38:40 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
"time",
|
|
|
|
SERVICE_SET_VALUE,
|
|
|
|
service_data={"time": time(hour=1, minute=1)},
|
|
|
|
blocking=True,
|
|
|
|
target={"entity_id": entity_id},
|
|
|
|
)
|
|
|
|
assert mock_send_message.assert_called_once
|