Bump `accuweather` to version 1.0.0 (#93305)

pull/93322/head
Maciej Bieniek 2023-05-21 12:50:10 +00:00 committed by GitHub
parent 90984c34a9
commit d47e58fb38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 75 additions and 45 deletions

View File

@ -121,12 +121,12 @@ class AccuWeatherDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
async def _async_update_data(self) -> dict[str, Any]:
"""Update data via library."""
forecast: list[dict[str, Any]] = []
try:
async with timeout(10):
current = await self.accuweather.async_get_current_conditions()
forecast = (
await self.accuweather.async_get_forecast() if self.forecast else {}
)
if self.forecast:
forecast = await self.accuweather.async_get_daily_forecast()
except (
ApiError,
ClientConnectorError,

View File

@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"loggers": ["accuweather"],
"quality_scale": "platinum",
"requirements": ["accuweather==0.5.2"]
"requirements": ["accuweather==1.0.0"]
}

View File

@ -1,8 +1,7 @@
"""Support for the AccuWeather service."""
from __future__ import annotations
from statistics import mean
from typing import Any, cast
from typing import cast
from homeassistant.components.weather import (
ATTR_FORECAST_CONDITION,
@ -120,15 +119,10 @@ class AccuWeatherEntity(
ATTR_FORECAST_TIME: utc_from_timestamp(item["EpochDate"]).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: item["TemperatureMax"]["Value"],
ATTR_FORECAST_NATIVE_TEMP_LOW: item["TemperatureMin"]["Value"],
ATTR_FORECAST_NATIVE_PRECIPITATION: self._calc_precipitation(item),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: round(
mean(
[
item["PrecipitationProbabilityDay"],
item["PrecipitationProbabilityNight"],
]
)
),
ATTR_FORECAST_NATIVE_PRECIPITATION: item["TotalLiquidDay"]["Value"],
ATTR_FORECAST_PRECIPITATION_PROBABILITY: item[
"PrecipitationProbabilityDay"
],
ATTR_FORECAST_NATIVE_WIND_SPEED: item["WindDay"]["Speed"]["Value"],
ATTR_FORECAST_WIND_BEARING: item["WindDay"]["Direction"]["Degrees"],
ATTR_FORECAST_CONDITION: [
@ -137,18 +131,3 @@ class AccuWeatherEntity(
}
for item in self.coordinator.data[ATTR_FORECAST]
]
@staticmethod
def _calc_precipitation(day: dict[str, Any]) -> float:
"""Return sum of the precipitation."""
precip_sum = 0
precip_types = ["Rain", "Snow", "Ice"]
for precip in precip_types:
precip_sum = sum(
[
precip_sum,
day[f"{precip}Day"]["Value"],
day[f"{precip}Night"]["Value"],
]
)
return round(precip_sum, 1)

View File

@ -71,7 +71,7 @@ WSDiscovery==2.0.0
WazeRouteCalculator==0.14
# homeassistant.components.accuweather
accuweather==0.5.2
accuweather==1.0.0
# homeassistant.components.adax
adax==0.2.0

View File

@ -61,7 +61,7 @@ WSDiscovery==2.0.0
WazeRouteCalculator==0.14
# homeassistant.components.accuweather
accuweather==0.5.2
accuweather==1.0.0
# homeassistant.components.adax
adax==0.2.0

View File

@ -41,7 +41,7 @@ async def init_integration(
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
return_value=current,
), patch(
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast",
return_value=forecast,
), patch(
"homeassistant.components.accuweather.AccuWeather.requests_remaining",

View File

@ -1,4 +1,5 @@
{
"WeatherText": "Sunny",
"WeatherIcon": 1,
"HasPrecipitation": false,
"PrecipitationType": null,

View File

@ -137,6 +137,11 @@
"HoursOfSnowDay": 0.0,
"HoursOfIceDay": 0.0,
"CloudCoverDay": 58,
"SolarIrradianceDay": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
},
"IconNight": 41,
"IconPhraseNight": "Partly cloudy w/ t-storms",
"HasPrecipitationNight": true,
@ -197,7 +202,12 @@
"HoursOfRainNight": 1.0,
"HoursOfSnowNight": 0.0,
"HoursOfIceNight": 0.0,
"CloudCoverNight": 65
"CloudCoverNight": 65,
"SolarIrradianceNight": {
"Value": 271.6,
"Unit": "W/m\u00b2",
"UnitType": 33
}
},
{
"Date": "2020-07-27T07:00:00+02:00",
@ -335,6 +345,11 @@
"HoursOfSnowDay": 0.0,
"HoursOfIceDay": 0.0,
"CloudCoverDay": 52,
"SolarIrradianceDay": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
},
"IconNight": 36,
"IconPhraseNight": "Intermittent clouds",
"HasPrecipitationNight": false,
@ -393,7 +408,12 @@
"HoursOfRainNight": 0.0,
"HoursOfSnowNight": 0.0,
"HoursOfIceNight": 0.0,
"CloudCoverNight": 63
"CloudCoverNight": 63,
"SolarIrradianceNight": {
"Value": 271.6,
"Unit": "W/m\u00b2",
"UnitType": 33
}
},
{
"Date": "2020-07-28T07:00:00+02:00",
@ -531,6 +551,11 @@
"HoursOfSnowDay": 0.0,
"HoursOfIceDay": 0.0,
"CloudCoverDay": 65,
"SolarIrradianceDay": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
},
"IconNight": 36,
"IconPhraseNight": "Intermittent clouds",
"HasPrecipitationNight": false,
@ -589,7 +614,12 @@
"HoursOfRainNight": 0.0,
"HoursOfSnowNight": 0.0,
"HoursOfIceNight": 0.0,
"CloudCoverNight": 53
"CloudCoverNight": 53,
"SolarIrradianceNight": {
"Value": 271.6,
"Unit": "W/m\u00b2",
"UnitType": 33
}
},
{
"Date": "2020-07-29T07:00:00+02:00",
@ -727,6 +757,11 @@
"HoursOfSnowDay": 0.0,
"HoursOfIceDay": 0.0,
"CloudCoverDay": 45,
"SolarIrradianceDay": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
},
"IconNight": 34,
"IconPhraseNight": "Mostly clear",
"HasPrecipitationNight": false,
@ -785,7 +820,12 @@
"HoursOfRainNight": 0.0,
"HoursOfSnowNight": 0.0,
"HoursOfIceNight": 0.0,
"CloudCoverNight": 27
"CloudCoverNight": 27,
"SolarIrradianceNight": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
}
},
{
"Date": "2020-07-30T07:00:00+02:00",
@ -923,6 +963,11 @@
"HoursOfSnowDay": 0.0,
"HoursOfIceDay": 0.0,
"CloudCoverDay": 50,
"SolarIrradianceDay": {
"Value": 7447.1,
"Unit": "W/m\u00b2",
"UnitType": 33
},
"IconNight": 34,
"IconPhraseNight": "Mostly clear",
"HasPrecipitationNight": false,
@ -981,6 +1026,11 @@
"HoursOfRainNight": 0.0,
"HoursOfSnowNight": 0.0,
"HoursOfIceNight": 0.0,
"CloudCoverNight": 13
"CloudCoverNight": 13,
"SolarIrradianceNight": {
"Value": 276.1,
"Unit": "W/m\u00b2",
"UnitType": 33
}
}
]

View File

@ -156,7 +156,7 @@ async def test_options_flow(hass: HomeAssistant) -> None:
"accuweather/current_conditions_data.json"
),
), patch(
"homeassistant.components.accuweather.AccuWeather.async_get_forecast"
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast"
), patch(
"homeassistant.components.accuweather.AccuWeather.requests_remaining",
new_callable=PropertyMock,

View File

@ -19,7 +19,7 @@ async def test_entry_diagnostics(
"current_conditions_data.json", "accuweather"
)
coordinator_data["forecast"] = {}
coordinator_data["forecast"] = []
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)

View File

@ -104,7 +104,7 @@ async def test_update_interval_forecast(hass: HomeAssistant) -> None:
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
return_value=current,
) as mock_current, patch(
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast",
return_value=forecast,
) as mock_forecast:
assert mock_current.call_count == 0

View File

@ -717,7 +717,7 @@ async def test_manual_update_entity(hass: HomeAssistant) -> None:
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
return_value=current,
) as mock_current, patch(
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast",
return_value=forecast,
) as mock_forecast, patch(
"homeassistant.components.accuweather.AccuWeather.requests_remaining",

View File

@ -74,8 +74,8 @@ async def test_weather_with_forecast(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
forecast = state.attributes.get(ATTR_FORECAST)[0]
assert forecast.get(ATTR_FORECAST_CONDITION) == "lightning-rainy"
assert forecast.get(ATTR_FORECAST_PRECIPITATION) == 4.8
assert forecast.get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) == 58
assert forecast.get(ATTR_FORECAST_PRECIPITATION) == 2.5
assert forecast.get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) == 60
assert forecast.get(ATTR_FORECAST_TEMP) == 29.5
assert forecast.get(ATTR_FORECAST_TEMP_LOW) == 15.4
assert forecast.get(ATTR_FORECAST_TIME) == "2020-07-26T05:00:00+00:00"
@ -141,7 +141,7 @@ async def test_manual_update_entity(hass: HomeAssistant) -> None:
"homeassistant.components.accuweather.AccuWeather.async_get_current_conditions",
return_value=current,
) as mock_current, patch(
"homeassistant.components.accuweather.AccuWeather.async_get_forecast",
"homeassistant.components.accuweather.AccuWeather.async_get_daily_forecast",
return_value=forecast,
) as mock_forecast, patch(
"homeassistant.components.accuweather.AccuWeather.requests_remaining",