Translate the Peblar setup exceptions (#180561)

This commit is contained in:
Franck Nijhof
2026-08-29 01:25:26 +02:00
committed by GitHub
parent dc189b94e1
commit 3da5869857
2 changed files with 39 additions and 10 deletions
+14 -7
View File
@@ -59,14 +59,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: PeblarConfigEntry) -> bo
system_information = await peblar.system_information()
api = await peblar.rest_api(enable=True, access_mode=AccessMode.READ_WRITE)
except PeblarConnectionError as err:
# pylint: disable-next=home-assistant-exception-not-translated
raise ConfigEntryNotReady("Could not connect to Peblar charger") from err
except PeblarAuthenticationError as err:
raise ConfigEntryAuthFailed from err
except PeblarError as err:
# pylint: disable-next=home-assistant-exception-not-translated
raise ConfigEntryNotReady(
"Unknown error occurred while connecting to Peblar charger"
translation_domain=DOMAIN,
translation_key="communication_error",
translation_placeholders={"error": str(err)},
) from err
except PeblarAuthenticationError as err:
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="authentication_error",
) from err
except PeblarError as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="unknown_error",
translation_placeholders={"error": str(err)},
) from err
# Setup the data coordinators
+25 -3
View File
@@ -35,16 +35,35 @@ async def test_load_unload_config_entry(
@pytest.mark.parametrize(
"exception",
[PeblarConnectionError, PeblarError],
("exception", "translation_key", "reason"),
[
(
PeblarConnectionError("Could not connect"),
"communication_error",
"An error occurred while communicating with the Peblar EV charger: "
"Could not connect",
),
(
PeblarError("Unknown error"),
"unknown_error",
"An unknown error occurred while communicating with the Peblar EV "
"charger: Unknown error",
),
],
)
async def test_config_entry_not_ready(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_peblar: MagicMock,
exception: Exception,
translation_key: str,
reason: str,
) -> None:
"""Test the Peblar configuration entry not ready."""
"""Test the Peblar configuration entry not ready.
The reason reaches the user, so it comes from strings.json rather than
from a sentence typed into the raise.
"""
mock_peblar.login.side_effect = exception
mock_config_entry.add_to_hass(hass)
@@ -53,6 +72,8 @@ async def test_config_entry_not_ready(
assert len(mock_peblar.login.mock_calls) == 1
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
assert mock_config_entry.error_reason_translation_key == translation_key
assert mock_config_entry.reason == reason
async def test_config_entry_authentication_failed(
@@ -69,6 +90,7 @@ async def test_config_entry_authentication_failed(
await hass.async_block_till_done()
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
assert mock_config_entry.error_reason_translation_key == "authentication_error"
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1