From 05fbc09ef044769c0ddf85ed2ce6ebe37b1edca4 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 6 Jun 2023 16:01:40 +0200 Subject: [PATCH] Remove Slack YAML configuration (#94106) --- homeassistant/components/slack/__init__.py | 15 +----- homeassistant/components/slack/config_flow.py | 13 ----- homeassistant/components/slack/notify.py | 34 ++++--------- tests/components/slack/test_config_flow.py | 48 ------------------- 4 files changed, 10 insertions(+), 100 deletions(-) diff --git a/homeassistant/components/slack/__init__.py b/homeassistant/components/slack/__init__.py index ee4935c7ead..076dcf7e590 100644 --- a/homeassistant/components/slack/__init__.py +++ b/homeassistant/components/slack/__init__.py @@ -7,8 +7,8 @@ from aiohttp.client_exceptions import ClientError from slack import WebClient from slack.errors import SlackApiError -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, Platform +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_API_KEY, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import aiohttp_client, config_validation as cv, discovery @@ -36,17 +36,6 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Slack component.""" hass.data[DATA_HASS_CONFIG] = config - - # Iterate all entries for notify to only get Slack - 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 diff --git a/homeassistant/components/slack/config_flow.py b/homeassistant/components/slack/config_flow.py index 253750a2310..187cef057a0 100644 --- a/homeassistant/components/slack/config_flow.py +++ b/homeassistant/components/slack/config_flow.py @@ -55,19 +55,6 @@ class SlackFlowHandler(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 Slack integration in YAML is deprecated and " - "will be removed in a future release; Your existing configuration " - "has been imported into the UI automatically and can be safely removed " - "from your configuration.yaml file" - ) - entries = self._async_current_entries() - if any(x.data[CONF_API_KEY] == import_config[CONF_API_KEY] for x in entries): - return self.async_abort(reason="already_configured") - return await self.async_step_user(import_config) - async def _async_try_connect( self, token: str ) -> tuple[str, None] | tuple[None, dict[str, str]]: diff --git a/homeassistant/components/slack/notify.py b/homeassistant/components/slack/notify.py index d587f960704..498eddffa3d 100644 --- a/homeassistant/components/slack/notify.py +++ b/homeassistant/components/slack/notify.py @@ -17,16 +17,9 @@ from homeassistant.components.notify import ( ATTR_DATA, ATTR_TARGET, ATTR_TITLE, - PLATFORM_SCHEMA, BaseNotificationService, ) -from homeassistant.const import ( - ATTR_ICON, - CONF_API_KEY, - CONF_ICON, - CONF_PATH, - CONF_USERNAME, -) +from homeassistant.const import ATTR_ICON, CONF_PATH from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import aiohttp_client, config_validation as cv, template from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -73,16 +66,6 @@ DATA_SCHEMA = vol.All( cv.ensure_list, [vol.Any(DATA_FILE_SCHEMA, DATA_TEXT_ONLY_SCHEMA)] ) -# Deprecated in Home Assistant 2022.5 -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_API_KEY): cv.string, - vol.Required(CONF_DEFAULT_CHANNEL): cv.string, - vol.Optional(CONF_ICON): cv.string, - vol.Optional(CONF_USERNAME): cv.string, - } -) - class AuthDictT(TypedDict, total=False): """Type for auth request data.""" @@ -117,14 +100,13 @@ async def async_get_service( discovery_info: DiscoveryInfoType | None = None, ) -> SlackNotificationService | None: """Set up the Slack notification service.""" - if discovery_info is None: - return None - - return SlackNotificationService( - hass, - discovery_info[SLACK_DATA][DATA_CLIENT], - discovery_info, - ) + if discovery_info: + return SlackNotificationService( + hass, + discovery_info[SLACK_DATA][DATA_CLIENT], + discovery_info, + ) + return None @callback diff --git a/tests/components/slack/test_config_flow.py b/tests/components/slack/test_config_flow.py index 97c8e6ee743..e941e4ba47c 100644 --- a/tests/components/slack/test_config_flow.py +++ b/tests/components/slack/test_config_flow.py @@ -90,51 +90,3 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None: assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["step_id"] == "user" assert result["errors"] == {"base": "unknown"} - - -async def test_flow_import( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker -) -> None: - """Test an import flow.""" - mock_connection(aioclient_mock) - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=CONF_DATA, - ) - - assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - assert result["title"] == TEAM_NAME - assert result["data"] == CONF_DATA - - -async def test_flow_import_no_name( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker -) -> None: - """Test import flow with no name in config.""" - mock_connection(aioclient_mock) - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=CONF_INPUT, - ) - - assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - assert result["title"] == TEAM_NAME - assert result["data"] == CONF_DATA - - -async def test_flow_import_already_configured( - hass: HomeAssistant, aioclient_mock: AiohttpClientMocker -) -> None: - """Test an import flow already configured.""" - create_entry(hass) - mock_connection(aioclient_mock) - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=CONF_DATA, - ) - - assert result["type"] == data_entry_flow.FlowResultType.ABORT - assert result["reason"] == "already_configured"