mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Remove deprecated Mastodon yaml config import (#134040)
* Remove Mastodon yaml import * Revert removal of async_migrate_entry
This commit is contained in:
parent
4080455c12
commit
4639f57014
@ -9,12 +9,7 @@ import voluptuous as vol
|
||||
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.helpers.selector import (
|
||||
)
|
||||
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 @@ class MastodonConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
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)
|
||||
|
@ -14,14 +14,12 @@ from homeassistant.components.notify import (
|
||||
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")
|
||||
|
@ -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": {
|
||||
|
@ -6,7 +6,7 @@ from mastodon.Mastodon import MastodonNetworkError, MastodonUnauthorizedError
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user