Add 'forecast' ability to yr weather sensor (#8650)

* Add forecast option to YR sensor

* Fix some style issues

* Fix linting
This commit is contained in:
Lukas Barth 2017-08-02 07:42:51 +02:00 committed by Paulus Schoutsen
parent 86c06ad76e
commit 47dad547eb
2 changed files with 100 additions and 35 deletions

View file

@ -69,3 +69,45 @@ def test_custom_setup(hass, aioclient_mock):
state = hass.states.get('sensor.yr_wind_speed')
assert state.attributes.get('unit_of_measurement') == 'm/s'
assert state.state == '3.5'
@asyncio.coroutine
def test_forecast_setup(hass, aioclient_mock):
"""Test a custom setup with 24h forecast."""
aioclient_mock.get('https://aa015h6buqvih86i1.api.met.no/'
'weatherapi/locationforecast/1.9/',
text=load_fixture('yr.no.json'))
config = {'platform': 'yr',
'elevation': 0,
'forecast': 24,
'monitored_conditions': [
'pressure',
'windDirection',
'humidity',
'fog',
'windSpeed']}
hass.allow_pool = True
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=NOW), assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {'sensor': config})
state = hass.states.get('sensor.yr_pressure')
assert state.attributes.get('unit_of_measurement') == 'hPa'
assert state.state == '1008.3'
state = hass.states.get('sensor.yr_wind_direction')
assert state.attributes.get('unit_of_measurement') == '°'
assert state.state == '148.9'
state = hass.states.get('sensor.yr_humidity')
assert state.attributes.get('unit_of_measurement') == '%'
assert state.state == '77.4'
state = hass.states.get('sensor.yr_fog')
assert state.attributes.get('unit_of_measurement') == '%'
assert state.state == '0.0'
state = hass.states.get('sensor.yr_wind_speed')
assert state.attributes.get('unit_of_measurement') == 'm/s'
assert state.state == '3.6'