Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if self.humidity check will not work with falsy values like 0.0.

Write something like if self.humidity is not None or, even better, make it an additional check like the other attributes:

data = {
            ATTR_WEATHER_TEMPERATURE: show_temp(
                self.hass, self.temperature, self.temperature_unit,
                self.precision),
        }

        humidity = self.humidity
        if humidity is not None:
            data[ATTR_WEATHER_HUMIDITY] = humidity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right, hadn't thought about that.
Even though humidity is probably never going to be 0, we should definitely take it into account.
Fixed in the commit below.

else None)
}

ozone = self.ozone
Expand Down