Add local_ip unique_id & icon and single_instance_allowed (#33483)
* Add config flow + sensor unique_id & icon to local_ip * single_instance_allowed * Fix test * Martin's review * Name deprecated
This commit is contained in:
1 parent
dd7fbef948
commit
45b28b8b00
8 files changed
+66
-37
No files matched your search
@@ -1,19 +1,33 @@
|
||||
"""Tests for the local_ip config_flow."""
|
||||
from homeassistant.components.local_ip import DOMAIN
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.local_ip.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_config_flow(hass):
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"name": "test"}
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test")
|
||||
state = hass.states.get(f"sensor.{DOMAIN}")
|
||||
assert state
|
||||
|
||||
|
||||
async def test_already_setup(hass):
|
||||
"""Test we abort if already setup."""
|
||||
MockConfigEntry(domain=DOMAIN, data={},).add_to_hass(hass)
|
||||
|
||||
# Should fail, same NAME
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "single_instance_allowed"
|
||||
@@ -9,7 +9,7 @@ from homeassistant.util import get_local_ip
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture():
|
||||
"""Create hass config fixture."""
|
||||
return {DOMAIN: {"name": "test"}}
|
||||
return {DOMAIN: {}}
|
||||
|
||||
|
||||
async def test_basic_setup(hass, config):
|
||||
@@ -17,6 +17,6 @@ async def test_basic_setup(hass, config):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
local_ip = await hass.async_add_executor_job(get_local_ip)
|
||||
state = hass.states.get("sensor.test")
|
||||
state = hass.states.get(f"sensor.{DOMAIN}")
|
||||
assert state
|
||||
assert state.state == local_ip
|
||||
Reference in new issue
Block a user