Add error handling to Tailwind service methods (#106463)
This commit is contained in:
parent
68ac4717dc
commit
a78ecb3895
7 changed files with 219 additions and 15 deletions
|
@ -1,12 +1,15 @@
|
|||
"""Tests for button entities provided by the Tailwind integration."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gotailwind import TailwindError
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = [
|
||||
|
@ -46,3 +49,17 @@ async def test_number_entities(
|
|||
|
||||
assert (state := hass.states.get(state.entity_id))
|
||||
assert state.state == "2023-12-17T15:25:00+00:00"
|
||||
|
||||
# Test error handling
|
||||
mock_tailwind.identify.side_effect = TailwindError("Some error")
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Some error") as excinfo:
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: state.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "communication_error"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue