This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -14,100 +14,111 @@ NOW = datetime(2016, 6, 9, 1, tzinfo=dt_util.UTC)
@asyncio.coroutine
def test_default_setup(hass, aioclient_mock):
"""Test the default setup."""
aioclient_mock.get('https://aa015h6buqvih86i1.api.met.no/'
'weatherapi/locationforecast/1.9/',
text=load_fixture('yr.no.json'))
config = {'platform': 'yr',
'elevation': 0}
aioclient_mock.get(
"https://aa015h6buqvih86i1.api.met.no/" "weatherapi/locationforecast/1.9/",
text=load_fixture("yr.no.json"),
)
config = {"platform": "yr", "elevation": 0}
hass.allow_pool = True
with patch('homeassistant.components.yr.sensor.dt_util.utcnow',
return_value=NOW), assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {'sensor': config})
with patch(
"homeassistant.components.yr.sensor.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_symbol')
state = hass.states.get("sensor.yr_symbol")
assert state.state == '3'
assert state.attributes.get('unit_of_measurement') is None
assert state.state == "3"
assert state.attributes.get("unit_of_measurement") is None
@asyncio.coroutine
def test_custom_setup(hass, aioclient_mock):
"""Test a custom setup."""
aioclient_mock.get('https://aa015h6buqvih86i1.api.met.no/'
'weatherapi/locationforecast/1.9/',
text=load_fixture('yr.no.json'))
aioclient_mock.get(
"https://aa015h6buqvih86i1.api.met.no/" "weatherapi/locationforecast/1.9/",
text=load_fixture("yr.no.json"),
)
config = {'platform': 'yr',
'elevation': 0,
'monitored_conditions': [
'pressure',
'windDirection',
'humidity',
'fog',
'windSpeed']}
config = {
"platform": "yr",
"elevation": 0,
"monitored_conditions": [
"pressure",
"windDirection",
"humidity",
"fog",
"windSpeed",
],
}
hass.allow_pool = True
with patch('homeassistant.components.yr.sensor.dt_util.utcnow',
return_value=NOW), assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {'sensor': config})
with patch(
"homeassistant.components.yr.sensor.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 == '1009.3'
state = hass.states.get("sensor.yr_pressure")
assert state.attributes.get("unit_of_measurement") == "hPa"
assert state.state == "1009.3"
state = hass.states.get('sensor.yr_wind_direction')
assert state.attributes.get('unit_of_measurement') == '°'
assert state.state == '103.6'
state = hass.states.get("sensor.yr_wind_direction")
assert state.attributes.get("unit_of_measurement") == "°"
assert state.state == "103.6"
state = hass.states.get('sensor.yr_humidity')
assert state.attributes.get('unit_of_measurement') == '%'
assert state.state == '55.5'
state = hass.states.get("sensor.yr_humidity")
assert state.attributes.get("unit_of_measurement") == "%"
assert state.state == "55.5"
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_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.5'
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'))
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']}
config = {
"platform": "yr",
"elevation": 0,
"forecast": 24,
"monitored_conditions": [
"pressure",
"windDirection",
"humidity",
"fog",
"windSpeed",
],
}
hass.allow_pool = True
with patch('homeassistant.components.yr.sensor.dt_util.utcnow',
return_value=NOW), assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {'sensor': config})
with patch(
"homeassistant.components.yr.sensor.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_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_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_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_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'
state = hass.states.get("sensor.yr_wind_speed")
assert state.attributes.get("unit_of_measurement") == "m/s"
assert state.state == "3.6"