mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Remove text_fr and text_nl from forecast and add text instead (auto-detect instance language)
This commit is contained in:
parent
44dd78c077
commit
a401bc172a
4 changed files with 14 additions and 13 deletions
|
@ -130,7 +130,7 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
|
||||||
"""From the API data, create the object that will be used in the entities"""
|
"""From the API data, create the object that will be used in the entities"""
|
||||||
return ProcessedCoordinatorData(
|
return ProcessedCoordinatorData(
|
||||||
current_weather=IrmKmiCoordinator.current_weather_from_data(api_data),
|
current_weather=IrmKmiCoordinator.current_weather_from_data(api_data),
|
||||||
daily_forecast=IrmKmiCoordinator.daily_list_to_forecast(api_data.get('for', {}).get('daily')),
|
daily_forecast=self.daily_list_to_forecast(api_data.get('for', {}).get('daily')),
|
||||||
hourly_forecast=IrmKmiCoordinator.hourly_list_to_forecast(api_data.get('for', {}).get('hourly')),
|
hourly_forecast=IrmKmiCoordinator.hourly_list_to_forecast(api_data.get('for', {}).get('hourly')),
|
||||||
animation=await self._async_animation_data(api_data=api_data),
|
animation=await self._async_animation_data(api_data=api_data),
|
||||||
warnings=self.warnings_from_data(api_data.get('for', {}).get('warning'))
|
warnings=self.warnings_from_data(api_data.get('for', {}).get('warning'))
|
||||||
|
@ -257,8 +257,7 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
|
||||||
|
|
||||||
return forecasts
|
return forecasts
|
||||||
|
|
||||||
@staticmethod
|
def daily_list_to_forecast(self, data: List[dict] | None) -> List[Forecast] | None:
|
||||||
def daily_list_to_forecast(data: List[dict] | None) -> List[Forecast] | None:
|
|
||||||
"""Parse data from the API to create a list of daily forecasts"""
|
"""Parse data from the API to create a list of daily forecasts"""
|
||||||
if data is None or not isinstance(data, list) or len(data) == 0:
|
if data is None or not isinstance(data, list) or len(data) == 0:
|
||||||
return None
|
return None
|
||||||
|
@ -295,8 +294,7 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
|
||||||
precipitation_probability=f.get('precipChance', None),
|
precipitation_probability=f.get('precipChance', None),
|
||||||
wind_bearing=f.get('wind', {}).get('dirText', {}).get('en'),
|
wind_bearing=f.get('wind', {}).get('dirText', {}).get('en'),
|
||||||
is_daytime=is_daytime,
|
is_daytime=is_daytime,
|
||||||
text_fr=f.get('text', {}).get('fr'),
|
text=f.get('text', {}).get(self.hass.config.language, ""),
|
||||||
text_nl=f.get('text', {}).get('nl')
|
|
||||||
)
|
)
|
||||||
forecasts.append(forecast)
|
forecasts.append(forecast)
|
||||||
if is_daytime or idx == 0:
|
if is_daytime or idx == 0:
|
||||||
|
|
|
@ -9,9 +9,7 @@ class IrmKmiForecast(Forecast):
|
||||||
"""Forecast class with additional attributes for IRM KMI"""
|
"""Forecast class with additional attributes for IRM KMI"""
|
||||||
|
|
||||||
# TODO: add condition_2 as well and evolution to match data from the API?
|
# TODO: add condition_2 as well and evolution to match data from the API?
|
||||||
# TODO: remove the _fr and _nl to have only one 'text' attribute
|
text: str | None
|
||||||
text_fr: str | None
|
|
||||||
text_nl: str | None
|
|
||||||
|
|
||||||
|
|
||||||
class CurrentWeatherData(TypedDict, total=False):
|
class CurrentWeatherData(TypedDict, total=False):
|
||||||
|
|
3
tests/fixtures/forecast.json
vendored
3
tests/fixtures/forecast.json
vendored
|
@ -66,7 +66,8 @@
|
||||||
"dayNight": "d",
|
"dayNight": "d",
|
||||||
"text": {
|
"text": {
|
||||||
"nl": "Foo",
|
"nl": "Foo",
|
||||||
"fr": "Bar"
|
"fr": "Bar",
|
||||||
|
"en": "Hey!"
|
||||||
},
|
},
|
||||||
"dawnRiseSeconds": "31440",
|
"dawnRiseSeconds": "31440",
|
||||||
"dawnSetSeconds": "60180",
|
"dawnSetSeconds": "60180",
|
||||||
|
|
|
@ -82,9 +82,14 @@ def test_current_weather_nl() -> None:
|
||||||
|
|
||||||
|
|
||||||
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00.028724'))
|
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00.028724'))
|
||||||
def test_daily_forecast() -> None:
|
async def test_daily_forecast(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_config_entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
api_data = get_api_data("forecast.json").get('for', {}).get('daily')
|
api_data = get_api_data("forecast.json").get('for', {}).get('daily')
|
||||||
result = IrmKmiCoordinator.daily_list_to_forecast(api_data)
|
|
||||||
|
coordinator = IrmKmiCoordinator(hass, mock_config_entry)
|
||||||
|
result = coordinator.daily_list_to_forecast(api_data)
|
||||||
|
|
||||||
assert isinstance(result, list)
|
assert isinstance(result, list)
|
||||||
assert len(result) == 8
|
assert len(result) == 8
|
||||||
|
@ -100,8 +105,7 @@ def test_daily_forecast() -> None:
|
||||||
precipitation_probability=0,
|
precipitation_probability=0,
|
||||||
wind_bearing='S',
|
wind_bearing='S',
|
||||||
is_daytime=True,
|
is_daytime=True,
|
||||||
text_fr='Bar',
|
text='Hey!',
|
||||||
text_nl='Foo'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result[1] == expected
|
assert result[1] == expected
|
||||||
|
|
Loading…
Add table
Reference in a new issue