Add forecast text as an attribute

This commit is contained in:
Jules 2023-12-24 16:58:02 +01:00
parent 1c50c78f7a
commit d488d15875
Signed by: jdejaegh
GPG key ID: 99D6D184CA66933A
2 changed files with 10 additions and 1 deletions

View file

@ -1 +1,7 @@
"""Integration for IRM KMI weather""" """Integration for IRM KMI weather"""
from homeassistant.components.weather import Forecast
class IrmKmiForecast(Forecast):
"""Forecast class with additional attributes for IRM KMI"""
text_fr: str | None
text_nl: str | None

View file

@ -13,6 +13,7 @@ from homeassistant.helpers.update_coordinator import (
UpdateFailed, UpdateFailed,
) )
from . import IrmKmiForecast
from .const import IRM_KMI_TO_HA_CONDITION_MAP as CDT_MAP from .const import IRM_KMI_TO_HA_CONDITION_MAP as CDT_MAP
from .api import IrmKmiApiClient, IrmKmiApiError from .api import IrmKmiApiClient, IrmKmiApiError
@ -33,7 +34,7 @@ def daily_dict_to_forecast(data: List[dict] | None) -> List[Forecast] | None:
is_daytime = f.get('dayNight', None) == 'd' is_daytime = f.get('dayNight', None) == 'd'
forecast = Forecast( forecast = IrmKmiForecast(
datetime=(datetime.now() + timedelta(days=n_days)).strftime('%Y-%m-%d') datetime=(datetime.now() + timedelta(days=n_days)).strftime('%Y-%m-%d')
if is_daytime else datetime.now().strftime('%Y-%m-%d'), if is_daytime else datetime.now().strftime('%Y-%m-%d'),
condition=CDT_MAP.get((f.get('ww1'), f.get('dayNight')), None), condition=CDT_MAP.get((f.get('ww1'), f.get('dayNight')), None),
@ -45,6 +46,8 @@ def daily_dict_to_forecast(data: List[dict] | None) -> List[Forecast] | None:
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_nl=f.get('text', {}).get('nl')
) )
forecasts.append(forecast) forecasts.append(forecast)
if is_daytime: if is_daytime: