Add severe weather sensor to Dark Sky (#22701)
* Add severe weather alert sensor to Dark Sky * fixup test case * address review comments and fixup testcases * address comments, fix assertion order * remove extra line * remove index increment
This commit is contained in:
parent
b52848d376
commit
de3d28d9d5
3 changed files with 146 additions and 9 deletions
|
@ -21,7 +21,8 @@ VALID_CONFIG_MINIMAL = {
|
|||
'api_key': 'foo',
|
||||
'forecast': [1, 2],
|
||||
'hourly_forecast': [1, 2],
|
||||
'monitored_conditions': ['summary', 'icon', 'temperature_high'],
|
||||
'monitored_conditions': ['summary', 'icon', 'temperature_high',
|
||||
'alerts'],
|
||||
'scan_interval': timedelta(seconds=120),
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +48,7 @@ VALID_CONFIG_LANG_DE = {
|
|||
'language': 'de',
|
||||
'monitored_conditions': ['summary', 'icon', 'temperature_high',
|
||||
'minutely_summary', 'hourly_summary',
|
||||
'daily_summary', 'humidity', ],
|
||||
'daily_summary', 'humidity', 'alerts'],
|
||||
'scan_interval': timedelta(seconds=120),
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +65,18 @@ INVALID_CONFIG_LANG = {
|
|||
}
|
||||
}
|
||||
|
||||
VALID_CONFIG_ALERTS = {
|
||||
'sensor': {
|
||||
'platform': 'darksky',
|
||||
'api_key': 'foo',
|
||||
'forecast': [1, 2],
|
||||
'hourly_forecast': [1, 2],
|
||||
'monitored_conditions': ['summary', 'icon', 'temperature_high',
|
||||
'alerts'],
|
||||
'scan_interval': timedelta(seconds=120),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def load_forecastMock(key, lat, lon,
|
||||
units, lang): # pylint: disable=invalid-name
|
||||
|
@ -149,6 +162,15 @@ class TestDarkSkySetup(unittest.TestCase):
|
|||
)
|
||||
assert not response
|
||||
|
||||
@MockDependency('forecastio')
|
||||
@patch('forecastio.load_forecast', new=load_forecastMock)
|
||||
def test_setup_with_alerts_config(self, mock_forecastio):
|
||||
"""Test the platform setup with alert configuration."""
|
||||
setup_component(self.hass, 'sensor', VALID_CONFIG_ALERTS)
|
||||
|
||||
state = self.hass.states.get('sensor.dark_sky_alerts')
|
||||
assert state.state == '0'
|
||||
|
||||
@requests_mock.Mocker()
|
||||
@patch('forecastio.api.get_forecast', wraps=forecastio.api.get_forecast)
|
||||
def test_setup(self, mock_req, mock_get_forecast):
|
||||
|
@ -161,10 +183,12 @@ class TestDarkSkySetup(unittest.TestCase):
|
|||
|
||||
assert mock_get_forecast.called
|
||||
assert mock_get_forecast.call_count == 1
|
||||
assert len(self.hass.states.entity_ids()) == 12
|
||||
assert len(self.hass.states.entity_ids()) == 13
|
||||
|
||||
state = self.hass.states.get('sensor.dark_sky_summary')
|
||||
assert state is not None
|
||||
assert state.state == 'Clear'
|
||||
assert state.attributes.get('friendly_name') == \
|
||||
'Dark Sky Summary'
|
||||
state = self.hass.states.get('sensor.dark_sky_alerts')
|
||||
assert state.state == '2'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue