mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 13:00:11 +00:00
Simplify Reolink exception handling (#141427)
This commit is contained in:
@@ -38,59 +38,59 @@ from tests.common import MockConfigEntry
|
||||
[
|
||||
(
|
||||
ApiError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="api_error"),
|
||||
),
|
||||
(
|
||||
ApiError("Test error", translation_key="firmware_rate_limit"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="firmware_rate_limit"),
|
||||
),
|
||||
(
|
||||
ApiError("Test error", translation_key="not_in_strings.json"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="api_error"),
|
||||
),
|
||||
(
|
||||
CredentialsInvalidError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="invalid_credentials"),
|
||||
),
|
||||
(
|
||||
InvalidContentTypeError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="invalid_content_type"),
|
||||
),
|
||||
(
|
||||
InvalidParameterError("Test error"),
|
||||
ServiceValidationError,
|
||||
ServiceValidationError(translation_key="invalid_parameter"),
|
||||
),
|
||||
(
|
||||
LoginError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="login_error"),
|
||||
),
|
||||
(
|
||||
NoDataError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="no_data"),
|
||||
),
|
||||
(
|
||||
NotSupportedError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="not_supported"),
|
||||
),
|
||||
(
|
||||
ReolinkConnectionError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="connection_error"),
|
||||
),
|
||||
(
|
||||
ReolinkError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="unexpected"),
|
||||
),
|
||||
(
|
||||
ReolinkTimeoutError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="timeout"),
|
||||
),
|
||||
(
|
||||
SubscriptionError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="subscription_error"),
|
||||
),
|
||||
(
|
||||
UnexpectedDataError("Test error"),
|
||||
HomeAssistantError,
|
||||
HomeAssistantError(translation_key="unexpected_data"),
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -99,7 +99,7 @@ async def test_try_function(
|
||||
config_entry: MockConfigEntry,
|
||||
reolink_connect: MagicMock,
|
||||
side_effect: ReolinkError,
|
||||
expected: Exception,
|
||||
expected: HomeAssistantError,
|
||||
) -> None:
|
||||
"""Test try_function error translations using number entity."""
|
||||
reolink_connect.volume.return_value = 80
|
||||
@@ -112,7 +112,7 @@ async def test_try_function(
|
||||
entity_id = f"{Platform.NUMBER}.{TEST_NVR_NAME}_volume"
|
||||
|
||||
reolink_connect.set_volume.side_effect = side_effect
|
||||
with pytest.raises(expected):
|
||||
with pytest.raises(expected.__class__) as err:
|
||||
await hass.services.async_call(
|
||||
NUMBER_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
@@ -120,4 +120,6 @@ async def test_try_function(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert err.value.translation_key == expected.translation_key
|
||||
|
||||
reolink_connect.set_volume.reset_mock(side_effect=True)
|
||||
|
||||
Reference in New Issue
Block a user