Added some extra options to Weather Underground component (#4306)
* Added some extra options to Weather Underground component * Added Location and Elevation options * Fixed if statement * Fixed lint * Updated tests including elevation and location * Update wunderground.py
This commit is contained in:
parent
01a6c1c1c8
commit
5e44934e7e
2 changed files with 61 additions and 26 deletions
|
@ -31,33 +31,44 @@ MIN_TIME_BETWEEN_UPDATES_OBSERVATION = timedelta(minutes=5)
|
||||||
# Sensor types are defined like: Name, units
|
# Sensor types are defined like: Name, units
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'alerts': ['Alerts', None],
|
'alerts': ['Alerts', None],
|
||||||
'weather': ['Weather Summary', None],
|
'dewpoint_c': ['Dewpoint (°C)', TEMP_CELSIUS],
|
||||||
'station_id': ['Station ID', None],
|
'dewpoint_f': ['Dewpoint (°F)', TEMP_FAHRENHEIT],
|
||||||
|
'dewpoint_string': ['Dewpoint Summary', None],
|
||||||
'feelslike_c': ['Feels Like (°C)', TEMP_CELSIUS],
|
'feelslike_c': ['Feels Like (°C)', TEMP_CELSIUS],
|
||||||
'feelslike_f': ['Feels Like (°F)', TEMP_FAHRENHEIT],
|
'feelslike_f': ['Feels Like (°F)', TEMP_FAHRENHEIT],
|
||||||
'feelslike_string': ['Feels Like', None],
|
'feelslike_string': ['Feels Like', None],
|
||||||
'heat_index_c': ['Dewpoint (°C)', TEMP_CELSIUS],
|
'heat_index_c': ['Dewpoint (°C)', TEMP_CELSIUS],
|
||||||
'heat_index_f': ['Dewpoint (°F)', TEMP_FAHRENHEIT],
|
'heat_index_f': ['Dewpoint (°F)', TEMP_FAHRENHEIT],
|
||||||
'heat_index_string': ['Heat Index Summary', None],
|
'heat_index_string': ['Heat Index Summary', None],
|
||||||
'dewpoint_c': ['Dewpoint (°C)', TEMP_CELSIUS],
|
'elevation': ['Elevation', 'ft'],
|
||||||
'dewpoint_f': ['Dewpoint (°F)', TEMP_FAHRENHEIT],
|
'location': ['Location', None],
|
||||||
'dewpoint_string': ['Dewpoint Summary', None],
|
'observation_time': ['Observation Time', None],
|
||||||
'wind_kph': ['Wind Speed', 'kpH'],
|
'precip_1hr_in': ['Precipation 1hr', 'in'],
|
||||||
'wind_mph': ['Wind Speed', 'mpH'],
|
'precip_1hr_metric': ['Precipation 1hr', 'mm'],
|
||||||
'UV': ['UV', None],
|
'precip_1hr_string': ['Precipation 1hr', None],
|
||||||
'pressure_in': ['Pressure', 'in'],
|
|
||||||
'pressure_mb': ['Pressure', 'mbar'],
|
|
||||||
'wind_dir': ['Wind Direction', None],
|
|
||||||
'wind_string': ['Wind Summary', None],
|
|
||||||
'temp_c': ['Temperature (°C)', TEMP_CELSIUS],
|
|
||||||
'temp_f': ['Temperature (°F)', TEMP_FAHRENHEIT],
|
|
||||||
'relative_humidity': ['Relative Humidity', '%'],
|
|
||||||
'visibility_mi': ['Visibility (miles)', 'mi'],
|
|
||||||
'visibility_km': ['Visibility (km)', 'km'],
|
|
||||||
'precip_today_in': ['Precipation Today', 'in'],
|
'precip_today_in': ['Precipation Today', 'in'],
|
||||||
'precip_today_metric': ['Precipitation Today', 'mm'],
|
'precip_today_metric': ['Precipitation Today', 'mm'],
|
||||||
'precip_today_string': ['Precipitation today', None],
|
'precip_today_string': ['Precipitation today', None],
|
||||||
'solarradiation': ['Solar Radiation', None]
|
'pressure_in': ['Pressure', 'in'],
|
||||||
|
'pressure_mb': ['Pressure', 'mb'],
|
||||||
|
'pressure_trend': ['Pressure Trend', None],
|
||||||
|
'relative_humidity': ['Relative Humidity', '%'],
|
||||||
|
'station_id': ['Station ID', None],
|
||||||
|
'solarradiation': ['Solar Radiation', None],
|
||||||
|
'temperature_string': ['Temperature Summary', None],
|
||||||
|
'temp_c': ['Temperature (°C)', TEMP_CELSIUS],
|
||||||
|
'temp_f': ['Temperature (°F)', TEMP_FAHRENHEIT],
|
||||||
|
'UV': ['UV', None],
|
||||||
|
'visibility_km': ['Visibility (km)', 'km'],
|
||||||
|
'visibility_mi': ['Visibility (miles)', 'mi'],
|
||||||
|
'weather': ['Weather Summary', None],
|
||||||
|
'wind_degrees': ['Wind Degrees', None],
|
||||||
|
'wind_dir': ['Wind Direction', None],
|
||||||
|
'wind_gust_kph': ['Wind Gust', 'kpH'],
|
||||||
|
'wind_gust_mph': ['Wind Gust', 'mpH'],
|
||||||
|
'wind_kph': ['Wind Speed', 'kpH'],
|
||||||
|
'wind_mph': ['Wind Speed', 'mpH'],
|
||||||
|
'wind_string': ['Wind Summary', None],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Alert Attributes
|
# Alert Attributes
|
||||||
|
@ -112,7 +123,18 @@ class WUndergroundSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if self.rest.data and self._condition in self.rest.data:
|
if self.rest.data:
|
||||||
|
|
||||||
|
if self._condition == 'elevation' and \
|
||||||
|
self._condition in self.rest.data['observation_location']:
|
||||||
|
return self.rest.data['observation_location'][self._condition]\
|
||||||
|
.split()[0]
|
||||||
|
|
||||||
|
if self._condition == 'location' and \
|
||||||
|
'full' in self.rest.data['display_location']:
|
||||||
|
return self.rest.data['display_location']['full']
|
||||||
|
|
||||||
|
if self._condition in self.rest.data:
|
||||||
if self._condition == 'relative_humidity':
|
if self._condition == 'relative_humidity':
|
||||||
return int(self.rest.data[self._condition][:-1])
|
return int(self.rest.data[self._condition][:-1])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -11,7 +11,7 @@ VALID_CONFIG_PWS = {
|
||||||
'api_key': 'foo',
|
'api_key': 'foo',
|
||||||
'pws_id': 'bar',
|
'pws_id': 'bar',
|
||||||
'monitored_conditions': [
|
'monitored_conditions': [
|
||||||
'weather', 'feelslike_c', 'alerts'
|
'weather', 'feelslike_c', 'alerts', 'elevation', 'location'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ VALID_CONFIG = {
|
||||||
'platform': 'wunderground',
|
'platform': 'wunderground',
|
||||||
'api_key': 'foo',
|
'api_key': 'foo',
|
||||||
'monitored_conditions': [
|
'monitored_conditions': [
|
||||||
'weather', 'feelslike_c', 'alerts'
|
'weather', 'feelslike_c', 'alerts', 'elevation', 'location'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,16 @@ def mocked_requests_get(*args, **kwargs):
|
||||||
},
|
},
|
||||||
"feelslike_c": FEELS_LIKE,
|
"feelslike_c": FEELS_LIKE,
|
||||||
"weather": WEATHER,
|
"weather": WEATHER,
|
||||||
"icon_url": ICON_URL
|
"icon_url": ICON_URL,
|
||||||
|
"display_location": {
|
||||||
|
"city": "Holly Springs",
|
||||||
|
"country": "US",
|
||||||
|
"full": "Holly Springs, NC"
|
||||||
|
},
|
||||||
|
"observation_location": {
|
||||||
|
"elevation": "413 ft",
|
||||||
|
"full": "Twin Lake, Holly Springs, North Carolina"
|
||||||
|
},
|
||||||
}, "alerts": [
|
}, "alerts": [
|
||||||
{
|
{
|
||||||
"type": 'FLO',
|
"type": 'FLO',
|
||||||
|
@ -149,6 +158,10 @@ class TestWundergroundSetup(unittest.TestCase):
|
||||||
self.assertEqual(ALERT_MESSAGE,
|
self.assertEqual(ALERT_MESSAGE,
|
||||||
device.device_state_attributes['Message'])
|
device.device_state_attributes['Message'])
|
||||||
self.assertIsNone(device.entity_picture)
|
self.assertIsNone(device.entity_picture)
|
||||||
|
elif device.name == 'PWS_location':
|
||||||
|
self.assertEqual('Holly Springs, NC', device.state)
|
||||||
|
elif device.name == 'PWS_elevation':
|
||||||
|
self.assertEqual('413', device.state)
|
||||||
else:
|
else:
|
||||||
self.assertIsNone(device.entity_picture)
|
self.assertIsNone(device.entity_picture)
|
||||||
self.assertEqual(FEELS_LIKE, device.state)
|
self.assertEqual(FEELS_LIKE, device.state)
|
||||||
|
|
Loading…
Add table
Reference in a new issue