Improve rainbird error handling (#98239)
This commit is contained in:
parent
6f97270cd2
commit
9ddf11f6cd
7 changed files with 170 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Tests for rainbird number platform."""
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -8,6 +9,7 @@ from homeassistant.components.rainbird import DOMAIN
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .conftest import (
|
||||
|
@ -17,6 +19,7 @@ from .conftest import (
|
|||
SERIAL_NUMBER,
|
||||
ComponentSetup,
|
||||
mock_response,
|
||||
mock_response_error,
|
||||
)
|
||||
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
@ -87,3 +90,40 @@ async def test_set_value(
|
|||
)
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("status", "expected_msg"),
|
||||
[
|
||||
(HTTPStatus.SERVICE_UNAVAILABLE, "Rain Bird device is busy"),
|
||||
(HTTPStatus.INTERNAL_SERVER_ERROR, "Rain Bird device failure"),
|
||||
],
|
||||
)
|
||||
async def test_set_value_error(
|
||||
hass: HomeAssistant,
|
||||
setup_integration: ComponentSetup,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
responses: list[str],
|
||||
config_entry: ConfigEntry,
|
||||
status: HTTPStatus,
|
||||
expected_msg: str,
|
||||
) -> None:
|
||||
"""Test an error while talking to the device."""
|
||||
|
||||
assert await setup_integration()
|
||||
|
||||
aioclient_mock.mock_calls.clear()
|
||||
responses.append(mock_response_error(status=status))
|
||||
|
||||
with pytest.raises(HomeAssistantError, match=expected_msg):
|
||||
await hass.services.async_call(
|
||||
number.DOMAIN,
|
||||
number.SERVICE_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "number.rain_bird_controller_rain_delay",
|
||||
number.ATTR_VALUE: 3,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue