Fix rain retrival for OWM (#39566)

As documented in the OWM API (https://openweathermap.org/api/one-call-api), rain and snow are reported on a 1h basis:

current.rain
    current.rain.1h (where available) Rain volume for last hour, mm
current.snow
    current.snow.1h (where available) Snow volume for last hour, mm
This commit is contained in:
Hendrik Schröter 2020-09-03 06:16:38 +00:00 committed by GitHub
parent 65e53b8251
commit 49daf57c54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -165,15 +165,16 @@ class OpenWeatherMapSensor(Entity):
self._state = data.get_clouds()
elif self.type == "rain":
rain = data.get_rain()
if "3h" in rain:
self._state = round(rain["3h"], 0)
if "1h" in rain:
self._state = round(rain["1h"], 0)
self._unit_of_measurement = "mm"
else:
self._state = "not raining"
self._unit_of_measurement = ""
elif self.type == "snow":
if data.get_snow():
self._state = round(data.get_snow(), 0)
snow = data.get_snow()
if "1h" in snow:
self._state = round(snow["1h"], 0)
self._unit_of_measurement = "mm"
else:
self._state = "not snowing"

View File

@ -203,18 +203,16 @@ class OpenWeatherMapWeather(WeatherEntity):
}
)
else:
rain = entry.get_rain().get("1h")
if rain is not None:
rain = round(rain, 1)
data.append(
{
ATTR_FORECAST_TIME: entry.get_reference_time("unix") * 1000,
ATTR_FORECAST_TEMP: entry.get_temperature("celsius").get(
"temp"
),
ATTR_FORECAST_PRECIPITATION: (
round(entry.get_rain().get("3h"), 1)
if entry.get_rain().get("3h") is not None
and (round(entry.get_rain().get("3h"), 1) > 0)
else None
),
ATTR_FORECAST_PRECIPITATION: rain,
ATTR_FORECAST_CONDITION: [
k
for k, v in CONDITION_CLASSES.items()