Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions homeassistant/components/local_ip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
"""Get the local IP address of the Home Assistant instance."""
import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from .const import DOMAIN, PLATFORMS

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
cv.deprecated(CONF_NAME),
vol.Schema({vol.Optional(CONF_NAME, default=DOMAIN): cv.string}),
)
},
extra=vol.ALLOW_EXTRA,
)


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up local_ip from configuration.yaml."""
conf = config.get(DOMAIN)
if conf:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, data=conf, context={"source": SOURCE_IMPORT}
)
)

return True
CONFIG_SCHEMA = cv.deprecated(DOMAIN)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
Expand Down
4 changes: 0 additions & 4 deletions homeassistant/components/local_ip/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ async def async_step_user(self, user_input=None):
return self.async_show_form(step_id="user")

return self.async_create_entry(title=DOMAIN, data=user_input)

async def async_step_import(self, import_info):
"""Handle import from config file."""
return await self.async_step_user(import_info)
17 changes: 7 additions & 10 deletions tests/components/local_ip/test_init.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""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: {}}
from tests.common import MockConfigEntry


async def test_basic_setup(hass, config):
async def test_basic_setup(hass):
"""Test component setup creates entry from config."""
assert await async_setup_component(hass, DOMAIN, config)
entry = MockConfigEntry(domain=DOMAIN, data={})
entry.add_to_hass(hass)

await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

local_ip = await hass.async_add_executor_job(get_local_ip)
state = hass.states.get(f"sensor.{DOMAIN}")
assert state
Expand Down