diff --git a/homeassistant/components/demo/weather.py b/homeassistant/components/demo/weather.py index b17c88fa828..3c87cd1c27c 100644 --- a/homeassistant/components/demo/weather.py +++ b/homeassistant/components/demo/weather.py @@ -4,6 +4,7 @@ from datetime import timedelta from homeassistant.components.weather import ( ATTR_FORECAST_CONDITION, ATTR_FORECAST_PRECIPITATION, + ATTR_FORECAST_PRECIPITATION_PROBABILITY, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME, @@ -48,13 +49,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): 0.5, TEMP_CELSIUS, [ - ["rainy", 1, 22, 15], - ["rainy", 5, 19, 8], - ["cloudy", 0, 15, 9], - ["sunny", 0, 12, 6], - ["partlycloudy", 2, 14, 7], - ["rainy", 15, 18, 7], - ["fog", 0.2, 21, 12], + ["rainy", 1, 22, 15, 60], + ["rainy", 5, 19, 8, 30], + ["cloudy", 0, 15, 9, 10], + ["sunny", 0, 12, 6, 0], + ["partlycloudy", 2, 14, 7, 20], + ["rainy", 15, 18, 7, 0], + ["fog", 0.2, 21, 12, 100], ], ), DemoWeather( @@ -66,13 +67,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): 4.8, TEMP_FAHRENHEIT, [ - ["snowy", 2, -10, -15], - ["partlycloudy", 1, -13, -14], - ["sunny", 0, -18, -22], - ["sunny", 0.1, -23, -23], - ["snowy", 4, -19, -20], - ["sunny", 0.3, -14, -19], - ["sunny", 0, -9, -12], + ["snowy", 2, -10, -15, 60], + ["partlycloudy", 1, -13, -14, 25], + ["sunny", 0, -18, -22, 70], + ["sunny", 0.1, -23, -23, 90], + ["snowy", 4, -19, -20, 40], + ["sunny", 0.3, -14, -19, 0], + ["sunny", 0, -9, -12, 0], ], ), ] @@ -163,6 +164,7 @@ class DemoWeather(WeatherEntity): ATTR_FORECAST_PRECIPITATION: entry[1], ATTR_FORECAST_TEMP: entry[2], ATTR_FORECAST_TEMP_LOW: entry[3], + ATTR_FORECAST_PRECIPITATION_PROBABILITY: entry[4], } reftime = reftime + timedelta(hours=4) forecast_data.append(data_dict) diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index 10666b4a34e..7bc614bd09e 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -8,6 +8,7 @@ import voluptuous as vol from homeassistant.components.weather import ( ATTR_FORECAST_CONDITION, + ATTR_FORECAST_PRECIPITATION_PROBABILITY, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME, @@ -183,6 +184,9 @@ def get_forecast(ec_data, forecast_type): ATTR_FORECAST_CONDITION: icon_code_to_condition( int(half_days[0]["icon_code"]) ), + ATTR_FORECAST_PRECIPITATION_PROBABILITY: int( + half_days[0]["precip_probability"] + ), } ) half_days = half_days[2:] @@ -200,6 +204,9 @@ def get_forecast(ec_data, forecast_type): ATTR_FORECAST_CONDITION: icon_code_to_condition( int(half_days[high]["icon_code"]) ), + ATTR_FORECAST_PRECIPITATION_PROBABILITY: int( + half_days[high]["precip_probability"] + ), } ) @@ -215,6 +222,9 @@ def get_forecast(ec_data, forecast_type): ATTR_FORECAST_CONDITION: icon_code_to_condition( int(hours[hour]["icon_code"]) ), + ATTR_FORECAST_PRECIPITATION_PROBABILITY: int( + hours[hour]["precip_probability"] + ), } ) diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 8efb8519636..5a6fcc2d80b 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -19,6 +19,7 @@ ATTR_CONDITION_CLASS = "condition_class" ATTR_FORECAST = "forecast" ATTR_FORECAST_CONDITION = "condition" ATTR_FORECAST_PRECIPITATION = "precipitation" +ATTR_FORECAST_PRECIPITATION_PROBABILITY = "precipitation_probability" ATTR_FORECAST_TEMP = "temperature" ATTR_FORECAST_TEMP_LOW = "templow" ATTR_FORECAST_TIME = "datetime" diff --git a/tests/components/weather/test_weather.py b/tests/components/weather/test_weather.py index 10161a0d634..ccddb35ad0a 100644 --- a/tests/components/weather/test_weather.py +++ b/tests/components/weather/test_weather.py @@ -6,6 +6,7 @@ from homeassistant.components.weather import ( ATTR_FORECAST, ATTR_FORECAST_CONDITION, ATTR_FORECAST_PRECIPITATION, + ATTR_FORECAST_PRECIPITATION_PROBABILITY, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_WEATHER_ATTRIBUTION, @@ -56,12 +57,20 @@ class TestWeather(unittest.TestCase): assert data.get(ATTR_WEATHER_ATTRIBUTION) == "Powered by Home Assistant" assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_CONDITION) == "rainy" assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION) == 1 + assert ( + data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) + == 60 + ) assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP) == 22 assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP_LOW) == 15 assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_CONDITION) == "fog" assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION) == 0.2 assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP) == 21 assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP_LOW) == 12 + assert ( + data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION_PROBABILITY) + == 100 + ) assert len(data.get(ATTR_FORECAST)) == 7 def test_temperature_convert(self):