mirror of https://github.com/home-assistant/core
Raise error on open/close failure in Aladdin Connect (#99746)
Raise error on open/close failure
This commit is contained in:
parent
f24c4ceab6
commit
54d92b649b
|
@ -10,7 +10,7 @@ from homeassistant.components.cover import CoverDeviceClass, CoverEntity
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPENING
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.exceptions import HomeAssistantError, PlatformNotReady
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -75,11 +75,13 @@ class AladdinDevice(CoverEntity):
|
|||
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Issue close command to cover."""
|
||||
await self._acc.close_door(self._device_id, self._number)
|
||||
if not await self._acc.close_door(self._device_id, self._number):
|
||||
raise HomeAssistantError("Aladdin Connect API failed to close the cover")
|
||||
|
||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||
"""Issue open command to cover."""
|
||||
await self._acc.open_door(self._device_id, self._number)
|
||||
if not await self._acc.open_door(self._device_id, self._number):
|
||||
raise HomeAssistantError("Aladdin Connect API failed to open the cover")
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update status of cover."""
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from AIOAladdinConnect import session_manager
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.aladdin_connect.const import DOMAIN
|
||||
from homeassistant.components.aladdin_connect.cover import SCAN_INTERVAL
|
||||
|
@ -19,6 +20,7 @@ from homeassistant.const import (
|
|||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
|
@ -123,6 +125,17 @@ async def test_cover_operation(
|
|||
)
|
||||
assert hass.states.get("cover.home").state == STATE_OPEN
|
||||
|
||||
mock_aladdinconnect_api.open_door.return_value = False
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: "cover.home"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_aladdinconnect_api.open_door.return_value = True
|
||||
|
||||
mock_aladdinconnect_api.async_get_door_status = AsyncMock(return_value=STATE_CLOSED)
|
||||
mock_aladdinconnect_api.get_door_status.return_value = STATE_CLOSED
|
||||
|
||||
|
@ -140,6 +153,17 @@ async def test_cover_operation(
|
|||
|
||||
assert hass.states.get("cover.home").state == STATE_CLOSED
|
||||
|
||||
mock_aladdinconnect_api.close_door.return_value = False
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: "cover.home"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_aladdinconnect_api.close_door.return_value = True
|
||||
|
||||
mock_aladdinconnect_api.async_get_door_status = AsyncMock(
|
||||
return_value=STATE_CLOSING
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue