Skip to content

Commit

Permalink
Add forecast text as an attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jdejaegh committed Dec 24, 2023
1 parent 1c50c78 commit d488d15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions custom_components/irm_kmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
"""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
5 changes: 4 additions & 1 deletion custom_components/irm_kmi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
UpdateFailed,
)

from . import IrmKmiForecast
from .const import IRM_KMI_TO_HA_CONDITION_MAP as CDT_MAP
from .api import IrmKmiApiClient, IrmKmiApiError

Expand All @@ -33,7 +34,7 @@ def daily_dict_to_forecast(data: List[dict] | None) -> List[Forecast] | None:

is_daytime = f.get('dayNight', None) == 'd'

forecast = Forecast(
forecast = IrmKmiForecast(
datetime=(datetime.now() + timedelta(days=n_days)).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),
Expand All @@ -45,6 +46,8 @@ def daily_dict_to_forecast(data: List[dict] | None) -> List[Forecast] | None:
precipitation_probability=f.get('precipChance', None),
wind_bearing=f.get('wind', {}).get('dirText', {}).get('en'),
is_daytime=is_daytime,
text_fr=f.get('text', {}).get('fr'),
text_nl=f.get('text', {}).get('nl')
)
forecasts.append(forecast)
if is_daytime:
Expand Down

0 comments on commit d488d15

Please sign in to comment.