Remove Slack YAML configuration (#94106)
parent
a1a20fab33
commit
05fbc09ef0
|
@ -7,8 +7,8 @@ from aiohttp.client_exceptions import ClientError
|
||||||
from slack import WebClient
|
from slack import WebClient
|
||||||
from slack.errors import SlackApiError
|
from slack.errors import SlackApiError
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, Platform
|
from homeassistant.const import CONF_API_KEY, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv, discovery
|
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:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Slack component."""
|
"""Set up the Slack component."""
|
||||||
hass.data[DATA_HASS_CONFIG] = config
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,19 +55,6 @@ class SlackFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
errors=errors,
|
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(
|
async def _async_try_connect(
|
||||||
self, token: str
|
self, token: str
|
||||||
) -> tuple[str, None] | tuple[None, dict[str, str]]:
|
) -> tuple[str, None] | tuple[None, dict[str, str]]:
|
||||||
|
|
|
@ -17,16 +17,9 @@ from homeassistant.components.notify import (
|
||||||
ATTR_DATA,
|
ATTR_DATA,
|
||||||
ATTR_TARGET,
|
ATTR_TARGET,
|
||||||
ATTR_TITLE,
|
ATTR_TITLE,
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
BaseNotificationService,
|
BaseNotificationService,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_ICON, CONF_PATH
|
||||||
ATTR_ICON,
|
|
||||||
CONF_API_KEY,
|
|
||||||
CONF_ICON,
|
|
||||||
CONF_PATH,
|
|
||||||
CONF_USERNAME,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv, template
|
from homeassistant.helpers import aiohttp_client, config_validation as cv, template
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
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)]
|
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):
|
class AuthDictT(TypedDict, total=False):
|
||||||
"""Type for auth request data."""
|
"""Type for auth request data."""
|
||||||
|
@ -117,14 +100,13 @@ async def async_get_service(
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> SlackNotificationService | None:
|
) -> SlackNotificationService | None:
|
||||||
"""Set up the Slack notification service."""
|
"""Set up the Slack notification service."""
|
||||||
if discovery_info is None:
|
if discovery_info:
|
||||||
return None
|
return SlackNotificationService(
|
||||||
|
hass,
|
||||||
return SlackNotificationService(
|
discovery_info[SLACK_DATA][DATA_CLIENT],
|
||||||
hass,
|
discovery_info,
|
||||||
discovery_info[SLACK_DATA][DATA_CLIENT],
|
)
|
||||||
discovery_info,
|
return None
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
|
|
@ -90,51 +90,3 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {"base": "unknown"}
|
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"
|
|
||||||
|
|
Loading…
Reference in New Issue