From 69a7eff55d97dd66b78bec0fa690f71669c86c0b Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Tue, 15 Dec 2020 00:59:23 -0800 Subject: [PATCH] Add tests for the Wemo __init__ module (#44196) Co-authored-by: Martin Hjelmare --- tests/components/wemo/test_init.py | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/components/wemo/test_init.py diff --git a/tests/components/wemo/test_init.py b/tests/components/wemo/test_init.py new file mode 100644 index 00000000000..87a6ff39552 --- /dev/null +++ b/tests/components/wemo/test_init.py @@ -0,0 +1,89 @@ +"""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