diff --git a/homeassistant/components/mastodon/config_flow.py b/homeassistant/components/mastodon/config_flow.py index a36ba2e917f5f..1b93cbecd98f5 100644 --- a/homeassistant/components/mastodon/config_flow.py +++ b/homeassistant/components/mastodon/config_flow.py @@ -9,12 +9,7 @@ from yarl import URL from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import ( - CONF_ACCESS_TOKEN, - CONF_CLIENT_ID, - CONF_CLIENT_SECRET, - CONF_NAME, -) +from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.helpers.selector import ( TextSelector, TextSelectorConfig, @@ -22,7 +17,7 @@ ) from homeassistant.util import slugify -from .const import CONF_BASE_URL, DEFAULT_URL, DOMAIN, LOGGER +from .const import CONF_BASE_URL, DOMAIN, LOGGER from .utils import construct_mastodon_username, create_mastodon_client STEP_USER_DATA_SCHEMA = vol.Schema( @@ -130,44 +125,3 @@ async def async_step_user( ) return self.show_user_form(user_input, errors) - - async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult: - """Import a config entry from configuration.yaml.""" - errors: dict[str, str] | None = None - - LOGGER.debug("Importing Mastodon from configuration.yaml") - - base_url = base_url_from_url(str(import_data.get(CONF_BASE_URL, DEFAULT_URL))) - client_id = str(import_data.get(CONF_CLIENT_ID)) - client_secret = str(import_data.get(CONF_CLIENT_SECRET)) - access_token = str(import_data.get(CONF_ACCESS_TOKEN)) - name = import_data.get(CONF_NAME) - - instance, account, errors = await self.hass.async_add_executor_job( - self.check_connection, - base_url, - client_id, - client_secret, - access_token, - ) - - if not errors: - name = construct_mastodon_username(instance, account) - await self.async_set_unique_id(slugify(name)) - self._abort_if_unique_id_configured() - - if not name: - name = construct_mastodon_username(instance, account) - - return self.async_create_entry( - title=name, - data={ - CONF_BASE_URL: base_url, - CONF_CLIENT_ID: client_id, - CONF_CLIENT_SECRET: client_secret, - CONF_ACCESS_TOKEN: access_token, - }, - ) - - reason = next(iter(errors.items()))[1] - return self.async_abort(reason=reason) diff --git a/homeassistant/components/mastodon/notify.py b/homeassistant/components/mastodon/notify.py index 7878fc665a177..bdfdbbf6e99e7 100644 --- a/homeassistant/components/mastodon/notify.py +++ b/homeassistant/components/mastodon/notify.py @@ -14,14 +14,12 @@ PLATFORM_SCHEMA as NOTIFY_PLATFORM_SCHEMA, BaseNotificationService, ) -from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_CLIENT_SECRET -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant -from homeassistant.data_entry_flow import FlowResultType -from homeassistant.helpers import config_validation as cv, issue_registry as ir +from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_validation as cv from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from .const import CONF_BASE_URL, DEFAULT_URL, DOMAIN, LOGGER +from .const import CONF_BASE_URL, DEFAULT_URL, LOGGER ATTR_MEDIA = "media" ATTR_TARGET = "target" @@ -46,51 +44,7 @@ async def async_get_service( discovery_info: DiscoveryInfoType | None = None, ) -> MastodonNotificationService | None: """Get the Mastodon notification service.""" - - if not discovery_info: - # Import config entry - - import_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, - ) - - if ( - import_result["type"] == FlowResultType.ABORT - and import_result["reason"] != "already_configured" - ): - ir.async_create_issue( - hass, - DOMAIN, - f"deprecated_yaml_import_issue_{import_result["reason"]}", - breaks_in_ha_version="2025.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=ir.IssueSeverity.WARNING, - translation_key=f"deprecated_yaml_import_issue_{import_result["reason"]}", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": INTEGRATION_TITLE, - }, - ) - return None - - ir.async_create_issue( - hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2025.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=ir.IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": INTEGRATION_TITLE, - }, - ) - + if discovery_info is None: return None client: Mastodon = discovery_info.get("client") diff --git a/homeassistant/components/mastodon/strings.json b/homeassistant/components/mastodon/strings.json index c6aefefca06d2..9df94ecf20430 100644 --- a/homeassistant/components/mastodon/strings.json +++ b/homeassistant/components/mastodon/strings.json @@ -25,20 +25,6 @@ "unknown": "Unknown error occured when connecting to the Mastodon instance." } }, - "issues": { - "deprecated_yaml_import_issue_unauthorized_error": { - "title": "YAML import failed due to an authentication error", - "description": "Configuring {integration_title} using YAML is being removed but there was an authentication error while importing your existing configuration.\nPlease use the UI to configure Mastodon. Don't forget to delete the YAML configuration." - }, - "deprecated_yaml_import_issue_network_error": { - "title": "YAML import failed because the instance was not found", - "description": "Configuring {integration_title} using YAML is being removed but no instance was found while importing your existing configuration.\nPlease use the UI to configure Mastodon. Don't forget to delete the YAML configuration." - }, - "deprecated_yaml_import_issue_unknown": { - "title": "YAML import failed with unknown error", - "description": "Configuring {integration_title} using YAML is being removed but there was an unknown error while importing your existing configuration.\nPlease use the UI to configure Mastodon. Don't forget to delete the YAML configuration." - } - }, "entity": { "sensor": { "followers": { diff --git a/tests/components/mastodon/test_config_flow.py b/tests/components/mastodon/test_config_flow.py index 33f73812348c7..4b022df2ca262 100644 --- a/tests/components/mastodon/test_config_flow.py +++ b/tests/components/mastodon/test_config_flow.py @@ -6,7 +6,7 @@ import pytest from homeassistant.components.mastodon.const import CONF_BASE_URL, DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -160,53 +160,3 @@ async def test_duplicate( assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" - - -async def test_import_flow( - hass: HomeAssistant, - mock_mastodon_client: AsyncMock, - mock_setup_entry: AsyncMock, -) -> None: - """Test importing yaml config.""" - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_BASE_URL: "https://mastodon.social", - CONF_CLIENT_ID: "import_client_id", - CONF_CLIENT_SECRET: "import_client_secret", - CONF_ACCESS_TOKEN: "import_access_token", - }, - ) - assert result["type"] is FlowResultType.CREATE_ENTRY - - -@pytest.mark.parametrize( - ("exception", "error"), - [ - (MastodonNetworkError, "network_error"), - (MastodonUnauthorizedError, "unauthorized_error"), - (Exception, "unknown"), - ], -) -async def test_import_flow_abort( - hass: HomeAssistant, - mock_mastodon_client: AsyncMock, - mock_setup_entry: AsyncMock, - exception: Exception, - error: str, -) -> None: - """Test importing yaml config abort.""" - mock_mastodon_client.account_verify_credentials.side_effect = exception - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_BASE_URL: "https://mastodon.social", - CONF_CLIENT_ID: "import_client_id", - CONF_CLIENT_SECRET: "import_client_secret", - CONF_ACCESS_TOKEN: "import_access_token", - }, - ) - assert result["type"] is FlowResultType.ABORT