core/tests/components/wemo/test_init.py

90 lines
2.8 KiB
Python

"""Tests for the wemo component."""
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC
from homeassistant.components.wemo.const import DOMAIN
from homeassistant.setup import async_setup_component
from .conftest import MOCK_HOST, MOCK_PORT
async def test_config_no_config(hass):
"""Component setup succeeds when there are no config entry for the domain."""
assert await async_setup_component(hass, DOMAIN, {})
async def test_config_no_static(hass):
"""Component setup succeeds when there are no static config entries."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_DISCOVERY: False}})
async def test_static_duplicate_static_entry(hass, pywemo_device):
"""Duplicate static entries are merged into a single entity."""
static_config_entry = f"{MOCK_HOST}:{MOCK_PORT}"
assert await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_DISCOVERY: False,
CONF_STATIC: [
static_config_entry,
static_config_entry,
],
},
},
)
await hass.async_block_till_done()
entity_reg = await hass.helpers.entity_registry.async_get_registry()
entity_entries = list(entity_reg.entities.values())
assert len(entity_entries) == 1
async def test_static_config_with_port(hass, pywemo_device):
"""Static device with host and port is added and removed."""
assert await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_DISCOVERY: False,
CONF_STATIC: [f"{MOCK_HOST}:{MOCK_PORT}"],
},
},
)
await hass.async_block_till_done()
entity_reg = await hass.helpers.entity_registry.async_get_registry()
entity_entries = list(entity_reg.entities.values())
assert len(entity_entries) == 1
async def test_static_config_without_port(hass, pywemo_device):
"""Static device with host and no port is added and removed."""
assert await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_DISCOVERY: False,
CONF_STATIC: [MOCK_HOST],
},
},
)
await hass.async_block_till_done()
entity_reg = await hass.helpers.entity_registry.async_get_registry()
entity_entries = list(entity_reg.entities.values())
assert len(entity_entries) == 1
async def test_static_config_with_invalid_host(hass):
"""Component setup fails if a static host is invalid."""
setup_success = await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_DISCOVERY: False,
CONF_STATIC: [""],
},
},
)
assert not setup_success