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 all commits
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
55 changes: 38 additions & 17 deletions homeassistant/components/weather/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
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)
from homeassistant.const import (STATE_UNKNOWN, TEMP_FAHRENHEIT)
from homeassistant.const import (TEMP_FAHRENHEIT)


DEPENDENCIES = ['ecobee']
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 None

@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 None

@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 None

@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 None

@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 None

@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 None

@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 None

@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 None

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

def update(self):
"""Get the latest state of the sensor."""
data = ecobee.NETWORK
data.update()
thermostat = data.ecobee.get_thermostat(self._index)
self.weather = thermostat.get('weather', None)
logging.error("Weather Update")