Fix openweathermap sensor.py so no KeyError if raining is miss… (#33372)

This commit is contained in:
Austin Mroczek 2020-03-28 20:59:57 -07:00 committed by GitHub
parent f32ae95ef4
commit d832ce0b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,8 +163,9 @@ class OpenWeatherMapSensor(Entity):
elif self.type == "clouds":
self._state = data.get_clouds()
elif self.type == "rain":
if data.get_rain():
self._state = round(data.get_rain()["3h"], 0)
rain = data.get_rain()
if "3h" in rain:
self._state = round(rain["3h"], 0)
self._unit_of_measurement = "mm"
else:
self._state = "not raining"