mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Breaking: Update return of get_forecasts_radar_service()
This commit is contained in:
parent
68bcb8aeb4
commit
cf71742b2f
2 changed files with 8 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
|||
"""Support for IRM KMI weather."""
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from typing import List, Dict
|
||||
|
||||
import voluptuous as vol
|
||||
from homeassistant.components.weather import (Forecast, WeatherEntity,
|
||||
|
@ -152,20 +152,18 @@ class IrmKmiWeather(CoordinatorEntity, WeatherEntity):
|
|||
|
||||
return [f for f in data if f.get('is_daytime')]
|
||||
|
||||
def get_forecasts_radar_service(self, include_past_forecasts: bool = False) -> List[Forecast] | None:
|
||||
def get_forecasts_radar_service(self, include_past_forecasts: bool = False) -> Dict[str, List[Forecast]]:
|
||||
"""
|
||||
Forecast service based on data from the radar. Only contains datetime and precipitation amount.
|
||||
The result always include the current 10 minutes interval, even if include_past_forecast is false.
|
||||
:param include_past_forecasts: whether to include data points that are in the past
|
||||
:return: ordered list of forecasts
|
||||
:return: ordered list of forecasts, under the 'forecast' key as other HA services
|
||||
"""
|
||||
now = dt.now()
|
||||
now = now.replace(minute=(now.minute // 10) * 10, second=0, microsecond=0)
|
||||
|
||||
# TODO adapt the return value to match the weather.get_forecasts in next breaking change release
|
||||
# return { 'forecast': [...] }
|
||||
return [f for f in self.coordinator.data.get('radar_forecast')
|
||||
if include_past_forecasts or datetime.fromisoformat(f.get('datetime')) >= now]
|
||||
return {'forecast': [f for f in self.coordinator.data.get('radar_forecast')
|
||||
if include_past_forecasts or datetime.fromisoformat(f.get('datetime')) >= now]}
|
||||
|
||||
# TODO remove on next breaking changes
|
||||
@property
|
||||
|
|
|
@ -61,25 +61,6 @@ async def test_weather_higher_temp_at_night(
|
|||
assert f['native_temperature'] >= f['native_templow']
|
||||
|
||||
|
||||
@freeze_time(datetime.fromisoformat("2023-12-26T18:30:00+01:00"))
|
||||
async def test_forecast_attribute_same_as_service_call(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry_with_deprecated: MockConfigEntry
|
||||
) -> None:
|
||||
coordinator = IrmKmiCoordinator(hass, mock_config_entry_with_deprecated)
|
||||
forecast = json.loads(load_fixture("forecast.json"))
|
||||
coordinator._api._api_data = forecast
|
||||
|
||||
coordinator.data = await coordinator.process_api_data()
|
||||
|
||||
weather = IrmKmiWeather(coordinator, mock_config_entry_with_deprecated)
|
||||
|
||||
result_service: List[Forecast] = await weather.async_forecast_twice_daily()
|
||||
result_forecast: List[Forecast] = weather.extra_state_attributes['forecast']
|
||||
|
||||
assert result_service == result_forecast
|
||||
|
||||
|
||||
@freeze_time(datetime.fromisoformat("2023-12-26T17:58:03+01:00"))
|
||||
async def test_radar_forecast_service(
|
||||
hass: HomeAssistant,
|
||||
|
@ -98,7 +79,7 @@ async def test_radar_forecast_service(
|
|||
|
||||
result_service: List[Forecast] = weather.get_forecasts_radar_service(False)
|
||||
|
||||
expected = [
|
||||
l = [
|
||||
IrmKmiRadarForecast(datetime="2023-12-26T17:00:00+01:00", native_precipitation=0, might_rain=False,
|
||||
rain_forecast_max=0, rain_forecast_min=0, unit='mm/10min'),
|
||||
IrmKmiRadarForecast(datetime="2023-12-26T17:10:00+01:00", native_precipitation=0, might_rain=False,
|
||||
|
@ -123,8 +104,8 @@ async def test_radar_forecast_service(
|
|||
rain_forecast_max=0, rain_forecast_min=0, unit='mm/10min')
|
||||
]
|
||||
|
||||
assert result_service == expected[5:]
|
||||
assert result_service == {'forecast': l[5:]}
|
||||
|
||||
result_service: List[Forecast] = weather.get_forecasts_radar_service(True)
|
||||
|
||||
assert result_service == expected
|
||||
assert result_service == {'forecast': l}
|
||||
|
|
Loading…
Add table
Reference in a new issue