8000 Add changes from comments after merging AccuWeather PR by bieniu · Pull Request #38227 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add changes from comments after merging AccuWeather PR #38227

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

Merged
merged 5 commits into from
Jul 27, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/accuweather/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "accuweather",
"name": "AccuWeather",
"documentation": "https://github.com/bieniu/ha-accuweather",
"documentation": "https://www.home-assistant.io/integrations/accuweather/",
"requirements": ["accuweather==0.0.9"],
"codeowners": ["@bieniu"],
"config_flow": true
Expand Down
58 changes: 28 additions & 30 deletions homeassistant/components/accuweather/weather.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ATTR_FORECAST_WIND_SPEED,
WeatherEntity,
)
from homeassistant.const import CONF_NAME, STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import CONF_NAME, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.util.dt import utc_from_timestamp

from .const import ATTR_FORECAST, ATTRIBUTION, CONDITION_CLASSES, COORDINATOR, DOMAIN
Expand Down Expand Up @@ -74,7 +74,7 @@ def condition(self):
if self.coordinator.data["WeatherIcon"] in v
][0]
except IndexError:
return STATE_UNKNOWN
return None

@property
def temperature(self):
Expand Down Expand Up @@ -124,34 +124,32 @@ def ozone(self):
@property
def forecast(self):
"""Return the forecast array."""
if self.coordinator.forecast:
# remap keys from library to keys understood by the weather component
forecast = [
{
ATTR_FORECAST_TIME: utc_from_timestamp(
item["EpochDate"]
).isoformat(),
ATTR_FORECAST_TEMP: item["TemperatureMax"]["Value"],
ATTR_FORECAST_TEMP_LOW: item["TemperatureMin"]["Value"],
ATTR_FORECAST_PRECIPITATION: self._calc_precipitation(item),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: round(
mean(
[
item["PrecipitationProbabilityDay"],
item["PrecipitationProbabilityNight"],
]
)
),
ATTR_FORECAST_WIND_SPEED: item["WindDay"]["Speed"]["Value"],
ATTR_FORECAST_WIND_BEARING: item["WindDay"]["Direction"]["Degrees"],
ATTR_FORECAST_CONDITION: [
k for k, v in CONDITION_CLASSES.items() if item["IconDay"] in v
][0],
}
for item in self.coordinator.data[ATTR_FORECAST]
]
return forecast
return None
if not self.coordinator.forecast:
return None
# remap keys from library to keys understood by the weather component
forecast = [
{
ATTR_FORECAST_TIME: utc_from_timestamp(item["EpochDate"]).isoformat(),
ATTR_FORECAST_TEMP: item["TemperatureMax"]["Value"],
ATTR_FORECAST_TEMP_LOW: item["TemperatureMin"]["Value"],
ATTR_FORECAST_PRECIPITATION: self._calc_precipitation(item),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: round(
mean(
[
item["PrecipitationProbabilityDay"],
item["PrecipitationProbabilityNight"],
]
)
),
ATTR_FORECAST_WIND_SPEED: item["WindDay"]["Speed"]["Value"],
ATTR_FORECAST_WIND_BEARING: item["WindDay"]["Direction"]["Degrees"],
ATTR_FORECAST_CONDITION: [
k for k, v in CONDITION_CLASSES.items() if item["IconDay"] in v
][0],
}
for item in self.coordinator.data[ATTR_FORECAST]
]
return forecast

async def async_added_to_hass(self):
"""Connect to dispatcher listening for entity data notifications."""
Expand Down
10 changes: 7 additions & 3 deletions tests/components/accuweather/test_config_flow.py
4D2D
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ async def test_show_form(hass):
assert result["step_id"] == SOURCE_USER


async def test_invalid_api_key_1(hass):
"""Test that errors are shown when API key is invalid."""
async def test_api_key_too_short(hass):
"""Test that errors are shown when API key is too short."""
# The API key length check is done by the library without polling the AccuWeather
# server so we don't need to patch the library method.
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
Expand All @@ -45,7 +47,7 @@ async def test_invalid_api_key_1(hass):
assert result["errors"] == {CONF_API_KEY: "invalid_api_key"}


async def test_invalid_api_key_2(hass):
async def test_invalid_api_key(hass):
"""Test that errors are shown when API key is invalid."""
with patch(
"accuweather.AccuWeather._async_get_data",
Expand Down Expand Up @@ -112,6 +114,8 @@ async def test_create_entry(hass):
with patch(
"accuweather.AccuWeather._async_get_data",
return_value=json.loads(load_fixture("accuweather/location_data.json")),
), patch(
"homeassistant.components.accuweather.async_setup_entry", return_value=True
):

result = await hass.config_entries.flow.async_init(
Expand Down
0