mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Drop owntracks import flow (#64967)
This commit is contained in:
parent
9079734348
commit
f92e8ab931
@ -7,7 +7,6 @@ import re
|
|||||||
from aiohttp.web import json_response
|
from aiohttp.web import json_response
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.components import cloud, mqtt, webhook
|
from homeassistant.components import cloud, mqtt, webhook
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -39,7 +38,9 @@ PLATFORMS = [Platform.DEVICE_TRACKER]
|
|||||||
|
|
||||||
DEFAULT_OWNTRACKS_TOPIC = "owntracks/#"
|
DEFAULT_OWNTRACKS_TOPIC = "owntracks/#"
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.All(
|
||||||
|
cv.removed(CONF_WEBHOOK_ID),
|
||||||
|
vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(DOMAIN, default={}): {
|
vol.Optional(DOMAIN, default={}): {
|
||||||
vol.Optional(CONF_MAX_GPS_ACCURACY): vol.Coerce(float),
|
vol.Optional(CONF_MAX_GPS_ACCURACY): vol.Coerce(float),
|
||||||
@ -48,28 +49,23 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_MQTT_TOPIC, default=DEFAULT_OWNTRACKS_TOPIC
|
CONF_MQTT_TOPIC, default=DEFAULT_OWNTRACKS_TOPIC
|
||||||
): mqtt.valid_subscribe_topic,
|
): mqtt.valid_subscribe_topic,
|
||||||
vol.Optional(CONF_WAYPOINT_WHITELIST): vol.All(cv.ensure_list, [cv.string]),
|
vol.Optional(CONF_WAYPOINT_WHITELIST): vol.All(
|
||||||
|
cv.ensure_list, [cv.string]
|
||||||
|
),
|
||||||
vol.Optional(CONF_SECRET): vol.Any(
|
vol.Optional(CONF_SECRET): vol.Any(
|
||||||
vol.Schema({vol.Optional(cv.string): cv.string}), cv.string
|
vol.Schema({vol.Optional(cv.string): cv.string}), cv.string
|
||||||
),
|
),
|
||||||
vol.Optional(CONF_REGION_MAPPING, default={}): dict,
|
vol.Optional(CONF_REGION_MAPPING, default={}): dict,
|
||||||
vol.Optional(CONF_WEBHOOK_ID): cv.string,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Initialize OwnTracks component."""
|
"""Initialize OwnTracks component."""
|
||||||
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
||||||
if not hass.config_entries.async_entries(DOMAIN):
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,21 +50,6 @@ class OwnTracksFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, user_input):
|
|
||||||
"""Import a config flow from configuration."""
|
|
||||||
if self._async_current_entries():
|
|
||||||
return self.async_abort(reason="single_instance_allowed")
|
|
||||||
webhook_id, _webhook_url, cloudhook = await self._get_webhook_id()
|
|
||||||
secret = secrets.token_hex(16)
|
|
||||||
return self.async_create_entry(
|
|
||||||
title="OwnTracks",
|
|
||||||
data={
|
|
||||||
CONF_WEBHOOK_ID: webhook_id,
|
|
||||||
CONF_SECRET: secret,
|
|
||||||
CONF_CLOUDHOOK: cloudhook,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def _get_webhook_id(self):
|
async def _get_webhook_id(self):
|
||||||
"""Generate webhook ID."""
|
"""Generate webhook ID."""
|
||||||
webhook_id = webhook.async_generate_id()
|
webhook_id = webhook.async_generate_id()
|
||||||
|
@ -76,21 +76,8 @@ async def test_user(hass, webhook_id, secret):
|
|||||||
assert result["description_placeholders"][CONF_WEBHOOK_URL] == WEBHOOK_URL
|
assert result["description_placeholders"][CONF_WEBHOOK_URL] == WEBHOOK_URL
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass, webhook_id, secret):
|
|
||||||
"""Test import step."""
|
|
||||||
flow = await init_config_flow(hass)
|
|
||||||
|
|
||||||
result = await flow.async_step_import({})
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["title"] == "OwnTracks"
|
|
||||||
assert result["data"][CONF_WEBHOOK_ID] == WEBHOOK_ID
|
|
||||||
assert result["data"][CONF_SECRET] == SECRET
|
|
||||||
assert result["data"][CONF_CLOUDHOOK] == CLOUDHOOK
|
|
||||||
assert result["description_placeholders"] is None
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_setup(hass):
|
async def test_import_setup(hass):
|
||||||
"""Test that we automatically create a config flow."""
|
"""Test that we don't automatically create a config entry."""
|
||||||
await async_process_ha_core_config(
|
await async_process_ha_core_config(
|
||||||
hass,
|
hass,
|
||||||
{"external_url": "http://example.com"},
|
{"external_url": "http://example.com"},
|
||||||
@ -99,7 +86,7 @@ async def test_import_setup(hass):
|
|||||||
assert not hass.config_entries.async_entries(DOMAIN)
|
assert not hass.config_entries.async_entries(DOMAIN)
|
||||||
assert await async_setup_component(hass, DOMAIN, {"owntracks": {}})
|
assert await async_setup_component(hass, DOMAIN, {"owntracks": {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.config_entries.async_entries(DOMAIN)
|
assert not hass.config_entries.async_entries(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass):
|
async def test_abort_if_already_setup(hass):
|
||||||
@ -109,11 +96,6 @@ async def test_abort_if_already_setup(hass):
|
|||||||
MockConfigEntry(domain=DOMAIN, data={}).add_to_hass(hass)
|
MockConfigEntry(domain=DOMAIN, data={}).add_to_hass(hass)
|
||||||
assert hass.config_entries.async_entries(DOMAIN)
|
assert hass.config_entries.async_entries(DOMAIN)
|
||||||
|
|
||||||
# Should fail, already setup (import)
|
|
||||||
result = await flow.async_step_import({})
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "single_instance_allowed"
|
|
||||||
|
|
||||||
# Should fail, already setup (flow)
|
# Should fail, already setup (flow)
|
||||||
result = await flow.async_step_user({})
|
result = await flow.async_step_user({})
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
@ -143,7 +125,7 @@ async def test_unload(hass):
|
|||||||
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup"
|
"homeassistant.config_entries.ConfigEntries.async_forward_entry_setup"
|
||||||
) as mock_forward:
|
) as mock_forward:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(mock_forward.mock_calls) == 1
|
assert len(mock_forward.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user