Remove deprecated async_get_scanner from keenetic_ndms2 (#63860)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-11 08:24:21 +01:00 committed by GitHub
parent 8dcffc9993
commit d8a3a26444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 99 deletions

View file

@ -20,7 +20,6 @@ from homeassistant.const import (
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import (
CONF_CONSIDER_HOME,
@ -98,12 +97,6 @@ class KeeneticFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(
self, user_input: ConfigType | None = None
) -> FlowResult:
"""Import a config entry."""
return await self.async_step_user(user_input)
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
"""Handle a discovered device."""
friendly_name = discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "")

View file

@ -1,98 +1,27 @@
"""Support for Keenetic routers as device tracker."""
from __future__ import annotations
from datetime import timedelta
import logging
from ndms2_client import Device
import voluptuous as vol
from homeassistant.components.device_tracker import (
DOMAIN as DEVICE_TRACKER_DOMAIN,
PLATFORM_SCHEMA as DEVICE_TRACKER_SCHEMA,
SOURCE_TYPE_ROUTER,
)
from homeassistant.components.device_tracker.config_entry import ScannerEntity
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.dt as dt_util
from .const import (
CONF_CONSIDER_HOME,
CONF_INTERFACES,
CONF_LEGACY_INTERFACE,
DEFAULT_CONSIDER_HOME,
DEFAULT_INTERFACE,
DEFAULT_SCAN_INTERVAL,
DEFAULT_TELNET_PORT,
DOMAIN,
ROUTER,
)
from .const import DOMAIN, ROUTER
from .router import KeeneticRouter
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = DEVICE_TRACKER_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PORT, default=DEFAULT_TELNET_PORT): cv.port,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_LEGACY_INTERFACE, default=DEFAULT_INTERFACE): cv.string,
}
)
async def async_get_scanner(hass: HomeAssistant, config):
"""Import legacy configuration from YAML."""
scanner_config = config[DEVICE_TRACKER_DOMAIN]
scan_interval: timedelta | None = scanner_config.get(CONF_SCAN_INTERVAL)
consider_home: timedelta | None = scanner_config.get(CONF_CONSIDER_HOME)
host: str = scanner_config[CONF_HOST]
hass.data[DOMAIN][f"imported_options_{host}"] = {
CONF_INTERFACES: [scanner_config[CONF_LEGACY_INTERFACE]],
CONF_SCAN_INTERVAL: int(scan_interval.total_seconds())
if scan_interval
else DEFAULT_SCAN_INTERVAL,
CONF_CONSIDER_HOME: int(consider_home.total_seconds())
if consider_home
else DEFAULT_CONSIDER_HOME,
}
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_HOST: scanner_config[CONF_HOST],
CONF_PORT: scanner_config[CONF_PORT],
CONF_USERNAME: scanner_config[CONF_USERNAME],
CONF_PASSWORD: scanner_config[CONF_PASSWORD],
},
)
)
_LOGGER.warning(
"Your Keenetic NDMS2 configuration has been imported into the UI, "
"please remove it from configuration.yaml. "
"Loading Keenetic NDMS2 via scanner setup is now deprecated"
)
return None
async def async_setup_entry(
hass: HomeAssistant,

View file

@ -69,25 +69,6 @@ async def test_flow_works(hass: HomeAssistant, connect) -> None:
assert len(mock_setup_entry.mock_calls) == 1
async def test_import_works(hass: HomeAssistant, connect) -> None:
"""Test config flow."""
with patch(
"homeassistant.components.keenetic_ndms2.async_setup_entry", return_value=True
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
keenetic.DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=MOCK_DATA,
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == MOCK_NAME
assert result["data"] == MOCK_DATA
assert len(mock_setup_entry.mock_calls) == 1
async def test_options(hass: HomeAssistant) -> None:
"""Test updating options."""
entry = MockConfigEntry(domain=keenetic.DOMAIN, data=MOCK_DATA)