mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 03:07:50 +00:00
Remove Aftership import issue when entry already exists (#105476)
This commit is contained in:
parent
47819bde4f
commit
32681acc79
@ -10,7 +10,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
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.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
|
|
||||||
@ -51,25 +51,6 @@ class AfterShipConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||||
"""Import configuration from yaml."""
|
"""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(
|
async_create_issue(
|
||||||
self.hass,
|
self.hass,
|
||||||
HOMEASSISTANT_DOMAIN,
|
HOMEASSISTANT_DOMAIN,
|
||||||
@ -84,6 +65,8 @@ class AfterShipConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"integration_title": "AfterShip",
|
"integration_title": "AfterShip",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._async_abort_entries_match({CONF_API_KEY: config[CONF_API_KEY]})
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=config.get(CONF_NAME, "AfterShip"),
|
title=config.get(CONF_NAME, "AfterShip"),
|
||||||
data={CONF_API_KEY: config[CONF_API_KEY]},
|
data={CONF_API_KEY: config[CONF_API_KEY]},
|
||||||
|
@ -49,10 +49,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"issues": {
|
"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": {
|
"deprecated_yaml_import_issue_cannot_connect": {
|
||||||
"title": "The {integration_title} YAML configuration import failed",
|
"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."
|
"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."
|
||||||
|
@ -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."""
|
"""Test importing yaml config."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -95,11 +97,12 @@ async def test_import_flow(hass: HomeAssistant, mock_setup_entry) -> None:
|
|||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_API_KEY: "yaml-api-key",
|
CONF_API_KEY: "yaml-api-key",
|
||||||
}
|
}
|
||||||
issue_registry = ir.async_get(hass)
|
|
||||||
assert len(issue_registry.issues) == 1
|
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."""
|
"""Test importing yaml config where entry already exists."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data={CONF_API_KEY: "yaml-api-key"})
|
entry = MockConfigEntry(domain=DOMAIN, data={CONF_API_KEY: "yaml-api-key"})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -108,3 +111,4 @@ async def test_import_flow_already_exists(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
assert result["type"] == FlowResultType.ABORT
|
assert result["type"] == FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
assert len(issue_registry.issues) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user