Fix nws platform setup and data update. (#34106)
* add test and fix tests for update logging. * Fix update logging. * Remove assert is True * guard against platform config and use async_write_ha_state * fix discovery info passing to platform * Improve testing for entities in init
This commit is contained in:
parent
ad5a396c10
commit
e6a6c3ceb6
4 changed files with 74 additions and 38 deletions
|
@ -31,7 +31,12 @@ DUPLICATE_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, {}) is True
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
assert len(entity_registry.entities) == 0
|
||||
|
||||
assert DOMAIN not in hass.data
|
||||
|
||||
|
||||
|
@ -39,29 +44,49 @@ 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
|
||||
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):
|
||||
assert await async_setup_component(hass, DOMAIN, LATLON_CONFIG) is True
|
||||
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):
|
||||
assert await async_setup_component(hass, DOMAIN, FULL_CONFIG) is True
|
||||
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) is True
|
||||
assert await async_setup_component(hass, DOMAIN, DUPLICATE_CONFIG)
|
||||
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.data[DOMAIN]) == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue