mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 11:39:26 +02:00
parent
e693224792
commit
a0b6fdc36c
2 changed files with 8 additions and 7 deletions
|
@ -273,7 +273,7 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
forecasts = list()
|
forecasts = list()
|
||||||
day = datetime.now()
|
day = datetime.now(tz=pytz.timezone('Europe/Brussels')).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
|
||||||
for f in data:
|
for f in data:
|
||||||
if 'dateShow' in f:
|
if 'dateShow' in f:
|
||||||
|
@ -282,6 +282,7 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
||||||
hour = f.get('hour', None)
|
hour = f.get('hour', None)
|
||||||
if hour is None:
|
if hour is None:
|
||||||
continue
|
continue
|
||||||
|
day = day.replace(hour=int(hour))
|
||||||
|
|
||||||
precipitation_probability = None
|
precipitation_probability = None
|
||||||
if f.get('precipChance', None) is not None:
|
if f.get('precipChance', None) is not None:
|
||||||
|
@ -299,7 +300,7 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
forecast = Forecast(
|
forecast = Forecast(
|
||||||
datetime=day.strftime(f'%Y-%m-%dT{hour}:00:00'),
|
datetime=day.isoformat(),
|
||||||
condition=CDT_MAP.get((ww, f.get('dayNight', None)), None),
|
condition=CDT_MAP.get((ww, f.get('dayNight', None)), None),
|
||||||
native_precipitation=f.get('precipQuantity', None),
|
native_precipitation=f.get('precipQuantity', None),
|
||||||
native_temperature=f.get('temp', None),
|
native_temperature=f.get('temp', None),
|
||||||
|
@ -347,10 +348,10 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
is_daytime = f.get('dayNight', None) == 'd'
|
is_daytime = f.get('dayNight', None) == 'd'
|
||||||
|
now = datetime.now(pytz.timezone('Europe/Brussels'))
|
||||||
forecast = IrmKmiForecast(
|
forecast = IrmKmiForecast(
|
||||||
datetime=(datetime.now() + timedelta(days=n_days)).strftime('%Y-%m-%d')
|
datetime=(now + timedelta(days=n_days)).strftime('%Y-%m-%d')
|
||||||
if is_daytime else datetime.now().strftime('%Y-%m-%d'),
|
if is_daytime else now.strftime('%Y-%m-%d'),
|
||||||
condition=CDT_MAP.get((f.get('ww1', None), f.get('dayNight', None)), None),
|
condition=CDT_MAP.get((f.get('ww1', None), f.get('dayNight', None)), None),
|
||||||
native_precipitation=precipitation,
|
native_precipitation=precipitation,
|
||||||
native_temperature=f.get('tempMax', None),
|
native_temperature=f.get('tempMax', None),
|
||||||
|
|
|
@ -113,7 +113,7 @@ async def test_daily_forecast(
|
||||||
assert result[1] == expected
|
assert result[1] == expected
|
||||||
|
|
||||||
|
|
||||||
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00.028724'))
|
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00+01:00'))
|
||||||
def test_hourly_forecast() -> None:
|
def test_hourly_forecast() -> None:
|
||||||
api_data = get_api_data("forecast.json").get('for', {}).get('hourly')
|
api_data = get_api_data("forecast.json").get('for', {}).get('hourly')
|
||||||
result = IrmKmiCoordinator.hourly_list_to_forecast(api_data)
|
result = IrmKmiCoordinator.hourly_list_to_forecast(api_data)
|
||||||
|
@ -122,7 +122,7 @@ def test_hourly_forecast() -> None:
|
||||||
assert len(result) == 49
|
assert len(result) == 49
|
||||||
|
|
||||||
expected = Forecast(
|
expected = Forecast(
|
||||||
datetime='2023-12-27T02:00:00',
|
datetime='2023-12-27T02:00:00+01:00',
|
||||||
condition=ATTR_CONDITION_RAINY,
|
condition=ATTR_CONDITION_RAINY,
|
||||||
native_precipitation=.98,
|
native_precipitation=.98,
|
||||||
native_temperature=8,
|
native_temperature=8,
|
||||||
|
|
Loading…
Add table
Reference in a new issue