Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions homeassistant/components/weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

ATTR_CONDITION_CLASS = 'condition_class'
ATTR_FORECAST = 'forecast'
ATTR_FORECAST_CONDITION = 'condition'
ATTR_FORECAST_PRECIPITATION = 'precipitation'
ATTR_FORECAST_TEMP = 'temperature'
ATTR_FORECAST_TEMP_LOW = 'templow'
ATTR_FORECAST_TIME = 'datetime'
ATTR_WEATHER_ATTRIBUTION = 'attribution'
ATTR_WEATHER_HUMIDITY = 'humidity'
Expand Down Expand Up @@ -144,6 +147,10 @@ def state_attributes(self):
forecast_entry[ATTR_FORECAST_TEMP] = show_temp(
self.hass, forecast_entry[ATTR_FORECAST_TEMP],
self.temperature_unit, self.precision)
if ATTR_FORECAST_TEMP_LOW in forecast_entry:
forecast_entry[ATTR_FORECAST_TEMP_LOW] = show_temp(
self.hass, forecast_entry[ATTR_FORECAST_TEMP_LOW],
self.temperature_unit, self.precision)
forecast.append(forecast_entry)

data[ATTR_FORECAST] = forecast
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/weather/buienradar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import voluptuous as vol

from homeassistant.components.weather import (
WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_CONDITION,
ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME)
from homeassistant.const import \
CONF_NAME, TEMP_CELSIUS, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.helpers import config_validation as cv
Expand All @@ -28,9 +29,6 @@

CONF_FORECAST = 'forecast'

ATTR_FORECAST_CONDITION = 'condition'
ATTR_FORECAST_TEMP_LOW = 'templow'


CONDITION_CLASSES = {
'cloudy': ['c', 'p'],
Expand Down
18 changes: 14 additions & 4 deletions homeassistant/components/weather/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from datetime import datetime, timedelta

from homeassistant.components.weather import (
WeatherEntity, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
WeatherEntity, ATTR_FORECAST_CONDITION, ATTR_FORECAST_PRECIPITATION,
ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME)
from homeassistant.const import (TEMP_CELSIUS, TEMP_FAHRENHEIT)

CONDITION_CLASSES = {
Expand All @@ -32,9 +33,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Demo weather."""
add_devices([
DemoWeather('South', 'Sunshine', 21.6414, 92, 1099, 0.5, TEMP_CELSIUS,
[22, 19, 15, 12, 14, 18, 21]),
[['rainy', 1, 22, 15], ['rainy', 5, 19, 8],
['cloudy', 0, 15, 9], ['sunny', 0, 12, 6],
['partlycloudy', 2, 14, 7], ['rainy', 15, 18, 7],
['fog', 0.2, 21, 12]]),
DemoWeather('North', 'Shower rain', -12, 54, 987, 4.8, TEMP_FAHRENHEIT,
[-10, -13, -18, -23, -19, -14, -9])
[['snowy', 2, -10, -15], ['partlycloudy', 1, -13, -14],
['sunny', 0, -18, -22], ['sunny', 0.1, -23, -23],
['snowy', 4, -19, -20], ['sunny', 0.3, -14, -19],
['sunny', 0, -9, -12]])
])


Expand Down Expand Up @@ -108,7 +115,10 @@ def forecast(self):
for entry in self._forecast:
data_dict = {
ATTR_FORECAST_TIME: reftime.isoformat(),
ATTR_FORECAST_TEMP: entry
ATTR_FORECAST_CONDITION: entry[0],
ATTR_FORECAST_PRECIPITATION: entry[1],
ATTR_FORECAST_TEMP: entry[2],
ATTR_FORECAST_TEMP_LOW: entry[3]
}
reftime = reftime + timedelta(hours=4)
forecast_data.append(data_dict)
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/weather/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"""
from homeassistant.components import ecobee
from homeassistant.components.weather import (
WeatherEntity, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
WeatherEntity, ATTR_FORECAST_CONDITION, ATTR_FORECAST_TEMP,
ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_TIME)
from homeassistant.const import (TEMP_FAHRENHEIT)


DEPENDENCIES = ['ecobee']

ATTR_FORECAST_CONDITION = 'condition'
ATTR_FORECAST_TEMP_LOW = 'templow'
ATTR_FORECAST_TEMP_HIGH = 'temphigh'
ATTR_FORECAST_PRESSURE = 'pressure'
ATTR_FORECAST_VISIBILITY = 'visibility'
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/weather/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import voluptuous as vol

from homeassistant.components.weather import (
ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity)
ATTR_FORECAST_CONDITION, ATTR_FORECAST_PRECIPITATION, ATTR_FORECAST_TEMP,
ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity)
from homeassistant.const import (
CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, STATE_UNKNOWN,
TEMP_CELSIUS)
Expand All @@ -21,7 +22,6 @@

_LOGGER = logging.getLogger(__name__)

ATTR_FORECAST_CONDITION = 'condition'
ATTRIBUTION = 'Data provided by OpenWeatherMap'

DEFAULT_NAME = 'OpenWeatherMap'
Expand Down Expand Up @@ -144,6 +144,7 @@ def forecast(self):
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
ATTR_FORECAST_TEMP:
entry.get_temperature('celsius').get('temp'),
ATTR_FORECAST_PRECIPITATION: entry.get_rain().get('3h'),
ATTR_FORECAST_CONDITION:
[k for k, v in CONDITION_CLASSES.items()
if entry.get_weather_code() in v][0]
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/weather/yweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import voluptuous as vol

from homeassistant.components.weather import (
ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity)
ATTR_FORECAST_CONDITION, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW,
ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity)
from homeassistant.const import CONF_NAME, STATE_UNKNOWN, TEMP_CELSIUS
import homeassistant.helpers.config_validation as cv

Expand All @@ -20,10 +21,8 @@

DATA_CONDITION = 'yahoo_condition'

ATTR_FORECAST_CONDITION = 'condition'
ATTRIBUTION = "Weather details provided by Yahoo! Inc."

ATTR_FORECAST_TEMP_LOW = 'templow'

CONF_WOEID = 'woeid'

Expand Down
12 changes: 11 additions & 1 deletion tests/components/weather/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from homeassistant.components.weather import (
ATTR_WEATHER_ATTRIBUTION, ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_OZONE,
ATTR_WEATHER_PRESSURE, ATTR_WEATHER_TEMPERATURE, ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_SPEED, ATTR_FORECAST, ATTR_FORECAST_TEMP)
ATTR_WEATHER_WIND_SPEED, ATTR_FORECAST, ATTR_FORECAST_CONDITION,
ATTR_FORECAST_PRECIPITATION, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW)
from homeassistant.util.unit_system import METRIC_SYSTEM
from homeassistant.setup import setup_component

Expand Down Expand Up @@ -45,8 +46,17 @@ def test_attributes(self):
assert data.get(ATTR_WEATHER_OZONE) is None
assert data.get(ATTR_WEATHER_ATTRIBUTION) == \
'Powered by Home Assistant'
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_CONDITION) == \
'rainy'
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION) == 1
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP) == 22
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP_LOW) == 15
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_CONDITION) == \
'fog'
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION) \
== 0.2
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP) == 21
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP_LOW) == 12
assert len(data.get(ATTR_FORECAST)) == 7

def test_temperature_convert(self):
Expand Down