Translate UnknownError and RuntimeError in OpenEVSE exception handler (#179682)

This commit is contained in:
Chris
2026-08-24 09:22:30 +02:00
committed by GitHub
parent f739818a23
commit 0662c32260
5 changed files with 75 additions and 14 deletions
+1 -1
View File
@@ -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,
+27 -6
View File
@@ -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",
),
],
)
+29 -7
View File
@@ -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",
),
],
)
+15
View File
@@ -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(