Merge pull request #1089 from balloob/yr

Added and fixed yr tests
This commit is contained in:
Paulus Schoutsen 2016-02-01 08:11:18 -08:00
commit d9aff0c76d
2 changed files with 27 additions and 17 deletions

View File

@ -28,7 +28,7 @@ SENSOR_TYPES = {
'temperature': ['Temperature', '°C'], 'temperature': ['Temperature', '°C'],
'windSpeed': ['Wind speed', 'm/s'], 'windSpeed': ['Wind speed', 'm/s'],
'windGust': ['Wind gust', 'm/s'], 'windGust': ['Wind gust', 'm/s'],
'pressure': ['Pressure', 'mbar'], 'pressure': ['Pressure', 'hPa'],
'windDirection': ['Wind direction', '°'], 'windDirection': ['Wind direction', '°'],
'humidity': ['Humidity', '%'], 'humidity': ['Humidity', '%'],
'fog': ['Fog', '%'], 'fog': ['Fog', '%'],

View File

@ -43,12 +43,17 @@ class TestSensorYr:
state = self.hass.states.get('sensor.yr_symbol') state = self.hass.states.get('sensor.yr_symbol')
assert '46' == state.state
assert state.state.isnumeric() assert state.state.isnumeric()
assert state.attributes.get('unit_of_measurement') is None assert state.attributes.get('unit_of_measurement') is None
def test_custom_setup(self, betamax_session): def test_custom_setup(self, betamax_session):
now = datetime(2016, 1, 5, 1, tzinfo=dt_util.UTC)
with patch('homeassistant.components.sensor.yr.requests.Session', with patch('homeassistant.components.sensor.yr.requests.Session',
return_value=betamax_session): return_value=betamax_session):
with patch('homeassistant.components.sensor.yr.dt_util.utcnow',
return_value=now):
assert sensor.setup(self.hass, { assert sensor.setup(self.hass, {
'sensor': { 'sensor': {
'platform': 'yr', 'platform': 'yr',
@ -64,16 +69,21 @@ class TestSensorYr:
}) })
state = self.hass.states.get('sensor.yr_pressure') state = self.hass.states.get('sensor.yr_pressure')
assert 'hPa', state.attributes.get('unit_of_measurement') assert 'hPa' == state.attributes.get('unit_of_measurement')
assert '1025.1' == state.state
state = self.hass.states.get('sensor.yr_wind_direction') state = self.hass.states.get('sensor.yr_wind_direction')
assert '°', state.attributes.get('unit_of_measurement') assert '°'== state.attributes.get('unit_of_measurement')
assert '81.8' == state.state
state = self.hass.states.get('sensor.yr_humidity') state = self.hass.states.get('sensor.yr_humidity')
assert '%', state.attributes.get('unit_of_measurement') assert '%' == state.attributes.get('unit_of_measurement')
assert '79.6' == state.state
state = self.hass.states.get('sensor.yr_fog') state = self.hass.states.get('sensor.yr_fog')
assert '%', state.attributes.get('unit_of_measurement') assert '%' == state.attributes.get('unit_of_measurement')
assert '0.0' == state.state
state = self.hass.states.get('sensor.yr_wind_speed') state = self.hass.states.get('sensor.yr_wind_speed')
assert 'm/s', state.attributes.get('unit_of_measurement') assert 'm/s', state.attributes.get('unit_of_measurement')
assert '4.3' == state.state