diff --git a/homeassistant/components/tile/config_flow.py b/homeassistant/components/tile/config_flow.py index 87f58193e9d..932c948defe 100644 --- a/homeassistant/components/tile/config_flow.py +++ b/homeassistant/components/tile/config_flow.py @@ -9,6 +9,10 @@ from homeassistant.helpers import aiohttp_client from .const import DOMAIN # pylint: disable=unused-import +DATA_SCHEMA = vol.Schema( + {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str} +) + class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Handle a Tile config flow.""" @@ -16,26 +20,10 @@ class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL - def __init__(self): - """Initialize the config flow.""" - self.data_schema = vol.Schema( - {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str} - ) - - async def _show_form(self, errors=None): - """Show the form to the user.""" - return self.async_show_form( - step_id="user", data_schema=self.data_schema, errors=errors or {} - ) - - async def async_step_import(self, import_config): - """Import a config entry from configuration.yaml.""" - return await self.async_step_user(import_config) - async def async_step_user(self, user_input=None): """Handle the start of the config flow.""" if not user_input: - return await self._show_form() + return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA) await self.async_set_unique_id(user_input[CONF_USERNAME]) self._abort_if_unique_id_configured() @@ -47,6 +35,10 @@ class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): user_input[CONF_USERNAME], user_input[CONF_PASSWORD], session=session ) except TileError: - return await self._show_form({"base": "invalid_auth"}) + return self.async_show_form( + step_id="user", + data_schema=DATA_SCHEMA, + errors={"base": "invalid_auth"}, + ) return self.async_create_entry(title=user_input[CONF_USERNAME], data=user_input) diff --git a/homeassistant/components/tile/device_tracker.py b/homeassistant/components/tile/device_tracker.py index 5b0065b2c4e..286ffa98869 100644 --- a/homeassistant/components/tile/device_tracker.py +++ b/homeassistant/components/tile/device_tracker.py @@ -3,8 +3,6 @@ import logging from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS -from homeassistant.config_entries import SOURCE_IMPORT -from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback from . import DATA_COORDINATOR, DOMAIN, TileEntity @@ -28,32 +26,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): [ TileDeviceTracker(coordinator, tile_uuid, tile) for tile_uuid, tile in coordinator.data.items() - ], - True, + ] ) -async def async_setup_scanner(hass, config, async_see, discovery_info=None): - """Detect a legacy configuration and import it.""" - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_USERNAME: config[CONF_USERNAME], - CONF_PASSWORD: config[CONF_PASSWORD], - }, - ) - ) - - _LOGGER.info( - "Your Tile configuration has been imported into the UI; " - "please remove it from configuration.yaml" - ) - - return True - - class TileDeviceTracker(TileEntity, TrackerEntity): """Representation of a network infrastructure device.""" diff --git a/tests/components/tile/test_config_flow.py b/tests/components/tile/test_config_flow.py index b9d4799dc2f..edb95cc5b05 100644 --- a/tests/components/tile/test_config_flow.py +++ b/tests/components/tile/test_config_flow.py @@ -3,7 +3,7 @@ from pytile.errors import TileError from homeassistant import data_entry_flow from homeassistant.components.tile import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from tests.async_mock import patch @@ -12,10 +12,7 @@ from tests.common import MockConfigEntry async def test_duplicate_error(hass): """Test that errors are shown when duplicates are added.""" - conf = { - CONF_USERNAME: "user@host.com", - CONF_PASSWORD: "123abc", - } + conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"} MockConfigEntry(domain=DOMAIN, unique_id="user@host.com", data=conf).add_to_hass( hass @@ -31,10 +28,7 @@ async def test_duplicate_error(hass): async def test_invalid_credentials(hass): """Test that invalid credentials key throws an error.""" - conf = { - CONF_USERNAME: "user@host.com", - CONF_PASSWORD: "123abc", - } + conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"} with patch( "homeassistant.components.tile.config_flow.async_login", @@ -47,33 +41,9 @@ async def test_invalid_credentials(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_step_import(hass): - """Test that the import step works.""" - conf = { - CONF_USERNAME: "user@host.com", - CONF_PASSWORD: "123abc", - } - - with patch( - "homeassistant.components.tile.async_setup_entry", return_value=True - ), patch("homeassistant.components.tile.config_flow.async_login"): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=conf - ) - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["title"] == "user@host.com" - assert result["data"] == { - CONF_USERNAME: "user@host.com", - CONF_PASSWORD: "123abc", - } - - async def test_step_user(hass): """Test that the user step works.""" - conf = { - CONF_USERNAME: "user@host.com", - CONF_PASSWORD: "123abc", - } + conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"} with patch( "homeassistant.components.tile.async_setup_entry", return_value=True