mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 22:38:02 -04:00
Skip real-time transitions in Snooz tests (#183691)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
"""Test Snooz fan entity."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, PropertyMock, patch
|
||||
|
||||
from pysnooz import SnoozDeviceState, UnknownSnoozState
|
||||
from pysnooz.commands import SnoozCommandResult, SnoozCommandResultStatus
|
||||
from pysnooz.commands import (
|
||||
SnoozCommandData,
|
||||
SnoozCommandResult,
|
||||
SnoozCommandResultStatus,
|
||||
turn_off,
|
||||
turn_on,
|
||||
)
|
||||
from pysnooz.testing import MockSnoozDevice
|
||||
import pytest
|
||||
|
||||
@@ -45,17 +53,53 @@ async def test_turn_on(hass: HomeAssistant, snooz_fan_entity_id: str) -> None:
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
|
||||
|
||||
async def test_transition_on(hass: HomeAssistant, snooz_fan_entity_id: str) -> None:
|
||||
"""Test transitioning on the device."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_ON,
|
||||
{ATTR_ENTITY_ID: [snooz_fan_entity_id], ATTR_DURATION: 1},
|
||||
blocking=True,
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("service", "command_name", "command", "expected_call", "expected_state"),
|
||||
[
|
||||
pytest.param(
|
||||
SERVICE_TRANSITION_ON,
|
||||
"turn_on",
|
||||
turn_on,
|
||||
{"volume": None, "duration": timedelta(seconds=1)},
|
||||
STATE_ON,
|
||||
id="on",
|
||||
),
|
||||
pytest.param(
|
||||
SERVICE_TRANSITION_OFF,
|
||||
"turn_off",
|
||||
turn_off,
|
||||
{"duration": timedelta(seconds=1)},
|
||||
STATE_OFF,
|
||||
id="off",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_transition(
|
||||
hass: HomeAssistant,
|
||||
snooz_fan_entity_id: str,
|
||||
service: str,
|
||||
command_name: str,
|
||||
command: Callable[..., SnoozCommandData],
|
||||
expected_call: dict[str, Any],
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test transitioning the device on and off."""
|
||||
# Zero duration makes pysnooz send a plain state write instead of a real-time transition
|
||||
with patch(
|
||||
f"homeassistant.components.snooz.fan.{command_name}",
|
||||
side_effect=lambda **kwargs: command(**kwargs | {"duration": None}),
|
||||
) as mock_command:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: [snooz_fan_entity_id], ATTR_DURATION: 1},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_command.assert_called_once_with(**expected_call)
|
||||
|
||||
state = hass.states.get(snooz_fan_entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.state == expected_state
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
|
||||
|
||||
@@ -133,20 +177,6 @@ async def test_turn_off(hass: HomeAssistant, snooz_fan_entity_id: str) -> None:
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
|
||||
|
||||
async def test_transition_off(hass: HomeAssistant, snooz_fan_entity_id: str) -> None:
|
||||
"""Test transitioning off the device."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_TRANSITION_OFF,
|
||||
{ATTR_ENTITY_ID: [snooz_fan_entity_id], ATTR_DURATION: 1},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get(snooz_fan_entity_id)
|
||||
assert state.state == STATE_OFF
|
||||
assert ATTR_ASSUMED_STATE not in state.attributes
|
||||
|
||||
|
||||
async def test_push_events(
|
||||
hass: HomeAssistant, mock_connected_snooz: SnoozFixture, snooz_fan_entity_id: str
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user