Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Teemu R. <tpr@iki.fi> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""Tests for the TP-Link component."""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.components import tplink
|
|
from homeassistant.components.tplink.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.const import CONF_HOST
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from . import IP_ADDRESS, MAC_ADDRESS, _patch_discovery, _patch_single_discovery
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_configuring_tplink_causes_discovery(hass):
|
|
"""Test that specifying empty config does discovery."""
|
|
with patch("homeassistant.components.tplink.Discover.discover") as discover:
|
|
discover.return_value = {"host": 1234}
|
|
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
|
|
await hass.async_block_till_done()
|
|
|
|
assert len(discover.mock_calls) == 1
|
|
|
|
|
|
async def test_config_entry_reload(hass):
|
|
"""Test that a config entry can be reloaded."""
|
|
already_migrated_config_entry = MockConfigEntry(
|
|
domain=DOMAIN, data={}, unique_id=MAC_ADDRESS
|
|
)
|
|
already_migrated_config_entry.add_to_hass(hass)
|
|
with _patch_discovery(), _patch_single_discovery():
|
|
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
|
|
await hass.async_block_till_done()
|
|
assert already_migrated_config_entry.state == ConfigEntryState.LOADED
|
|
await hass.config_entries.async_unload(already_migrated_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
assert already_migrated_config_entry.state == ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
async def test_config_entry_retry(hass):
|
|
"""Test that a config entry can be retried."""
|
|
already_migrated_config_entry = MockConfigEntry(
|
|
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS
|
|
)
|
|
already_migrated_config_entry.add_to_hass(hass)
|
|
with _patch_discovery(no_device=True), _patch_single_discovery(no_device=True):
|
|
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
|
|
await hass.async_block_till_done()
|
|
assert already_migrated_config_entry.state == ConfigEntryState.SETUP_RETRY
|