Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump accuweather to version 1.0.0 #93305

Merged
merged 6 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/accuweather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def __init__(

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,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/accuweather/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"loggers": ["accuweather"],
"quality_scale": "platinum",
"requirements": ["accuweather==0.5.2"]
"requirements": ["accuweather==1.0.0"]
}
31 changes: 5 additions & 26 deletions homeassistant/components/accuweather/weather.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -120,15 +119,10 @@ def forecast(self) -> list[Forecast] | None:
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: [
Expand All @@ -137,18 +131,3 @@ def forecast(self) -> list[Forecast] | None:
}
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)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/accuweather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"WeatherText": "Sunny",
"WeatherIcon": 1,
"HasPrecipitation": false,
"PrecipitationType": null,
Expand Down
60 changes: 55 additions & 5 deletions tests/components/accuweather/fixtures/forecast_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
]
2 changes: 1 addition & 1 deletion tests/components/accuweather/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/components/accuweather/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/components/accuweather/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/accuweather/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/components/accuweather/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down