mirror of
https://github.com/home-assistant/core
synced 2024-09-12 15:16:21 +02:00
This reverts commit 19f48e180c
.
This commit is contained in:
parent
16364636d1
commit
907907e6f9
@ -9,10 +9,6 @@ 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."""
|
||||
@ -20,10 +16,26 @@ 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 self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
|
||||
return await self._show_form()
|
||||
|
||||
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
||||
self._abort_if_unique_id_configured()
|
||||
@ -35,10 +47,6 @@ class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
user_input[CONF_USERNAME], user_input[CONF_PASSWORD], session=session
|
||||
)
|
||||
except TileError:
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=DATA_SCHEMA,
|
||||
errors={"base": "invalid_auth"},
|
||||
)
|
||||
return await self._show_form({"base": "invalid_auth"})
|
||||
|
||||
return self.async_create_entry(title=user_input[CONF_USERNAME], data=user_input)
|
||||
|
@ -3,6 +3,8 @@ 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
|
||||
@ -26,10 +28,32 @@ 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."""
|
||||
|
||||
|
@ -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_USER
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from tests.async_mock import patch
|
||||
@ -12,7 +12,10 @@ 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
|
||||
@ -28,7 +31,10 @@ 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",
|
||||
@ -41,9 +47,33 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user