mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Remove YAML config for Tile (#43064)
This commit is contained in:
parent
39cdf61c2d
commit
19f48e180c
@ -9,6 +9,10 @@ from homeassistant.helpers import aiohttp_client
|
|||||||
|
|
||||||
from .const import DOMAIN # pylint: disable=unused-import
|
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):
|
class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a Tile config flow."""
|
"""Handle a Tile config flow."""
|
||||||
@ -16,26 +20,10 @@ class TileFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 1
|
VERSION = 1
|
||||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
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):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle the start of the config flow."""
|
"""Handle the start of the config flow."""
|
||||||
if not user_input:
|
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])
|
await self.async_set_unique_id(user_input[CONF_USERNAME])
|
||||||
self._abort_if_unique_id_configured()
|
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
|
user_input[CONF_USERNAME], user_input[CONF_PASSWORD], session=session
|
||||||
)
|
)
|
||||||
except TileError:
|
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)
|
return self.async_create_entry(title=user_input[CONF_USERNAME], data=user_input)
|
||||||
|
@ -3,8 +3,6 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
||||||
from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS
|
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 homeassistant.core import callback
|
||||||
|
|
||||||
from . import DATA_COORDINATOR, DOMAIN, TileEntity
|
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)
|
TileDeviceTracker(coordinator, tile_uuid, tile)
|
||||||
for tile_uuid, tile in coordinator.data.items()
|
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):
|
class TileDeviceTracker(TileEntity, TrackerEntity):
|
||||||
"""Representation of a network infrastructure device."""
|
"""Representation of a network infrastructure device."""
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from pytile.errors import TileError
|
|||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.tile import DOMAIN
|
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 homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
@ -12,10 +12,7 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
async def test_duplicate_error(hass):
|
async def test_duplicate_error(hass):
|
||||||
"""Test that errors are shown when duplicates are added."""
|
"""Test that errors are shown when duplicates are added."""
|
||||||
conf = {
|
conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"}
|
||||||
CONF_USERNAME: "user@host.com",
|
|
||||||
CONF_PASSWORD: "123abc",
|
|
||||||
}
|
|
||||||
|
|
||||||
MockConfigEntry(domain=DOMAIN, unique_id="user@host.com", data=conf).add_to_hass(
|
MockConfigEntry(domain=DOMAIN, unique_id="user@host.com", data=conf).add_to_hass(
|
||||||
hass
|
hass
|
||||||
@ -31,10 +28,7 @@ async def test_duplicate_error(hass):
|
|||||||
|
|
||||||
async def test_invalid_credentials(hass):
|
async def test_invalid_credentials(hass):
|
||||||
"""Test that invalid credentials key throws an error."""
|
"""Test that invalid credentials key throws an error."""
|
||||||
conf = {
|
conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"}
|
||||||
CONF_USERNAME: "user@host.com",
|
|
||||||
CONF_PASSWORD: "123abc",
|
|
||||||
}
|
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tile.config_flow.async_login",
|
"homeassistant.components.tile.config_flow.async_login",
|
||||||
@ -47,33 +41,9 @@ async def test_invalid_credentials(hass):
|
|||||||
assert result["errors"] == {"base": "invalid_auth"}
|
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):
|
async def test_step_user(hass):
|
||||||
"""Test that the user step works."""
|
"""Test that the user step works."""
|
||||||
conf = {
|
conf = {CONF_USERNAME: "user@host.com", CONF_PASSWORD: "123abc"}
|
||||||
CONF_USERNAME: "user@host.com",
|
|
||||||
CONF_PASSWORD: "123abc",
|
|
||||||
}
|
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tile.async_setup_entry", return_value=True
|
"homeassistant.components.tile.async_setup_entry", return_value=True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user