Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues from review of ecobee weather component #10903

Merged
merged 2 commits into from
Dec 2, 2017
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
51 changes: 36 additions & 15 deletions homeassistant/components/weather/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/weather.ecobee/
"""
import logging
from homeassistant.components import ecobee
from homeassistant.components.weather import (
WeatherEntity, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
Expand Down Expand Up @@ -52,8 +51,8 @@ def get_forecast(self, index, param):
try:
forecast = self.weather['forecasts'][index]
return forecast[param]
except (ValueError, IndexError):
return STATE_UNKNOWN
except (ValueError, IndexError, KeyError):
raise ValueError

@property
def name(self):
Expand All @@ -63,12 +62,18 @@ def name(self):
@property
def condition(self):
"""Return the current condition."""
return self.get_forecast(0, 'condition')
try:
return self.get_forecast(0, 'condition')
except ValueError:
return STATE_UNKNOWN
Copy link
Member

Choose a reason for hiding this comment

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

Usually unknown attributes are not populated in the state attributes at all. So if we want to follow that, we should return None in that case.


@property
def temperature(self):
"""Return the temperature."""
return float(self.get_forecast(0, 'temperature')) / 10
try:
return float(self.get_forecast(0, 'temperature')) / 10
except ValueError:
return STATE_UNKNOWN

@property
def temperature_unit(self):
Expand All @@ -78,34 +83,51 @@ def temperature_unit(self):
@property
def pressure(self):
"""Return the pressure."""
return int(self.get_forecast(0, 'pressure'))
try:
return int(self.get_forecast(0, 'pressure'))
except ValueError:
return STATE_UNKNOWN

@property
def humidity(self):
"""Return the humidity."""
return int(self.get_forecast(0, 'relativeHumidity'))
try:
return int(self.get_forecast(0, 'relativeHumidity'))
except ValueError:
return STATE_UNKNOWN

@property
def visibility(self):
"""Return the visibility."""
return int(self.get_forecast(0, 'visibility'))
try:
return int(self.get_forecast(0, 'visibility'))
except ValueError:
return STATE_UNKNOWN

@property
def wind_speed(self):
"""Return the wind speed."""
return int(self.get_forecast(0, 'windSpeed'))
try:
return int(self.get_forecast(0, 'windSpeed'))
except ValueError:
return STATE_UNKNOWN

@property
def wind_bearing(self):
"""Return the wind direction."""
return int(self.get_forecast(0, 'windBearing'))
try:
return int(self.get_forecast(0, 'windBearing'))
except ValueError:
return STATE_UNKNOWN

@property
def attribution(self):
"""Return the attribution."""
station = self.weather['weatherStation']
time = self.weather['timestamp']
return "Ecobee weather provided by " + station + " at " + time
if self.weather:
station = self.weather.get('weatherStation', "UNKNOWN")
time = self.weather.get('timestamp', "UNKNOWN")
return "Ecobee weather provided by {} at {}".format(station, time)
return STATE_UNKNOWN

@property
def forecast(self):
Expand Down Expand Up @@ -134,7 +156,7 @@ def forecast(self):
int(day['relativeHumidity'])
forecasts.append(forecast)
return forecasts
except (ValueError, IndexError):
except (ValueError, IndexError, KeyError):
return STATE_UNKNOWN

def update(self):
Expand All @@ -143,4 +165,3 @@ def update(self):
data.update()
thermostat = data.ecobee.get_thermostat(self._index)
self.weather = thermostat.get('weather', None)
logging.error("Weather Update")