Skip to content

Commit

Permalink
Remove Aftership import issue when entry already exists (#105476)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek committed Dec 11, 2023
1 parent 47819bd commit 32681ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
23 changes: 3 additions & 20 deletions homeassistant/components/aftership/config_flow.py
Expand Up @@ -10,7 +10,7 @@
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_API_KEY, CONF_NAME
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from homeassistant.data_entry_flow import AbortFlow, FlowResult
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue

Expand Down Expand Up @@ -51,25 +51,6 @@ async def async_step_user(

async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"""Import configuration from yaml."""
try:
self._async_abort_entries_match({CONF_API_KEY: config[CONF_API_KEY]})
except AbortFlow as err:
async_create_issue(
self.hass,
DOMAIN,
"deprecated_yaml_import_issue_already_configured",
breaks_in_ha_version="2024.4.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml_import_issue_already_configured",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "AfterShip",
},
)
raise err

async_create_issue(
self.hass,
HOMEASSISTANT_DOMAIN,
Expand All @@ -84,6 +65,8 @@ async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"integration_title": "AfterShip",
},
)

self._async_abort_entries_match({CONF_API_KEY: config[CONF_API_KEY]})
return self.async_create_entry(
title=config.get(CONF_NAME, "AfterShip"),
data={CONF_API_KEY: config[CONF_API_KEY]},
Expand Down
4 changes: 0 additions & 4 deletions homeassistant/components/aftership/strings.json
Expand Up @@ -49,10 +49,6 @@
}
},
"issues": {
"deprecated_yaml_import_issue_already_configured": {
"title": "The {integration_title} YAML configuration import failed",
"description": "Configuring {integration_title} using YAML is being removed but the YAML configuration was already imported.\n\nRemove the YAML configuration and restart Home Assistant."
},
"deprecated_yaml_import_issue_cannot_connect": {
"title": "The {integration_title} YAML configuration import failed",
"description": "Configuring {integration_title} using YAML is being removed but there was an connection error importing your YAML configuration.\n\nEnsure connection to {integration_title} works and restart Home Assistant to try again or remove the {integration_title} YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
Expand Down
10 changes: 7 additions & 3 deletions tests/components/aftership/test_config_flow.py
Expand Up @@ -77,7 +77,9 @@ async def test_flow_cannot_connect(hass: HomeAssistant, mock_setup_entry) -> Non
}


async def test_import_flow(hass: HomeAssistant, mock_setup_entry) -> None:
async def test_import_flow(
hass: HomeAssistant, issue_registry: ir.IssueRegistry, mock_setup_entry
) -> None:
"""Test importing yaml config."""

with patch(
Expand All @@ -95,11 +97,12 @@ async def test_import_flow(hass: HomeAssistant, mock_setup_entry) -> None:
assert result["data"] == {
CONF_API_KEY: "yaml-api-key",
}
issue_registry = ir.async_get(hass)
assert len(issue_registry.issues) == 1


async def test_import_flow_already_exists(hass: HomeAssistant) -> None:
async def test_import_flow_already_exists(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test importing yaml config where entry already exists."""
entry = MockConfigEntry(domain=DOMAIN, data={CONF_API_KEY: "yaml-api-key"})
entry.add_to_hass(hass)
Expand All @@ -108,3 +111,4 @@ async def test_import_flow_already_exists(hass: HomeAssistant) -> None:
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert len(issue_registry.issues) == 1

0 comments on commit 32681ac

Please sign in to comment.