Convert nws integration to component configuration (#31398)
* convert nws to component configuration * add more debug logging * remove assumed state * move initialization of data into init * refactor update logic * use forecast success for checking available entities * Split unique_id into more usable pieces. use a base_unique_id for each entry. Add domain for signaling to entities. Each entity in each platform can use base_unique_id to form individual unique_id's. * Revert "move initialization of data into init" This reverts commit 09eb0220469285b10f0500f5f6def67415931a81. * add silver quality scale to manifest * unsubscribe listener in will_remove_from_hass * initialize _unsub_listener in __init__ * use async_on_remove * remove scan interval from configuration * Use better name Co-Authored-By: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
f5b7deda72
commit
a3e84791c6
8 changed files with 496 additions and 273 deletions
67
tests/components/nws/test_init.py
Normal file
67
tests/components/nws/test_init.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
"""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 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},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
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, {}) is True
|
||||
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):
|
||||
assert await async_setup_component(hass, DOMAIN, MINIMAL_CONFIG) is True
|
||||
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):
|
||||
assert await async_setup_component(hass, DOMAIN, LATLON_CONFIG) is True
|
||||
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):
|
||||
assert await async_setup_component(hass, DOMAIN, FULL_CONFIG) is True
|
||||
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) is True
|
||||
assert len(hass.data[DOMAIN]) == 1
|
Loading…
Add table
Add a link
Reference in a new issue