1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Added the ability to Weather Underground to track severe weather alerts (#3505)

*  Added the ability to Weather Underground to track severe weather alerts

*   * Added message on the advisory attr

  * Updated tests

* * Making use of guard clause

* Checking multiple_alerts prior loop

* Using a better way to create dict

* Fixed issue to set to None only the object that failed

* Added unittest

* Split update() method to different calls with their one throttle control to minimize API calls

* Updated unittest and make sure the alert sensor will not return 'unknown' status'

* Removed update() method from state property

* Branch rebased and include Weather Underground attribution

* Update wunderground.py
This commit is contained in:
Marcelo Moreira de Mello
2016-10-15 00:35:27 -04:00
committed by Paulus Schoutsen
parent 1bf5554017
commit 6fcb1b548e
2 changed files with 86 additions and 24 deletions

View File

@@ -11,7 +11,7 @@ VALID_CONFIG_PWS = {
'api_key': 'foo',
'pws_id': 'bar',
'monitored_conditions': [
'weather', 'feelslike_c'
'weather', 'feelslike_c', 'alerts'
]
}
@@ -19,17 +19,19 @@ VALID_CONFIG = {
'platform': 'wunderground',
'api_key': 'foo',
'monitored_conditions': [
'weather', 'feelslike_c'
'weather', 'feelslike_c', 'alerts'
]
}
FEELS_LIKE = '40'
WEATHER = 'Clear'
ICON_URL = 'http://icons.wxug.com/i/c/k/clear.gif'
ALERT_MESSAGE = 'This is a test alert message'
def mocked_requests_get(*args, **kwargs):
"""Mock requests.get invocations."""
# pylint: disable=too-few-public-methods
class MockResponse:
"""Class to represent a mocked response."""
@@ -61,26 +63,36 @@ def mocked_requests_get(*args, **kwargs):
"feelslike_c": FEELS_LIKE,
"weather": WEATHER,
"icon_url": ICON_URL
}
}, "alerts": [
{
"type": 'FLO',
"description": "Areal Flood Warning",
"date": "9:36 PM CDT on September 22, 2016",
"expires": "10:00 AM CDT on September 23, 2016",
"message": ALERT_MESSAGE,
},
],
}, 200)
else:
return MockResponse({
"response": {
"version": "0.1",
"termsofService":
"http://www.wunderground.com/weather/api/d/terms.html",
"features": {},
"error": {
"type": "keynotfound",
"description": "this key does not exist"
}
"response": {
"version": "0.1",
"termsofService":
"http://www.wunderground.com/weather/api/d/terms.html",
"features": {},
"error": {
"type": "keynotfound",
"description": "this key does not exist"
}
}, 200)
}
}, 200)
class TestWundergroundSetup(unittest.TestCase):
"""Test the WUnderground platform."""
# pylint: disable=invalid-name
DEVICES = []
def add_devices(self, devices):
@@ -107,14 +119,13 @@ class TestWundergroundSetup(unittest.TestCase):
self.add_devices, None))
self.assertTrue(
wunderground.setup_platform(self.hass, VALID_CONFIG,
self.add_devices,
None))
self.add_devices, None))
invalid_config = {
'platform': 'wunderground',
'api_key': 'BOB',
'pws_id': 'bar',
'monitored_conditions': [
'weather', 'feelslike_c'
'weather', 'feelslike_c', 'alerts'
]
}
@@ -128,11 +139,17 @@ class TestWundergroundSetup(unittest.TestCase):
wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices,
None)
for device in self.DEVICES:
device.update()
self.assertTrue(str(device.name).startswith('PWS_'))
if device.name == 'PWS_weather':
self.assertEqual(ICON_URL, device.entity_picture)
self.assertEqual(WEATHER, device.state)
self.assertIsNone(device.unit_of_measurement)
elif device.name == 'PWS_alerts':
self.assertEqual(1, device.state)
self.assertEqual(ALERT_MESSAGE,
device.device_state_attributes['Message'])
self.assertIsNone(device.entity_picture)
else:
self.assertIsNone(device.entity_picture)
self.assertEqual(FEELS_LIKE, device.state)