2016-10-25 04:53:03 +00:00
|
|
|
"""The tests for the Weather component."""
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from homeassistant.components import weather
|
|
|
|
from homeassistant.components.weather import (
|
2019-07-31 19:25:30 +00:00
|
|
|
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_CONDITION,
|
|
|
|
ATTR_FORECAST_PRECIPITATION,
|
|
|
|
ATTR_FORECAST_TEMP,
|
|
|
|
ATTR_FORECAST_TEMP_LOW,
|
|
|
|
)
|
2016-10-25 04:53:03 +00:00
|
|
|
from homeassistant.util.unit_system import METRIC_SYSTEM
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2016-10-25 04:53:03 +00:00
|
|
|
|
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
|
|
|
|
|
|
class TestWeather(unittest.TestCase):
|
|
|
|
"""Test the Weather component."""
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-10-25 04:53:03 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
self.hass.config.units = METRIC_SYSTEM
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass, weather.DOMAIN, {"weather": {"platform": "demo"}}
|
|
|
|
)
|
2016-10-25 04:53:03 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""Stop down everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_attributes(self):
|
|
|
|
"""Test weather attributes."""
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("weather.demo_weather_south")
|
2016-10-25 04:53:03 +00:00
|
|
|
assert state is not None
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "sunny"
|
2016-10-25 04:53:03 +00:00
|
|
|
|
|
|
|
data = state.attributes
|
2017-11-14 09:36:18 +00:00
|
|
|
assert data.get(ATTR_WEATHER_TEMPERATURE) == 21.6
|
2016-10-25 04:53:03 +00:00
|
|
|
assert data.get(ATTR_WEATHER_HUMIDITY) == 92
|
|
|
|
assert data.get(ATTR_WEATHER_PRESSURE) == 1099
|
|
|
|
assert data.get(ATTR_WEATHER_WIND_SPEED) == 0.5
|
|
|
|
assert data.get(ATTR_WEATHER_WIND_BEARING) is None
|
|
|
|
assert data.get(ATTR_WEATHER_OZONE) is None
|
2019-07-31 19:25:30 +00:00
|
|
|
assert data.get(ATTR_WEATHER_ATTRIBUTION) == "Powered by Home Assistant"
|
|
|
|
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_CONDITION) == "rainy"
|
2018-04-29 15:50:49 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_PRECIPITATION) == 1
|
2017-02-20 00:42:12 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP) == 22
|
2018-04-29 15:50:49 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[0].get(ATTR_FORECAST_TEMP_LOW) == 15
|
2019-07-31 19:25:30 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_CONDITION) == "fog"
|
|
|
|
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_PRECIPITATION) == 0.2
|
2017-02-20 00:42:12 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP) == 21
|
2018-04-29 15:50:49 +00:00
|
|
|
assert data.get(ATTR_FORECAST)[6].get(ATTR_FORECAST_TEMP_LOW) == 12
|
2017-02-20 00:42:12 +00:00
|
|
|
assert len(data.get(ATTR_FORECAST)) == 7
|
2016-10-25 04:53:03 +00:00
|
|
|
|
|
|
|
def test_temperature_convert(self):
|
|
|
|
"""Test temperature conversion."""
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("weather.demo_weather_north")
|
2016-10-25 04:53:03 +00:00
|
|
|
assert state is not None
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "rainy"
|
2016-10-25 04:53:03 +00:00
|
|
|
|
|
|
|
data = state.attributes
|
2017-11-14 09:36:18 +00:00
|
|
|
assert data.get(ATTR_WEATHER_TEMPERATURE) == -24
|