From d47e58fb38337cf7a6d9d2ff22581bf9a8d8e732 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sun, 21 May 2023 12:50:10 +0000 Subject: [PATCH] Bump `accuweather` to version 1.0.0 (#93305) --- .../components/accuweather/__init__.py | 6 +- .../components/accuweather/manifest.json | 2 +- .../components/accuweather/weather.py | 31 ++-------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/accuweather/__init__.py | 2 +- .../fixtures/current_conditions_data.json | 1 + .../accuweather/fixtures/forecast_data.json | 60 +++++++++++++++++-- .../accuweather/test_config_flow.py | 2 +- .../accuweather/test_diagnostics.py | 2 +- tests/components/accuweather/test_init.py | 2 +- tests/components/accuweather/test_sensor.py | 2 +- tests/components/accuweather/test_weather.py | 6 +- 13 files changed, 75 insertions(+), 45 deletions(-) diff --git a/homeassistant/components/accuweather/__init__.py b/homeassistant/components/accuweather/__init__.py index c7943d15bd0..2a19f0d0291 100644 --- a/homeassistant/components/accuweather/__init__.py +++ b/homeassistant/components/accuweather/__init__.py @@ -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, diff --git a/homeassistant/components/accuweather/manifest.json b/homeassistant/components/accuweather/manifest.json index fbf31720e13..658b5d368d0 100644 --- a/homeassistant/components/accuweather/manifest.json +++ b/homeassistant/components/accuweather/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "loggers": ["accuweather"], "quality_scale": "platinum", - "requirements": ["accuweather==0.5.2"] + "requirements": ["accuweather==1.0.0"] } diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index 0ef729b9b69..6107285e376 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -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) diff --git a/requirements_all.txt b/requirements_all.txt index 07fbb1d88d4..6aa217b0068 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ada42531b2e..55573f84f00 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/accuweather/__init__.py b/tests/components/accuweather/__init__.py index fd6441b4346..3c7f81450c6 100644 --- a/tests/components/accuweather/__init__.py +++ b/tests/components/accuweather/__init__.py @@ -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", diff --git a/tests/components/accuweather/fixtures/current_conditions_data.json b/tests/components/accuweather/fixtures/current_conditions_data.json index 020345bf8fa..97f42dcc411 100644 --- a/tests/components/accuweather/fixtures/current_conditions_data.json +++ b/tests/components/accuweather/fixtures/current_conditions_data.json @@ -1,4 +1,5 @@ { + "WeatherText": "Sunny", "WeatherIcon": 1, "HasPrecipitation": false, "PrecipitationType": null, diff --git a/tests/components/accuweather/fixtures/forecast_data.json b/tests/components/accuweather/fixtures/forecast_data.json index 1b432fbd075..a7d57af113a 100644 --- a/tests/components/accuweather/fixtures/forecast_data.json +++ b/tests/components/accuweather/fixtures/forecast_data.json @@ -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 + } } ] diff --git a/tests/components/accuweather/test_config_flow.py b/tests/components/accuweather/test_config_flow.py index 4d8d83a2a2f..35b6e095c0f 100644 --- a/tests/components/accuweather/test_config_flow.py +++ b/tests/components/accuweather/test_config_flow.py @@ -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, diff --git a/tests/components/accuweather/test_diagnostics.py b/tests/components/accuweather/test_diagnostics.py index 767bbd9953a..98be70d9ec6 100644 --- a/tests/components/accuweather/test_diagnostics.py +++ b/tests/components/accuweather/test_diagnostics.py @@ -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) diff --git a/tests/components/accuweather/test_init.py b/tests/components/accuweather/test_init.py index 7123d5ef817..c7f79b487b5 100644 --- a/tests/components/accuweather/test_init.py +++ b/tests/components/accuweather/test_init.py @@ -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 diff --git a/tests/components/accuweather/test_sensor.py b/tests/components/accuweather/test_sensor.py index 37e58504efe..f27aa158e0e 100644 --- a/tests/components/accuweather/test_sensor.py +++ b/tests/components/accuweather/test_sensor.py @@ -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", diff --git a/tests/components/accuweather/test_weather.py b/tests/components/accuweather/test_weather.py index ab4faf73c81..de1703128dd 100644 --- a/tests/components/accuweather/test_weather.py +++ b/tests/components/accuweather/test_weather.py @@ -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",