|
| 1 | +"""Tests for the Velux cover platform.""" |
| 2 | + |
| 3 | +from unittest.mock import AsyncMock, patch |
| 4 | + |
| 5 | +from freezegun.api import FrozenDateTimeFactory |
| 6 | +import pytest |
| 7 | + |
| 8 | +from homeassistant.const import STATE_CLOSED, STATE_OPEN, Platform |
| 9 | +from homeassistant.core import HomeAssistant |
| 10 | + |
| 11 | +from . import update_callback_entity |
| 12 | + |
| 13 | +from tests.common import MockConfigEntry |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.usefixtures("mock_module") |
| 17 | +async def test_cover_closed( |
| 18 | + hass: HomeAssistant, |
| 19 | + mock_window: AsyncMock, |
| 20 | + mock_config_entry: MockConfigEntry, |
| 21 | + freezer: FrozenDateTimeFactory, |
| 22 | +) -> None: |
| 23 | + """Test the cover closed state.""" |
| 24 | + |
| 25 | + mock_config_entry.add_to_hass(hass) |
| 26 | + with patch("homeassistant.components.velux.PLATFORMS", [Platform.COVER]): |
| 27 | + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) |
| 28 | + await hass.async_block_till_done() |
| 29 | + |
| 30 | + test_entity_id = "cover.test_window" |
| 31 | + |
| 32 | + # Initial state should be open |
| 33 | + state = hass.states.get(test_entity_id) |
| 34 | + assert state is not None |
| 35 | + assert state.state == STATE_OPEN |
| 36 | + |
| 37 | + # Update mock window position to closed percentage |
| 38 | + mock_window.position.position_percent = 100 |
| 39 | + # Also directly set position to closed, so this test should |
| 40 | + # continue to be green after the lib is fixed |
| 41 | + mock_window.position.closed = True |
| 42 | + |
| 43 | + # Trigger entity state update via registered callback |
| 44 | + await update_callback_entity(hass, mock_window) |
| 45 | + |
| 46 | + state = hass.states.get(test_entity_id) |
| 47 | + assert state is not None |
| 48 | + assert state.state == STATE_CLOSED |
0 commit comments