Add local_ip component (#29973)
* Added localip component * Split config and core logic, and migrate to sensor platform (requested by @MartinHjelmare) Also allow overriding the sensor name via the config * Tweak docstring Co-Authored-By: Fabian Affolter <mail@fabian-affolter.ch> * Initial support for config entries * Rename localip to local_ip (1/2) * Rename localip to local_ip (2/2) * Add test for config_flow * Split and rename tests * Remove unneeded code from config_flow * Implement configuration as config entry import. Other misc requested changes from code review. * Fix tests * minor code review fixes * remove unneeded code Co-authored-by: Fabian Affolter <mail@fabian-affolter.ch>
This commit is contained in:
1 parent
5414e9d155
commit
3f570245aa
10 files changed
+179
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Tests for the local_ip integration."""
|
||||
@@ -0,0 +1,19 @@
|
||||
"""Tests for the local_ip config_flow."""
|
||||
from homeassistant.components.local_ip import DOMAIN
|
||||
|
||||
|
||||
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"}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"name": "test"}
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Tests for the local_ip component."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.local_ip import DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import get_local_ip
|
||||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture():
|
||||
"""Create hass config fixture."""
|
||||
return {DOMAIN: {"name": "test"}}
|
||||
|
||||
|
||||
async def test_basic_setup(hass, config):
|
||||
"""Test component setup creates entry from 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")
|
||||
assert state
|
||||
assert state.state == local_ip
|
||||
Reference in new issue
Block a user