mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Translate UnknownError and RuntimeError in OpenEVSE exception handler (#179682)
This commit is contained in:
@@ -94,5 +94,5 @@ class OpenEVSEButton(CoordinatorEntity[OpenEVSEDataUpdateCoordinator], ButtonEnt
|
||||
@override
|
||||
async def async_press(self) -> None:
|
||||
"""Press the button."""
|
||||
with openevse_exception_handler(0.0):
|
||||
with openevse_exception_handler():
|
||||
await self.entity_description.press_fn(self.coordinator.charger)
|
||||
|
||||
@@ -8,6 +8,7 @@ from aiohttp import ContentTypeError, ServerTimeoutError
|
||||
from openevsehttp.exceptions import (
|
||||
AuthenticationError,
|
||||
ParseJSONError,
|
||||
UnknownError,
|
||||
UnsupportedFeature,
|
||||
)
|
||||
|
||||
@@ -46,6 +47,8 @@ def openevse_exception_handler(value: Any = None) -> Iterator[None]:
|
||||
ServerTimeoutError,
|
||||
ContentTypeError,
|
||||
ParseJSONError,
|
||||
UnknownError,
|
||||
RuntimeError,
|
||||
) as err:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
|
||||
@@ -6,6 +6,7 @@ from aiohttp import ContentTypeError, ServerTimeoutError
|
||||
from openevsehttp.exceptions import (
|
||||
AuthenticationError,
|
||||
ParseJSONError,
|
||||
UnknownError,
|
||||
UnsupportedFeature,
|
||||
)
|
||||
import pytest
|
||||
@@ -76,41 +77,61 @@ async def test_press(
|
||||
@pytest.mark.parametrize(
|
||||
("raised", "expected", "translation_key", "translation_placeholders"),
|
||||
[
|
||||
(
|
||||
pytest.param(
|
||||
AuthenticationError("bad creds"),
|
||||
ConfigEntryAuthFailed,
|
||||
"authentication_error",
|
||||
None,
|
||||
id="auth_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
TimeoutError("timed out"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="timeout_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ServerTimeoutError("timed out"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="server_timeout_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ParseJSONError("bad json"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="parse_json_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
UnsupportedFeature("old firmware"),
|
||||
HomeAssistantError,
|
||||
"unsupported_feature",
|
||||
None,
|
||||
id="unsupported_feature",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ContentTypeError(MagicMock(), (), message="bad content"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="content_type_error",
|
||||
),
|
||||
pytest.param(
|
||||
UnknownError("unknown error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="unknown_error",
|
||||
),
|
||||
pytest.param(
|
||||
RuntimeError("runtime error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="runtime_error",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ from aiohttp import ContentTypeError, ServerTimeoutError
|
||||
from openevsehttp.exceptions import (
|
||||
AuthenticationError,
|
||||
ParseJSONError,
|
||||
UnknownError,
|
||||
UnsupportedFeature,
|
||||
)
|
||||
import pytest
|
||||
@@ -67,47 +68,68 @@ async def test_set_value(
|
||||
@pytest.mark.parametrize(
|
||||
("raised", "expected", "translation_key", "translation_placeholders"),
|
||||
[
|
||||
(
|
||||
pytest.param(
|
||||
ValueError("out of range"),
|
||||
ServiceValidationError,
|
||||
"invalid_value",
|
||||
{"value": "32.0"},
|
||||
id="value_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
AuthenticationError("bad creds"),
|
||||
ConfigEntryAuthFailed,
|
||||
"authentication_error",
|
||||
None,
|
||||
id="auth_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
TimeoutError("timed out"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="timeout_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ServerTimeoutError("timed out"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="server_timeout_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ParseJSONError("bad json"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="parse_json_error",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
UnsupportedFeature("old firmware"),
|
||||
HomeAssistantError,
|
||||
"unsupported_feature",
|
||||
None,
|
||||
id="unsupported_feature",
|
||||
),
|
||||
(
|
||||
pytest.param(
|
||||
ContentTypeError(MagicMock(), (), message="bad content"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="content_type_error",
|
||||
),
|
||||
pytest.param(
|
||||
UnknownError("unknown error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="unknown_error",
|
||||
),
|
||||
pytest.param(
|
||||
RuntimeError("runtime error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="runtime_error",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ from aiohttp import ContentTypeError, ServerTimeoutError
|
||||
from openevsehttp.exceptions import (
|
||||
AuthenticationError,
|
||||
ParseJSONError,
|
||||
UnknownError,
|
||||
UnsupportedFeature,
|
||||
)
|
||||
import pytest
|
||||
@@ -167,6 +168,20 @@ async def test_switch_turn_on_off(
|
||||
None,
|
||||
id="content_type_error",
|
||||
),
|
||||
pytest.param(
|
||||
UnknownError("unknown error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="unknown_error",
|
||||
),
|
||||
pytest.param(
|
||||
RuntimeError("runtime error"),
|
||||
HomeAssistantError,
|
||||
"communication_error",
|
||||
None,
|
||||
id="runtime_error",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_switch_raises(
|
||||
|
||||
Reference in New Issue
Block a user