Improve rainbird error handling (#98239)

This commit is contained in:
Allen Porter 2023-08-14 04:32:08 -07:00 committed by GitHub
parent 6f97270cd2
commit 9ddf11f6cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 170 additions and 17 deletions

View file

@ -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