From fa8e976de744a946eaec3d1de280cda0367b537f Mon Sep 17 00:00:00 2001 From: tronikos Date: Wed, 18 Mar 2026 13:25:58 -0700 Subject: [PATCH] Add exception translations to Google Weather (#165935) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/google_weather/coordinator.py | 10 +++++++++- .../components/google_weather/quality_scale.yaml | 2 +- homeassistant/components/google_weather/strings.json | 5 +++++ tests/components/google_weather/test_init.py | 5 ++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_weather/coordinator.py b/homeassistant/components/google_weather/coordinator.py index 3f81a8a31e9..695dc5ea191 100644 --- a/homeassistant/components/google_weather/coordinator.py +++ b/homeassistant/components/google_weather/coordinator.py @@ -24,6 +24,8 @@ from homeassistant.helpers.update_coordinator import ( UpdateFailed, ) +from .const import DOMAIN + _LOGGER = logging.getLogger(__name__) T = TypeVar( @@ -97,7 +99,13 @@ class GoogleWeatherBaseCoordinator(TimestampDataUpdateCoordinator[T]): self.subentry.title, err, ) - raise UpdateFailed(f"Error fetching {self._data_type_name}") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="update_error", + translation_placeholders={ + "error": str(err), + }, + ) from err class GoogleWeatherCurrentConditionsCoordinator( diff --git a/homeassistant/components/google_weather/quality_scale.yaml b/homeassistant/components/google_weather/quality_scale.yaml index 946bcc9a0d3..8c86565e8f9 100644 --- a/homeassistant/components/google_weather/quality_scale.yaml +++ b/homeassistant/components/google_weather/quality_scale.yaml @@ -66,7 +66,7 @@ rules: entity-device-class: done entity-disabled-by-default: done entity-translations: done - exception-translations: todo + exception-translations: done icon-translations: done reconfiguration-flow: todo repair-issues: diff --git a/homeassistant/components/google_weather/strings.json b/homeassistant/components/google_weather/strings.json index 7f23f297544..977adb306fc 100644 --- a/homeassistant/components/google_weather/strings.json +++ b/homeassistant/components/google_weather/strings.json @@ -98,5 +98,10 @@ "name": "Wind gust speed" } } + }, + "exceptions": { + "update_error": { + "message": "Error fetching weather data: {error}" + } } } diff --git a/tests/components/google_weather/test_init.py b/tests/components/google_weather/test_init.py index 16462c86023..aa3b6629e94 100644 --- a/tests/components/google_weather/test_init.py +++ b/tests/components/google_weather/test_init.py @@ -42,16 +42,19 @@ async def test_config_not_ready( mock_config_entry: MockConfigEntry, mock_google_weather_api: AsyncMock, failing_api_method: str, + caplog: pytest.LogCaptureFixture, ) -> None: """Test for setup failure if an API call fails.""" getattr( mock_google_weather_api, failing_api_method - ).side_effect = GoogleWeatherApiError() + ).side_effect = GoogleWeatherApiError("API error") await hass.config_entries.async_setup(mock_config_entry.entry_id) assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY + assert "Error fetching weather data: API error" in caplog.text + async def test_unload_entry( hass: HomeAssistant,