mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Merge pull request #47 from jdejaegh/fix_nl_weather
Fix current condition and twice daily forecast datetime for NL
This commit is contained in:
commit
48ad275cf9
3 changed files with 1730 additions and 1 deletions
|
@ -270,6 +270,14 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
|||
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
|
||||
|
@ -383,9 +391,17 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
|||
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')),
|
||||
|
|
1676
tests/fixtures/forecast_ams_no_ww.json
vendored
Normal file
1676
tests/fixtures/forecast_ams_no_ww.json
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -313,3 +313,40 @@ def test_radar_forecast_rain_interval() -> None:
|
|||
|
||||
assert result[12] == _12
|
||||
assert result[13] == _13
|
||||
|
||||
|
||||
@freeze_time("2024-06-09T13:40:00+00:00")
|
||||
async def test_datetime_daily_forecast_nl(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api_data = get_api_data("forecast_ams_no_ww.json").get('for', {}).get('daily')
|
||||
|
||||
coordinator = IrmKmiCoordinator(hass, mock_config_entry)
|
||||
result = await coordinator.daily_list_to_forecast(api_data)
|
||||
|
||||
assert result[0]['datetime'] == '2024-06-09'
|
||||
assert result[0]['is_daytime']
|
||||
|
||||
assert result[1]['datetime'] == '2024-06-10'
|
||||
assert not result[1]['is_daytime']
|
||||
|
||||
assert result[2]['datetime'] == '2024-06-10'
|
||||
assert result[2]['is_daytime']
|
||||
|
||||
|
||||
@freeze_time("2024-06-09T13:40:00+00:00")
|
||||
async def test_current_condition_forecast_nl() -> None:
|
||||
api_data = get_api_data("forecast_ams_no_ww.json")
|
||||
result = await IrmKmiCoordinator.current_weather_from_data(api_data)
|
||||
|
||||
expected = CurrentWeatherData(
|
||||
condition=ATTR_CONDITION_PARTLYCLOUDY,
|
||||
temperature=15,
|
||||
wind_speed=26,
|
||||
wind_gust_speed=None,
|
||||
wind_bearing=270,
|
||||
pressure=1010,
|
||||
uv_index=6
|
||||
)
|
||||
assert result == expected
|
||||
|
|
Loading…
Add table
Reference in a new issue