mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Translate the Peblar setup exceptions (#180561)
This commit is contained in:
@@ -48,14 +48,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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user