From 6e0a3abf66d89833394d55b2ac25af4068ab2a01 Mon Sep 17 00:00:00 2001 From: mvn23 Date: Mon, 30 Apr 2018 19:27:45 +0200 Subject: [PATCH] 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. --- homeassistant/components/weather/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 467a106a6a2..c36c960c4fc 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -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