mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Remove YAML configuration from Discord (#71696)
This commit is contained in:
parent
ef9d8944f1
commit
991f0b40f2
@ -2,33 +2,17 @@
|
||||
from aiohttp.client_exceptions import ClientConnectorError
|
||||
import nextcord
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_PLATFORM, Platform
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_TOKEN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS = [Platform.NOTIFY]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Discord component."""
|
||||
# Iterate all entries for notify to only get Discord
|
||||
if Platform.NOTIFY in config:
|
||||
for entry in config[Platform.NOTIFY]:
|
||||
if entry[CONF_PLATFORM] == DOMAIN:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=entry
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Discord from a config entry."""
|
||||
nextcord.VoiceClient.warn_nacl = False
|
||||
|
@ -8,7 +8,7 @@ import nextcord
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_NAME
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import DOMAIN, URL_PLACEHOLDER
|
||||
@ -69,7 +69,7 @@ class DiscordFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=info.name,
|
||||
data=user_input | {CONF_NAME: user_input.get(CONF_NAME, info.name)},
|
||||
data=user_input | {CONF_NAME: info.name},
|
||||
)
|
||||
|
||||
user_input = user_input or {}
|
||||
@ -80,20 +80,6 @@ class DiscordFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config: dict[str, str]) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
_LOGGER.warning(
|
||||
"Configuration of the Discord integration in YAML is deprecated and "
|
||||
"will be removed in Home Assistant 2022.6; Your existing configuration "
|
||||
"has been imported into the UI automatically and can be safely removed "
|
||||
"from your configuration.yaml file"
|
||||
)
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_API_TOKEN] == import_config[CONF_TOKEN]:
|
||||
return self.async_abort(reason="already_configured")
|
||||
import_config[CONF_API_TOKEN] = import_config.pop(CONF_TOKEN)
|
||||
return await self.async_step_user(import_config)
|
||||
|
||||
|
||||
async def _async_try_connect(token: str) -> tuple[str | None, nextcord.AppInfo | None]:
|
||||
"""Try connecting to Discord."""
|
||||
|
@ -7,17 +7,14 @@ from typing import Any, cast
|
||||
|
||||
import nextcord
|
||||
from nextcord.abc import Messageable
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_DATA,
|
||||
ATTR_TARGET,
|
||||
PLATFORM_SCHEMA,
|
||||
BaseNotificationService,
|
||||
)
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_TOKEN
|
||||
from homeassistant.const import CONF_API_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -33,9 +30,6 @@ ATTR_EMBED_THUMBNAIL = "thumbnail"
|
||||
ATTR_EMBED_URL = "url"
|
||||
ATTR_IMAGES = "images"
|
||||
|
||||
# Deprecated in Home Assistant 2022.4
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_TOKEN): cv.string})
|
||||
|
||||
|
||||
async def async_get_service(
|
||||
hass: HomeAssistant,
|
||||
|
@ -6,7 +6,7 @@ import nextcord
|
||||
|
||||
from homeassistant.components.discord.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -21,10 +21,6 @@ CONF_DATA = {
|
||||
CONF_NAME: NAME,
|
||||
}
|
||||
|
||||
CONF_IMPORT_DATA_NO_NAME = {CONF_TOKEN: TOKEN}
|
||||
|
||||
CONF_IMPORT_DATA = CONF_IMPORT_DATA_NO_NAME | {CONF_NAME: NAME}
|
||||
|
||||
|
||||
def create_entry(hass: HomeAssistant) -> ConfigEntry:
|
||||
"""Add config entry in Home Assistant."""
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Test Discord config flow."""
|
||||
import nextcord
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.discord.const import DOMAIN
|
||||
@ -9,8 +8,6 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import (
|
||||
CONF_DATA,
|
||||
CONF_IMPORT_DATA,
|
||||
CONF_IMPORT_DATA_NO_NAME,
|
||||
CONF_INPUT,
|
||||
NAME,
|
||||
create_entry,
|
||||
@ -121,49 +118,6 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
|
||||
assert result["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_import(hass: HomeAssistant, caplog: LogCaptureFixture) -> None:
|
||||
"""Test an import flow."""
|
||||
with mocked_discord_info(), patch_discord_login():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=CONF_IMPORT_DATA.copy(),
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == NAME
|
||||
assert result["data"] == CONF_DATA
|
||||
assert "Discord integration in YAML" in caplog.text
|
||||
|
||||
|
||||
async def test_flow_import_no_name(hass: HomeAssistant) -> None:
|
||||
"""Test import flow with no name in config."""
|
||||
with mocked_discord_info(), patch_discord_login():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=CONF_IMPORT_DATA_NO_NAME,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == NAME
|
||||
assert result["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_import_already_configured(hass: HomeAssistant) -> None:
|
||||
"""Test an import flow already configured."""
|
||||
create_entry(hass)
|
||||
with mocked_discord_info(), patch_discord_login():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=CONF_IMPORT_DATA,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_flow_reauth(hass: HomeAssistant) -> None:
|
||||
"""Test a reauth flow."""
|
||||
entry = create_entry(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user