mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add full test coverage for Comelit cover (#144761)
This commit is contained in:
parent
7c5090d627
commit
e64f76bebe
@ -7,7 +7,7 @@ from typing import Any, cast
|
|||||||
from aiocomelit import ComelitSerialBridgeObject
|
from aiocomelit import ComelitSerialBridgeObject
|
||||||
from aiocomelit.const import COVER, STATE_COVER, STATE_OFF, STATE_ON
|
from aiocomelit.const import COVER, STATE_COVER, STATE_OFF, STATE_ON
|
||||||
|
|
||||||
from homeassistant.components.cover import CoverDeviceClass, CoverEntity, CoverState
|
from homeassistant.components.cover import CoverDeviceClass, CoverEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
@ -68,16 +68,10 @@ class ComelitCoverEntity(ComelitBridgeBaseEntity, RestoreEntity, CoverEntity):
|
|||||||
def is_closed(self) -> bool | None:
|
def is_closed(self) -> bool | None:
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
|
|
||||||
if self._last_state in [None, "unknown"]:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if self.device_status != STATE_COVER.index("stopped"):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if self._last_action:
|
if self._last_action:
|
||||||
return self._last_action == STATE_COVER.index("closing")
|
return self._last_action == STATE_COVER.index("closing")
|
||||||
|
|
||||||
return self._last_state == CoverState.CLOSED
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closing(self) -> bool:
|
def is_closing(self) -> bool:
|
||||||
|
@ -15,6 +15,7 @@ from homeassistant.components.cover import (
|
|||||||
SERVICE_STOP_COVER,
|
SERVICE_STOP_COVER,
|
||||||
STATE_CLOSED,
|
STATE_CLOSED,
|
||||||
STATE_CLOSING,
|
STATE_CLOSING,
|
||||||
|
STATE_OPEN,
|
||||||
STATE_OPENING,
|
STATE_OPENING,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
|
||||||
@ -94,7 +95,7 @@ async def test_cover_open(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert (state := hass.states.get(ENTITY_ID))
|
assert (state := hass.states.get(ENTITY_ID))
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_OPEN
|
||||||
|
|
||||||
|
|
||||||
async def test_cover_close(
|
async def test_cover_close(
|
||||||
@ -159,3 +160,36 @@ async def test_cover_stop_if_stopped(
|
|||||||
|
|
||||||
assert (state := hass.states.get(ENTITY_ID))
|
assert (state := hass.states.get(ENTITY_ID))
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cover_restore_state(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
mock_serial_bridge: AsyncMock,
|
||||||
|
mock_serial_bridge_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test cover restore state on reload."""
|
||||||
|
|
||||||
|
mock_serial_bridge.reset_mock()
|
||||||
|
await setup_integration(hass, mock_serial_bridge_config_entry)
|
||||||
|
|
||||||
|
assert (state := hass.states.get(ENTITY_ID))
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
# Open cover
|
||||||
|
await hass.services.async_call(
|
||||||
|
COVER_DOMAIN,
|
||||||
|
SERVICE_OPEN_COVER,
|
||||||
|
{ATTR_ENTITY_ID: ENTITY_ID},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
mock_serial_bridge.set_device_status.assert_called()
|
||||||
|
|
||||||
|
assert (state := hass.states.get(ENTITY_ID))
|
||||||
|
assert state.state == STATE_OPENING
|
||||||
|
|
||||||
|
await hass.config_entries.async_reload(mock_serial_bridge_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert (state := hass.states.get(ENTITY_ID))
|
||||||
|
assert state.state == STATE_OPENING
|
||||||
|
Loading…
x
Reference in New Issue
Block a user