Add config flow tests for OwnTracks (#28644)
* Add config flow tests for OwnTracks * Fix pylint * Woops, uncomment test * Woops again, logs removed * Review from @MartinHjelmare + fix pylint
This commit is contained in:
parent
cfcacc2827
commit
decab3e15b
5 changed files with 134 additions and 26 deletions
|
@ -3,6 +3,8 @@ from homeassistant import config_entries
|
|||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
from homeassistant.auth.util import generate_secret
|
||||
|
||||
from .const import DOMAIN # noqa pylint: disable=unused-import
|
||||
|
||||
CONF_SECRET = "secret"
|
||||
CONF_CLOUDHOOK = "cloudhook"
|
||||
|
||||
|
@ -17,8 +19,7 @@ def supports_encryption():
|
|||
return False
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register("owntracks")
|
||||
class OwnTracksFlow(config_entries.ConfigFlow):
|
||||
class OwnTracksFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Set up OwnTracks."""
|
||||
|
||||
VERSION = 1
|
||||
|
@ -36,14 +37,9 @@ class OwnTracksFlow(config_entries.ConfigFlow):
|
|||
secret = generate_secret(16)
|
||||
|
||||
if supports_encryption():
|
||||
secret_desc = (
|
||||
"The encryption key is {} "
|
||||
"(on Android under preferences -> advanced)".format(secret)
|
||||
)
|
||||
secret_desc = f"The encryption key is {secret} (on Android under preferences -> advanced)"
|
||||
else:
|
||||
secret_desc = (
|
||||
"Encryption is not supported because libsodium is not " "installed."
|
||||
)
|
||||
secret_desc = "Encryption is not supported because nacl is not installed."
|
||||
|
||||
return self.async_create_entry(
|
||||
title="OwnTracks",
|
||||
|
@ -55,8 +51,7 @@ class OwnTracksFlow(config_entries.ConfigFlow):
|
|||
description_placeholders={
|
||||
"secret": secret_desc,
|
||||
"webhook_url": webhook_url,
|
||||
"android_url": "https://play.google.com/store/apps/details?"
|
||||
"id=org.owntracks.android",
|
||||
"android_url": "https://play.google.com/store/apps/details?id=org.owntracks.android",
|
||||
"ios_url": "https://itunes.apple.com/us/app/owntracks/id692424691?mt=8",
|
||||
"docs_url": "https://www.home-assistant.io/integrations/owntracks/",
|
||||
},
|
||||
|
@ -64,6 +59,8 @@ class OwnTracksFlow(config_entries.ConfigFlow):
|
|||
|
||||
async def async_step_import(self, user_input):
|
||||
"""Import a config flow from configuration."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="one_instance_allowed")
|
||||
webhook_id, _webhook_url, cloudhook = await self._get_webhook_id()
|
||||
secret = generate_secret(16)
|
||||
return self.async_create_entry(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue