Promote Homevolt exception translations (#181651)

This commit is contained in:
Daniel Hjelseth Høyer
2026-09-08 16:51:22 +02:00
committed by GitHub
parent 4e49aa6f9e
commit aa8a735a30
3 changed files with 35 additions and 3 deletions
@@ -51,6 +51,10 @@ class HomevoltDataUpdateCoordinator(DataUpdateCoordinator[Homevolt]):
except HomevoltAuthenticationError as err:
raise ConfigEntryAuthFailed from err
except (HomevoltConnectionError, HomevoltError) as err:
raise UpdateFailed(f"Error communicating with device: {err}") from err
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="communication_error",
translation_placeholders={"error": str(err)},
) from err
return self.client
@@ -64,7 +64,7 @@ rules:
entity-device-class: done
entity-disabled-by-default: done
entity-translations: done
exception-translations: todo
exception-translations: done
icon-translations: todo
reconfiguration-flow: todo
repair-issues: todo
+29 -1
View File
@@ -2,9 +2,10 @@
from unittest.mock import MagicMock
from homevolt import HomevoltAuthenticationError, HomevoltConnectionError
from homevolt import HomevoltAuthenticationError, HomevoltConnectionError, HomevoltError
import pytest
from homeassistant.components.homevolt.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
@@ -56,3 +57,30 @@ async def test_config_entry_setup_failure(
await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state is expected_state
@pytest.mark.parametrize(
"exception",
[
pytest.param(HomevoltConnectionError("Connection failed"), id="connection"),
pytest.param(HomevoltError("Connection failed"), id="homevolt"),
],
)
async def test_setup_retry_error_is_translated(
hass: HomeAssistant,
mock_homevolt_client: MagicMock,
mock_config_entry: MockConfigEntry,
exception: HomevoltError,
) -> None:
"""Test communication errors expose translated setup retry reasons."""
mock_homevolt_client.update_info.side_effect = exception
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
assert mock_config_entry.error_reason_translation_domain == DOMAIN
assert mock_config_entry.error_reason_translation_key == "communication_error"
assert mock_config_entry.error_reason_translation_placeholders == {
"error": "Connection failed"
}