mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Follow the Home Assistant language in irm_kmi by default (#182938)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user