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

Ecobee: convert visibility/wind_speed into native units #11136

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 16 additions & 9 deletions homeassistant/components/weather/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from homeassistant.components import ecobee
from homeassistant.components.weather import (
WeatherEntity, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
from homeassistant.const import (TEMP_FAHRENHEIT)

from homeassistant.const import (TEMP_FAHRENHEIT, LENGTH_MILES)

DEPENDENCIES = ['ecobee']

Expand All @@ -32,19 +31,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for index in range(len(data.ecobee.thermostats)):
thermostat = data.ecobee.get_thermostat(index)
if 'weather' in thermostat:
dev.append(EcobeeWeather(thermostat['name'], index))

dev.append(EcobeeWeather(hass, thermostat['name'], index))
add_devices(dev, True)


class EcobeeWeather(WeatherEntity):
"""Representation of Ecobee weather data."""

def __init__(self, name, index):
def __init__(self, hass, name, index):
"""Initialize the sensor."""
self._name = name
self._index = index
self.weather = None
self.units = hass.config.units

def get_forecast(self, index, param):
"""Retrieve forecast parameter."""
Expand Down Expand Up @@ -100,15 +99,21 @@ def humidity(self):
def visibility(self):
"""Return the visibility."""
try:
return int(self.get_forecast(0, 'visibility'))
# Visibility is in miles * 1000
return self.units.length(
float(self.get_forecast(0, 'visibility')) / 1000,
LENGTH_MILES)
except ValueError:
return None

@property
def wind_speed(self):
"""Return the wind speed."""
try:
return int(self.get_forecast(0, 'windSpeed'))
# Speed is in mph * 1000
return self.units.length(
float(self.get_forecast(0, 'windSpeed')) / 1000,
LENGTH_MILES)
except ValueError:
return None

Expand Down Expand Up @@ -148,9 +153,11 @@ def forecast(self):
if day['pressure'] != MISSING_DATA:
forecast[ATTR_FORECAST_PRESSURE] = int(day['pressure'])
if day['windSpeed'] != MISSING_DATA:
forecast[ATTR_FORECAST_WIND_SPEED] = int(day['windSpeed'])
forecast[ATTR_FORECAST_WIND_SPEED] = self.units.length(
float(day['windSpeed']) / 1000, LENGTH_MILES)
if day['visibility'] != MISSING_DATA:
forecast[ATTR_FORECAST_WIND_SPEED] = int(day['visibility'])
forecast[ATTR_FORECAST_WIND_SPEED] = self.units.length(
float(day['visibility']) / 1000, LENGTH_MILES)
if day['relativeHumidity'] != MISSING_DATA:
forecast[ATTR_FORECAST_HUMIDITY] = \
int(day['relativeHumidity'])
Expand Down