Local ip tests (#82051)
This commit is contained in:
parent
3d29638804
commit
13577981f9
2 changed files with 15 additions and 3 deletions
|
@ -1,12 +1,15 @@
|
||||||
"""Tests for the local_ip config_flow."""
|
"""Tests for the local_ip config_flow."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.local_ip.const import DOMAIN
|
from homeassistant.components.local_ip.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_config_flow(hass, mock_get_source_ip):
|
async def test_config_flow(hass: HomeAssistant, mock_get_source_ip) -> None:
|
||||||
"""Test we can finish a config flow."""
|
"""Test we can finish a config flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
|
@ -21,7 +24,7 @@ async def test_config_flow(hass, mock_get_source_ip):
|
||||||
assert state
|
assert state
|
||||||
|
|
||||||
|
|
||||||
async def test_already_setup(hass, mock_get_source_ip):
|
async def test_already_setup(hass: HomeAssistant, mock_get_source_ip) -> None:
|
||||||
"""Test we abort if already setup."""
|
"""Test we abort if already setup."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,20 +1,29 @@
|
||||||
"""Tests for the local_ip component."""
|
"""Tests for the local_ip component."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.local_ip import DOMAIN
|
from homeassistant.components.local_ip import DOMAIN
|
||||||
from homeassistant.components.network import async_get_source_ip
|
from homeassistant.components.network import async_get_source_ip
|
||||||
from homeassistant.components.zeroconf import MDNS_TARGET_IP
|
from homeassistant.components.zeroconf import MDNS_TARGET_IP
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_basic_setup(hass, mock_get_source_ip):
|
async def test_basic_setup(hass: HomeAssistant, mock_get_source_ip) -> None:
|
||||||
"""Test component setup creates entry from config."""
|
"""Test component setup creates entry from config."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data={})
|
entry = MockConfigEntry(domain=DOMAIN, data={})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert entry.state == config_entries.ConfigEntryState.LOADED
|
||||||
|
|
||||||
local_ip = await async_get_source_ip(hass, target_ip=MDNS_TARGET_IP)
|
local_ip = await async_get_source_ip(hass, target_ip=MDNS_TARGET_IP)
|
||||||
state = hass.states.get(f"sensor.{DOMAIN}")
|
state = hass.states.get(f"sensor.{DOMAIN}")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == local_ip
|
assert state.state == local_ip
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert entry.state is config_entries.ConfigEntryState.NOT_LOADED
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue