From 3fc09dfd1c65592fa9416f60287a053ceb9a3489 Mon Sep 17 00:00:00 2001 From: YP30 <58120331+YP30@users.noreply.github.com> Date: Tue, 6 Oct 2026 07:32:40 +0200 Subject: [PATCH] Follow the Home Assistant language in irm_kmi by default (#182938) --- .../components/irm_kmi/coordinator.py | 2 + homeassistant/components/irm_kmi/utils.py | 17 +++---- tests/components/irm_kmi/test_init.py | 50 +++++++++++++++++++ tests/components/irm_kmi/test_weather.py | 7 +++ 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/irm_kmi/coordinator.py b/homeassistant/components/irm_kmi/coordinator.py index cea0057d5899..e8dfcb66602b 100644 --- a/homeassistant/components/irm_kmi/coordinator.py +++ b/homeassistant/components/irm_kmi/coordinator.py @@ -29,6 +29,8 @@ type IrmKmiConfigEntry = ConfigEntry[IrmKmiCoordinator] class IrmKmiCoordinator(TimestampDataUpdateCoordinator[ProcessedCoordinatorData]): """Coordinator to update data from IRM KMI.""" + config_entry: IrmKmiConfigEntry + def __init__( self, hass: HomeAssistant, diff --git a/homeassistant/components/irm_kmi/utils.py b/homeassistant/components/irm_kmi/utils.py index 662e6554affb..d2eb0a025f12 100644 --- a/homeassistant/components/irm_kmi/utils.py +++ b/homeassistant/components/irm_kmi/utils.py @@ -6,16 +6,13 @@ from homeassistant.core import HomeAssistant from .const import CONF_LANGUAGE_OVERRIDE, LANGS -def preferred_language(hass: HomeAssistant, config_entry: ConfigEntry | None) -> str: - """Get the preferred language for the integration. +def preferred_language(hass: HomeAssistant, config_entry: ConfigEntry) -> str: + """Return the language to use for this config entry. - Returns the overridden language if set in configuration. + Falls back to the Home Assistant language, or to English when that one is + not supported. """ - - if ( - config_entry is None - or config_entry.options.get(CONF_LANGUAGE_OVERRIDE) == "none" - ): + language: str = config_entry.options.get(CONF_LANGUAGE_OVERRIDE, "none") + if language == "none": return hass.config.language if hass.config.language in LANGS else "en" - - return config_entry.options.get(CONF_LANGUAGE_OVERRIDE, "en") + return language diff --git a/tests/components/irm_kmi/test_init.py b/tests/components/irm_kmi/test_init.py index 82e628d055dd..00752fbf007b 100644 --- a/tests/components/irm_kmi/test_init.py +++ b/tests/components/irm_kmi/test_init.py @@ -7,9 +7,11 @@ from freezegun.api import FrozenDateTimeFactory from irm_kmi_api import IrmKmiApiError import pytest +from homeassistant.components.irm_kmi.const import CONF_LANGUAGE_OVERRIDE, DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr from . import setup_integration from .const import WEATHER_ENTITY_ID @@ -33,6 +35,54 @@ async def test_load_unload_config_entry( assert mock_config_entry.state is ConfigEntryState.NOT_LOADED +@pytest.mark.parametrize( + ("hass_language", "options", "expected_manufacturer"), + [ + pytest.param( + "nl", + {}, + "Koninklijk Meteorologisch Instituut van België", + id="home_assistant_language", + ), + pytest.param( + "nl", + {CONF_LANGUAGE_OVERRIDE: "fr"}, + "Institut Royal Météorologique de Belgique", + id="language_override", + ), + pytest.param( + "es", + {}, + "Royal Meteorological Institute of Belgium", + id="unsupported_language_falls_back_to_english", + ), + ], +) +@pytest.mark.usefixtures("mock_irm_kmi_api") +async def test_device_entry( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, + hass_language: str, + options: dict[str, str], + expected_manufacturer: str, +) -> None: + """Test the device entry.""" + hass.config.language = hass_language + mock_config_entry.add_to_hass(hass) + hass.config_entries.async_update_entry(mock_config_entry, options=options) + + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + device_entry = device_registry.async_get_device_by_identifier( + (DOMAIN, mock_config_entry.entry_id), mock_config_entry.entry_id + ) + assert device_entry + assert device_entry.entry_type is dr.DeviceEntryType.SERVICE + assert device_entry.manufacturer == expected_manufacturer + + async def test_config_entry_not_ready( hass: HomeAssistant, mock_config_entry: MockConfigEntry, diff --git a/tests/components/irm_kmi/test_weather.py b/tests/components/irm_kmi/test_weather.py index 38ea243217b2..c29a00249e70 100644 --- a/tests/components/irm_kmi/test_weather.py +++ b/tests/components/irm_kmi/test_weather.py @@ -131,6 +131,13 @@ async def test_daily_forecast_night_low_above_day_high( "Koninklijk Meteorologisch Instituut van België", id="follow_home_assistant", ), + pytest.param( + "nl", + {}, + "Foo", + "Koninklijk Meteorologisch Instituut van België", + id="follow_home_assistant_by_default", + ), ], ) @pytest.mark.freeze_time("2024-01-23T14:15:00+01:00")