From 97165a33a2387fbe14cd1ae9841bfca5598603c7 Mon Sep 17 00:00:00 2001 From: mvn23 Date: Sun, 29 Apr 2018 23:46:52 +0200 Subject: [PATCH 1/2] 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. --- homeassistant/components/weather/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index b200d634ba91f..5e1e754684fd4 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -110,7 +110,8 @@ def state_attributes(self): ATTR_WEATHER_TEMPERATURE: show_temp( self.hass, self.temperature, self.temperature_unit, self.precision), - ATTR_WEATHER_HUMIDITY: round(self.humidity) + ATTR_WEATHER_HUMIDITY: (round(self.humidity) if self.humidity + else None) } ozone = self.ozone From dadbd0d402cf05ce4b2cee4d3c401868038384c5 Mon Sep 17 00:00:00 2001 From: mvn23 Date: Mon, 30 Apr 2018 11:10:28 +0200 Subject: [PATCH 2/2] 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 5e1e754684fd4..9fdf8debc7716 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -110,10 +110,12 @@ def state_attributes(self): ATTR_WEATHER_TEMPERATURE: show_temp( self.hass, self.temperature, self.temperature_unit, self.precision), - ATTR_WEATHER_HUMIDITY: (round(self.humidity) if self.humidity - else None) } + 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