Fix TypeError on round(self.humidity) (fixes #13116)#14174
Merged
balloob merged 2 commits intohome-assistant:devfrom Apr 30, 2018
Merged
Fix TypeError on round(self.humidity) (fixes #13116)#14174balloob merged 2 commits intohome-assistant:devfrom
balloob merged 2 commits intohome-assistant:devfrom
Conversation
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.
Contributor
OttoWinter
reviewed
Apr 30, 2018
Member
OttoWinter
left a comment
There was a problem hiding this comment.
Nice 👍 Just a quick comment about falsy values.
| self.hass, self.temperature, self.temperature_unit, | ||
| self.precision), | ||
| ATTR_WEATHER_HUMIDITY: round(self.humidity) | ||
| ATTR_WEATHER_HUMIDITY: (round(self.humidity) if self.humidity |
Member
There was a problem hiding this comment.
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
Contributor
Author
There was a problem hiding this comment.
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.
As per the suggestion from @OttoWinter, rewrite to avoid matching e.g. 0.0 as false.
balloob
approved these changes
Apr 30, 2018
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During init, some (most?) platforms postpone the first update for a while. This produces errors in the log as home assistant is trying to round() uninitialised variables. This commit fixes that
Description:
fixes #13116
Checklist:
tox.