From aa8a735a3084117ae2fe351b8729b243753206c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hjelseth=20H=C3=B8yer?= Date: Tue, 8 Sep 2026 16:51:22 +0200 Subject: [PATCH] Promote Homevolt exception translations (#181651) --- .../components/homevolt/coordinator.py | 6 +++- .../components/homevolt/quality_scale.yaml | 2 +- tests/components/homevolt/test_init.py | 30 ++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homevolt/coordinator.py b/homeassistant/components/homevolt/coordinator.py index 272afdd5f14a..26ee5cfaf5d9 100644 --- a/homeassistant/components/homevolt/coordinator.py +++ b/homeassistant/components/homevolt/coordinator.py @@ -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 diff --git a/homeassistant/components/homevolt/quality_scale.yaml b/homeassistant/components/homevolt/quality_scale.yaml index f33aab82954c..fe97cb9a53f6 100644 --- a/homeassistant/components/homevolt/quality_scale.yaml +++ b/homeassistant/components/homevolt/quality_scale.yaml @@ -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 diff --git a/tests/components/homevolt/test_init.py b/tests/components/homevolt/test_init.py index 1b3a0b0bf790..c2f648a1f2c8 100644 --- a/tests/components/homevolt/test_init.py +++ b/tests/components/homevolt/test_init.py @@ -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" + }