mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
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:
parent
65e53b8251
commit
49daf57c54
@ -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"
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user