2019-06-19 21:41:27 +00:00
|
|
|
"""Test Met weather entity."""
|
|
|
|
|
|
|
|
|
|
|
|
async def test_tracking_home(hass, mock_weather):
|
|
|
|
"""Test we track home."""
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.config_entries.flow.async_init("met", context={"source": "onboarding"})
|
2019-06-19 21:41:27 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(hass.states.async_entity_ids("weather")) == 1
|
2019-06-19 21:41:27 +00:00
|
|
|
assert len(mock_weather.mock_calls) == 3
|
|
|
|
|
|
|
|
# Test we track config
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.config.async_update(latitude=10, longitude=20)
|
2019-06-19 21:41:27 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_weather.mock_calls) == 6
|
|
|
|
|
|
|
|
entry = hass.config_entries.async_entries()[0]
|
|
|
|
await hass.config_entries.async_remove(entry.entry_id)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(hass.states.async_entity_ids("weather")) == 0
|
2019-06-19 21:41:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_not_tracking_home(hass, mock_weather):
|
|
|
|
"""Test when we not track home."""
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.config_entries.flow.async_init(
|
|
|
|
"met",
|
|
|
|
context={"source": "user"},
|
|
|
|
data={"name": "Somewhere", "latitude": 10, "longitude": 20, "elevation": 0},
|
|
|
|
)
|
2019-06-19 21:41:27 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(hass.states.async_entity_ids("weather")) == 1
|
2019-06-19 21:41:27 +00:00
|
|
|
assert len(mock_weather.mock_calls) == 3
|
|
|
|
|
|
|
|
# Test we do not track config
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.config.async_update(latitude=10, longitude=20)
|
2019-06-19 21:41:27 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_weather.mock_calls) == 3
|
|
|
|
|
|
|
|
entry = hass.config_entries.async_entries()[0]
|
|
|
|
await hass.config_entries.async_remove(entry.entry_id)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(hass.states.async_entity_ids("weather")) == 0
|