DNS IP: Remove deprecated YAML import (#69007)
Co-authored-by: Franck Nijhof <git@frenck.dev>pull/69024/head
parent
fef43d4f39
commit
666cbebd28
|
@ -1,15 +1,11 @@
|
||||||
"""The dnsip component."""
|
"""The dnsip component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import PLATFORMS
|
from .const import PLATFORMS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up DNS IP from a config entry."""
|
"""Set up DNS IP from a config entry."""
|
||||||
|
|
|
@ -82,14 +82,6 @@ class DnsIPConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Return Option handler."""
|
"""Return Option handler."""
|
||||||
return DnsIPOptionsFlowHandler(config_entry)
|
return DnsIPOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Import a configuration from config.yaml."""
|
|
||||||
|
|
||||||
hostname = config.get(CONF_HOSTNAME, DEFAULT_HOSTNAME)
|
|
||||||
self._async_abort_entries_match({CONF_HOSTNAME: hostname})
|
|
||||||
config[CONF_HOSTNAME] = hostname
|
|
||||||
return await self.async_step_user(user_input=config)
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
|
|
|
@ -6,20 +6,14 @@ import logging
|
||||||
|
|
||||||
import aiodns
|
import aiodns
|
||||||
from aiodns.error import DNSError
|
from aiodns.error import DNSError
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import SensorEntity
|
||||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
from homeassistant.config_entries import ConfigEntry
|
||||||
SensorEntity,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_HOSTNAME,
|
CONF_HOSTNAME,
|
||||||
|
@ -27,10 +21,6 @@ from .const import (
|
||||||
CONF_IPV6,
|
CONF_IPV6,
|
||||||
CONF_RESOLVER,
|
CONF_RESOLVER,
|
||||||
CONF_RESOLVER_IPV6,
|
CONF_RESOLVER_IPV6,
|
||||||
DEFAULT_HOSTNAME,
|
|
||||||
DEFAULT_IPV6,
|
|
||||||
DEFAULT_RESOLVER,
|
|
||||||
DEFAULT_RESOLVER_IPV6,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,38 +28,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=120)
|
SCAN_INTERVAL = timedelta(seconds=120)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_HOSTNAME, default=DEFAULT_HOSTNAME): cv.string,
|
|
||||||
vol.Optional(CONF_RESOLVER, default=DEFAULT_RESOLVER): cv.string,
|
|
||||||
vol.Optional(CONF_RESOLVER_IPV6, default=DEFAULT_RESOLVER_IPV6): cv.string,
|
|
||||||
vol.Optional(CONF_IPV6, default=DEFAULT_IPV6): cv.boolean,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_devices: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the DNS IP sensor."""
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Configuration of the DNS IP platform in YAML is deprecated and will be "
|
|
||||||
"removed in Home Assistant 2022.4; Your existing configuration "
|
|
||||||
"has been imported into the UI automatically and can be safely removed "
|
|
||||||
"from your configuration.yaml file"
|
|
||||||
)
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=config,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
|
|
@ -146,66 +146,6 @@ async def test_form_error(hass: HomeAssistant) -> None:
|
||||||
assert result2["errors"] == {"base": "invalid_hostname"}
|
assert result2["errors"] == {"base": "invalid_hostname"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"p_input,p_output,p_options",
|
|
||||||
[
|
|
||||||
(
|
|
||||||
{CONF_HOSTNAME: "home-assistant.io"},
|
|
||||||
{
|
|
||||||
"hostname": "home-assistant.io",
|
|
||||||
"name": "home-assistant.io",
|
|
||||||
"ipv4": True,
|
|
||||||
"ipv6": True,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"resolver": "208.67.222.222",
|
|
||||||
"resolver_ipv6": "2620:0:ccc::2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
"hostname": "myip.opendns.com",
|
|
||||||
"name": "myip",
|
|
||||||
"ipv4": True,
|
|
||||||
"ipv6": True,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"resolver": "208.67.222.222",
|
|
||||||
"resolver_ipv6": "2620:0:ccc::2",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_import_flow_success(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
p_input: dict[str, str],
|
|
||||||
p_output: dict[str, str],
|
|
||||||
p_options: dict[str, str],
|
|
||||||
) -> None:
|
|
||||||
"""Test a successful import of YAML."""
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.dnsip.config_flow.aiodns.DNSResolver",
|
|
||||||
return_value=RetrieveDNS(),
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.dnsip.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data=p_input,
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result2["title"] == p_output["name"]
|
|
||||||
assert result2["data"] == p_output
|
|
||||||
assert result2["options"] == p_options
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_already_exist(hass: HomeAssistant) -> None:
|
async def test_flow_already_exist(hass: HomeAssistant) -> None:
|
||||||
"""Test flow when unique id already exist."""
|
"""Test flow when unique id already exist."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue