Fix TypeError on round(self.humidity) (fixes #13116) (#14174)

* Fix TypeError on round(self.humidity)

Some weather platforms postpone the first data fetch for a while on init. As a result round(self.humidity is called before it is assigned a value, producing an error. This is a fix for that.

* Rewrite to avoid false negative evaluation

As per the suggestion from @OttoWinter, rewrite to avoid matching e.g. 0.0 as false.
This commit is contained in:
mvn23 2018-04-30 19:27:45 +02:00 committed by Paulus Schoutsen
parent eceece866d
commit 6e0a3abf66

View file

@ -113,9 +113,12 @@ class WeatherEntity(Entity):
ATTR_WEATHER_TEMPERATURE: show_temp(
self.hass, self.temperature, self.temperature_unit,
self.precision),
ATTR_WEATHER_HUMIDITY: round(self.humidity)
}
humidity = self.humidity
if humidity is not None:
data[ATTR_WEATHER_HUMIDITY] = round(humidity)
ozone = self.ozone
if ozone is not None:
data[ATTR_WEATHER_OZONE] = ozone