mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Add config flow to nws and remove yaml configuration (#34267)
* add config flow to nws and remove yaml * Don't duplicate scan_time Co-Authored-By: J. Nick Koston <nick@koston.org> * Use _abort_if_unique_id_configured Co-Authored-By: J. Nick Koston <nick@koston.org> * fix abort * Add unavailable tests * update and use better strings * lint Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -1,92 +1,26 @@
|
||||
"""Tests for init module."""
|
||||
from homeassistant.components import nws
|
||||
from homeassistant.components.nws.const import CONF_STATION, DOMAIN
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.nws.const import DOMAIN
|
||||
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
|
||||
|
||||
from tests.common import assert_setup_component
|
||||
from tests.components.nws.const import MINIMAL_CONFIG
|
||||
|
||||
LATLON_CONFIG = {
|
||||
DOMAIN: [{CONF_API_KEY: "test", CONF_LATITUDE: 45.0, CONF_LONGITUDE: -75.0}]
|
||||
}
|
||||
FULL_CONFIG = {
|
||||
DOMAIN: [
|
||||
{
|
||||
CONF_API_KEY: "test",
|
||||
CONF_LATITUDE: 45.0,
|
||||
CONF_LONGITUDE: -75.0,
|
||||
CONF_STATION: "XYZ",
|
||||
}
|
||||
]
|
||||
}
|
||||
DUPLICATE_CONFIG = {
|
||||
DOMAIN: [
|
||||
{CONF_API_KEY: "test", CONF_LATITUDE: 45.0, CONF_LONGITUDE: -75.0},
|
||||
{CONF_API_KEY: "test", CONF_LATITUDE: 45.0, CONF_LONGITUDE: -75.0},
|
||||
]
|
||||
}
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.nws.const import NWS_CONFIG
|
||||
|
||||
|
||||
async def test_no_config(hass, mock_simple_nws):
|
||||
"""Test that nws does not setup with no config."""
|
||||
with assert_setup_component(0):
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
async def test_unload_entry(hass, mock_simple_nws):
|
||||
"""Test that nws setup with config yaml."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=NWS_CONFIG,)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 0
|
||||
|
||||
assert DOMAIN not in hass.data
|
||||
|
||||
|
||||
async def test_successful_minimal_config(hass, mock_simple_nws):
|
||||
"""Test that nws setup with minimal config."""
|
||||
hass.config.latitude = 40.0
|
||||
hass.config.longitude = -75.0
|
||||
with assert_setup_component(1, DOMAIN):
|
||||
assert await async_setup_component(hass, DOMAIN, MINIMAL_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 2
|
||||
|
||||
assert DOMAIN in hass.data
|
||||
assert nws.base_unique_id(40.0, -75.0) in hass.data[DOMAIN]
|
||||
|
||||
|
||||
async def test_successful_latlon_config(hass, mock_simple_nws):
|
||||
"""Test that nws setup with latlon config."""
|
||||
with assert_setup_component(1, DOMAIN):
|
||||
assert await async_setup_component(hass, DOMAIN, LATLON_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 2
|
||||
|
||||
assert DOMAIN in hass.data
|
||||
assert nws.base_unique_id(45.0, -75.0) in hass.data[DOMAIN]
|
||||
|
||||
|
||||
async def test_successful_full_config(hass, mock_simple_nws):
|
||||
"""Test that nws setup with full config."""
|
||||
with assert_setup_component(1, DOMAIN):
|
||||
assert await async_setup_component(hass, DOMAIN, FULL_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 2
|
||||
|
||||
assert DOMAIN in hass.data
|
||||
assert nws.base_unique_id(45.0, -75.0) in hass.data[DOMAIN]
|
||||
|
||||
|
||||
async def test_unsuccessful_duplicate_config(hass, mock_simple_nws):
|
||||
"""Test that nws setup with duplicate config."""
|
||||
assert await async_setup_component(hass, DOMAIN, DUPLICATE_CONFIG)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 2
|
||||
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 2
|
||||
assert DOMAIN in hass.data
|
||||
|
||||
assert len(hass.data[DOMAIN]) == 1
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
|
||||
assert await hass.config_entries.async_unload(entries[0].entry_id)
|
||||
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 0
|
||||
assert DOMAIN not in hass.data
|
||||
|
||||
Reference in New Issue
Block a user