mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Remove async await where not needed
This commit is contained in:
parent
7951bafefb
commit
57cce48c5f
4 changed files with 36 additions and 36 deletions
|
@ -112,7 +112,7 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
|||
if self.data is not None else PollenParser.get_unavailable_data()
|
||||
|
||||
try:
|
||||
radar_animation, image_path, bg_size = await self._api.get_animation_data(tz, lang, self._style,
|
||||
radar_animation, image_path, bg_size = self._api.get_animation_data(tz, lang, self._style,
|
||||
self._dark_mode)
|
||||
animation = await RainGraph(radar_animation, image_path, bg_size, tz=tz, dark_mode=self._dark_mode,
|
||||
api_client=self._api).build()
|
||||
|
@ -120,9 +120,9 @@ class IrmKmiCoordinator(TimestampDataUpdateCoordinator):
|
|||
animation = None
|
||||
|
||||
return ProcessedCoordinatorData(
|
||||
current_weather=await self._api.get_current_weather(tz),
|
||||
daily_forecast=await self._api.get_daily_forecast(tz, lang),
|
||||
hourly_forecast=await self._api.get_hourly_forecast(tz),
|
||||
current_weather=self._api.get_current_weather(tz),
|
||||
daily_forecast=self._api.get_daily_forecast(tz, lang),
|
||||
hourly_forecast=self._api.get_hourly_forecast(tz),
|
||||
radar_forecast=self._api.get_radar_forecast(),
|
||||
animation=animation,
|
||||
warnings=self._api.get_warnings(lang),
|
||||
|
|
|
@ -153,11 +153,11 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
def get_country(self) -> str | None:
|
||||
return self._api_data.get('country', None)
|
||||
|
||||
async def get_current_weather(self, tz: ZoneInfo) -> CurrentWeatherData:
|
||||
def get_current_weather(self, tz: ZoneInfo) -> CurrentWeatherData:
|
||||
"""Parse the API data to build a CurrentWeatherData."""
|
||||
|
||||
now_hourly = await self._get_now_hourly(tz)
|
||||
uv_index = await self._get_uv_index()
|
||||
now_hourly = self._get_now_hourly(tz)
|
||||
uv_index = self._get_uv_index()
|
||||
|
||||
try:
|
||||
pressure = float(now_hourly.get('pressure', None)) if now_hourly is not None else None
|
||||
|
@ -221,7 +221,7 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
|
||||
return current_weather
|
||||
|
||||
async def _get_uv_index(self) -> float | None:
|
||||
def _get_uv_index(self) -> float | None:
|
||||
uv_index = None
|
||||
module_data = self._api_data.get('module', None)
|
||||
if not (module_data is None or not isinstance(module_data, list)):
|
||||
|
@ -230,7 +230,7 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
uv_index = module.get('data', {}).get('levelValue')
|
||||
return uv_index
|
||||
|
||||
async def _get_now_hourly(self, tz: ZoneInfo) -> dict | None:
|
||||
def _get_now_hourly(self, tz: ZoneInfo) -> dict | None:
|
||||
now_hourly = None
|
||||
hourly_forecast_data = self._api_data.get('for', {}).get('hourly')
|
||||
now = datetime.now(tz)
|
||||
|
@ -244,7 +244,7 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
break
|
||||
return now_hourly
|
||||
|
||||
async def get_daily_forecast(self, tz: ZoneInfo, lang: str) -> List[IrmKmiForecast] | None:
|
||||
def get_daily_forecast(self, tz: ZoneInfo, lang: str) -> List[IrmKmiForecast] | None:
|
||||
"""Parse data from the API to create a list of daily forecasts"""
|
||||
data = self._api_data.get('for', {}).get('daily')
|
||||
if data is None or not isinstance(data, list) or len(data) == 0:
|
||||
|
@ -336,12 +336,12 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
|
||||
return forecasts
|
||||
|
||||
async def get_hourly_forecast(self, tz: ZoneInfo) -> List[Forecast] | None:
|
||||
def get_hourly_forecast(self, tz: ZoneInfo) -> List[Forecast] :
|
||||
"""Parse data from the API to create a list of hourly forecasts"""
|
||||
data = self._api_data.get('for', {}).get('hourly')
|
||||
|
||||
if data is None or not isinstance(data, list) or len(data) == 0:
|
||||
return None
|
||||
return []
|
||||
|
||||
forecasts = list()
|
||||
day = datetime.now(tz).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
@ -417,7 +417,7 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
)
|
||||
return forecast
|
||||
|
||||
async def get_animation_data(self, tz: ZoneInfo, lang: str, style: str, dark_mode: bool) -> (RadarAnimationData,
|
||||
def get_animation_data(self, tz: ZoneInfo, lang: str, style: str, dark_mode: bool) -> (RadarAnimationData,
|
||||
str, Tuple[int, int]):
|
||||
"""From the API data passed in, call the API to get all the images and create the radar animation data object.
|
||||
Frames from the API are merged with the background map and the location marker to create each frame."""
|
||||
|
|
|
@ -49,7 +49,7 @@ async def test_warning_data(
|
|||
async def test_current_weather_be() -> None:
|
||||
api = get_api_with_data("forecast.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
result = await api.get_current_weather(tz)
|
||||
result = api.get_current_weather(tz)
|
||||
|
||||
expected = CurrentWeatherData(
|
||||
condition=ATTR_CONDITION_CLOUDY,
|
||||
|
@ -68,7 +68,7 @@ async def test_current_weather_be() -> None:
|
|||
async def test_current_weather_nl() -> None:
|
||||
api = get_api_with_data("forecast_nl.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
result = await api.get_current_weather(tz)
|
||||
result = api.get_current_weather(tz)
|
||||
|
||||
expected = CurrentWeatherData(
|
||||
condition=ATTR_CONDITION_CLOUDY,
|
||||
|
@ -84,13 +84,13 @@ async def test_current_weather_nl() -> None:
|
|||
|
||||
|
||||
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00+01:00'))
|
||||
async def test_daily_forecast(
|
||||
def test_daily_forecast(
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api = get_api_with_data("forecast.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_daily_forecast(tz, 'fr')
|
||||
result = api.get_daily_forecast(tz, 'fr')
|
||||
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 8
|
||||
|
@ -116,10 +116,10 @@ async def test_daily_forecast(
|
|||
|
||||
|
||||
@freeze_time(datetime.fromisoformat('2023-12-26T18:30:00+01:00'))
|
||||
async def test_hourly_forecast() -> None:
|
||||
def test_hourly_forecast() -> None:
|
||||
api = get_api_with_data("forecast.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
result = await api.get_hourly_forecast(tz)
|
||||
result = api.get_hourly_forecast(tz)
|
||||
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 49
|
||||
|
@ -142,11 +142,11 @@ async def test_hourly_forecast() -> None:
|
|||
|
||||
|
||||
@freeze_time(datetime.fromisoformat('2024-05-31T01:50:00+02:00'))
|
||||
async def test_hourly_forecast_bis() -> None:
|
||||
def test_hourly_forecast_bis() -> None:
|
||||
api = get_api_with_data("no-midnight-bug-31-05-2024T01-55.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_hourly_forecast(tz)
|
||||
result = api.get_hourly_forecast(tz)
|
||||
|
||||
assert isinstance(result, list)
|
||||
|
||||
|
@ -160,12 +160,12 @@ async def test_hourly_forecast_bis() -> None:
|
|||
|
||||
|
||||
@freeze_time(datetime.fromisoformat('2024-05-31T00:10:00+02:00'))
|
||||
async def test_hourly_forecast_midnight_bug() -> None:
|
||||
def test_hourly_forecast_midnight_bug() -> None:
|
||||
# Related to https://github.com/jdejaegh/irm-kmi-ha/issues/38
|
||||
api = get_api_with_data("midnight-bug-31-05-2024T00-13.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_hourly_forecast(tz)
|
||||
result = api.get_hourly_forecast(tz)
|
||||
|
||||
assert isinstance(result, list)
|
||||
|
||||
|
@ -197,13 +197,13 @@ async def test_hourly_forecast_midnight_bug() -> None:
|
|||
|
||||
|
||||
@freeze_time(datetime.fromisoformat('2024-05-31T00:10:00+02:00'))
|
||||
async def test_daily_forecast_midnight_bug(
|
||||
def test_daily_forecast_midnight_bug(
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api = get_api_with_data("midnight-bug-31-05-2024T00-13.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_daily_forecast(tz, 'en')
|
||||
result = api.get_daily_forecast(tz, 'en')
|
||||
|
||||
assert result[0]['datetime'] == '2024-05-31'
|
||||
assert not result[0]['is_daytime']
|
||||
|
@ -310,13 +310,13 @@ def test_radar_forecast_rain_interval() -> None:
|
|||
|
||||
|
||||
@freeze_time("2024-06-09T13:40:00+00:00")
|
||||
async def test_datetime_daily_forecast_nl(
|
||||
def test_datetime_daily_forecast_nl(
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api = get_api_with_data("forecast_ams_no_ww.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_daily_forecast(tz, 'en')
|
||||
result = api.get_daily_forecast(tz, 'en')
|
||||
|
||||
assert result[0]['datetime'] == '2024-06-09'
|
||||
assert result[0]['is_daytime']
|
||||
|
@ -333,7 +333,7 @@ async def test_current_condition_forecast_nl() -> None:
|
|||
api = get_api_with_data("forecast_ams_no_ww.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_current_weather(tz)
|
||||
result = api.get_current_weather(tz)
|
||||
|
||||
expected = CurrentWeatherData(
|
||||
condition=ATTR_CONDITION_PARTLYCLOUDY,
|
||||
|
@ -348,13 +348,13 @@ async def test_current_condition_forecast_nl() -> None:
|
|||
|
||||
|
||||
@freeze_time("2024-06-09T13:40:00+00:00")
|
||||
async def test_sunrise_sunset_nl(
|
||||
def test_sunrise_sunset_nl(
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api = get_api_with_data("forecast_ams_no_ww.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_daily_forecast(tz, 'en')
|
||||
result = api.get_daily_forecast(tz, 'en')
|
||||
|
||||
assert result[0]['sunrise'] == '2024-06-09T05:19:28+02:00'
|
||||
assert result[0]['sunset'] == '2024-06-09T22:01:09+02:00'
|
||||
|
@ -367,13 +367,13 @@ async def test_sunrise_sunset_nl(
|
|||
|
||||
|
||||
@freeze_time("2023-12-26T18:30:00+01:00")
|
||||
async def test_sunrise_sunset_be(
|
||||
def test_sunrise_sunset_be(
|
||||
mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
api = get_api_with_data("forecast.json")
|
||||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
result = await api.get_daily_forecast(tz, 'en')
|
||||
result = api.get_daily_forecast(tz, 'en')
|
||||
|
||||
assert result[1]['sunrise'] == '2023-12-27T08:44:00+01:00'
|
||||
assert result[1]['sunset'] == '2023-12-27T16:43:00+01:00'
|
||||
|
|
|
@ -119,8 +119,8 @@ async def test_current_weather_sensors(
|
|||
async def run(mock_config_entry_, sensor_, expected_):
|
||||
coordinator = IrmKmiCoordinator(hass, mock_config_entry_)
|
||||
coordinator.data = ProcessedCoordinatorData(
|
||||
current_weather=await api.get_current_weather(tz),
|
||||
hourly_forecast=await api.get_hourly_forecast(tz),
|
||||
current_weather=api.get_current_weather(tz),
|
||||
hourly_forecast=api.get_hourly_forecast(tz),
|
||||
radar_forecast=api.get_radar_forecast(),
|
||||
country=api_data.get('country')
|
||||
)
|
||||
|
@ -153,8 +153,8 @@ async def test_current_rainfall_unit(
|
|||
tz = ZoneInfo("Europe/Brussels")
|
||||
|
||||
coordinator.data = ProcessedCoordinatorData(
|
||||
current_weather=await api.get_current_weather(tz),
|
||||
hourly_forecast=await api.get_hourly_forecast(tz),
|
||||
current_weather=api.get_current_weather(tz),
|
||||
hourly_forecast=api.get_hourly_forecast(tz),
|
||||
radar_forecast=api.get_radar_forecast(),
|
||||
country=api.get_country()
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue