Remove YAML configuration from Local IP (#50642)
parent
117860f13b
commit
c9b25fe2a2
|
@ -1,35 +1,11 @@
|
||||||
"""Get the local IP address of the Home Assistant instance."""
|
"""Get the local IP address of the Home Assistant instance."""
|
||||||
import voluptuous as vol
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS
|
from .const import DOMAIN, PLATFORMS
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
|
|
|
@ -20,7 +20,3 @@ class SimpleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
return self.async_show_form(step_id="user")
|
return self.async_show_form(step_id="user")
|
||||||
|
|
||||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
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)
|
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
"""Tests for the local_ip component."""
|
"""Tests for the local_ip component."""
|
||||||
import pytest
|
|
||||||
|
|
||||||
from homeassistant.components.local_ip import DOMAIN
|
from homeassistant.components.local_ip import DOMAIN
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
from homeassistant.util import get_local_ip
|
from homeassistant.util import get_local_ip
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
@pytest.fixture(name="config")
|
|
||||||
def config_fixture():
|
|
||||||
"""Create hass config fixture."""
|
|
||||||
return {DOMAIN: {}}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_basic_setup(hass, config):
|
async def test_basic_setup(hass):
|
||||||
"""Test component setup creates entry from config."""
|
"""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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
local_ip = await hass.async_add_executor_job(get_local_ip)
|
local_ip = await hass.async_add_executor_job(get_local_ip)
|
||||||
state = hass.states.get(f"sensor.{DOMAIN}")
|
state = hass.states.get(f"sensor.{DOMAIN}")
|
||||||
assert state
|
assert state
|
||||||
|
|
Loading…
Reference in New Issue