Skip to content

Commit

Permalink
Merge pull request #47 from jdejaegh/fix_nl_weather
Browse files Browse the repository at this point in the history
Fix current condition and twice daily forecast datetime for NL
  • Loading branch information
jdejaegh authored Jun 9, 2024
2 parents 7e153e2 + f66b202 commit 48ad275
Show file tree
Hide file tree
Showing 3 changed files with 1,730 additions and 1 deletion.
18 changes: 17 additions & 1 deletion custom_components/irm_kmi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ async def current_weather_from_data(api_data: dict) -> CurrentWeatherData:
except ValueError:
current_weather['wind_bearing'] = None

# Since June 2024, the NL weather does not include the condition in the 'ww' key, so we get it from the current
# hourly forecast instead if it is missing
if current_weather['condition'] is None:
try:
current_weather['condition'] = CDT_MAP.get((int(now_hourly.get('ww')), now_hourly.get('dayNight')))
except (TypeError, ValueError):
current_weather['condition'] = None

return current_weather

@staticmethod
Expand Down Expand Up @@ -383,9 +391,17 @@ async def daily_list_to_forecast(self, data: List[dict] | None) -> List[Forecast
pass

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

day_name = f.get('dayName', {}).get('en', None)
if day_name in WEEKDAYS:
timestamp = f.get('timestamp', None)
if timestamp is not None:
forecast_day = datetime.fromisoformat(timestamp)
elif day_name in WEEKDAYS:
forecast_day = next_weekday(forecast_day, WEEKDAYS.index(day_name))
elif day_name in ['Today', 'Tonight']:
forecast_day = dt.now(tz)
elif day_name == 'Tomorrow':
forecast_day = dt.now(tz) + timedelta(days=1)

forecast = IrmKmiForecast(
datetime=(forecast_day.strftime('%Y-%m-%d')),
Expand Down
Loading

0 comments on commit 48ad275

Please sign in to comment.