2020-04-08 15:22:25 +00:00
|
|
|
"""Tests for init module."""
|
2020-04-16 14:15:55 +00:00
|
|
|
from homeassistant.components.nws.const import DOMAIN
|
|
|
|
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
|
2021-02-08 09:45:46 +00:00
|
|
|
from homeassistant.const import STATE_UNAVAILABLE
|
2020-04-08 15:22:25 +00:00
|
|
|
|
2020-04-16 14:15:55 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
from tests.components.nws.const import NWS_CONFIG
|
2020-04-08 15:22:25 +00:00
|
|
|
|
|
|
|
|
2020-04-16 14:15:55 +00:00
|
|
|
async def test_unload_entry(hass, mock_simple_nws):
|
|
|
|
"""Test that nws setup with config yaml."""
|
2020-08-27 11:56:20 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=NWS_CONFIG,
|
|
|
|
)
|
2020-04-16 14:15:55 +00:00
|
|
|
entry.add_to_hass(hass)
|
2020-04-08 15:22:25 +00:00
|
|
|
|
2020-04-16 14:15:55 +00:00
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
2020-04-12 22:19:22 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-09-30 14:53:33 +00:00
|
|
|
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 1
|
2020-04-16 14:15:55 +00:00
|
|
|
assert DOMAIN in hass.data
|
2020-04-12 22:19:22 +00:00
|
|
|
|
2020-04-08 15:22:25 +00:00
|
|
|
assert len(hass.data[DOMAIN]) == 1
|
2020-04-16 14:15:55 +00:00
|
|
|
entries = hass.config_entries.async_entries(DOMAIN)
|
|
|
|
assert len(entries) == 1
|
|
|
|
|
|
|
|
assert await hass.config_entries.async_unload(entries[0].entry_id)
|
2021-02-08 09:45:46 +00:00
|
|
|
entities = hass.states.async_entity_ids(WEATHER_DOMAIN)
|
|
|
|
assert len(entities) == 1
|
|
|
|
for entity in entities:
|
|
|
|
assert hass.states.get(entity).state == STATE_UNAVAILABLE
|
2020-04-16 14:15:55 +00:00
|
|
|
assert DOMAIN not in hass.data
|
2021-02-08 09:45:46 +00:00
|
|
|
|
|
|
|
assert await hass.config_entries.async_remove(entries[0].entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 0
|