diff --git a/homeassistant/components/aftership/config_flow.py b/homeassistant/components/aftership/config_flow.py index 9d377ae8ce7..f48221840ba 100644 --- a/homeassistant/components/aftership/config_flow.py +++ b/homeassistant/components/aftership/config_flow.py @@ -8,10 +8,8 @@ from pyaftership import AfterShip, AfterShipException import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_NAME -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN +from homeassistant.const import CONF_API_KEY from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from .const import DOMAIN @@ -47,26 +45,3 @@ class AfterShipConfigFlow(ConfigFlow, domain=DOMAIN): data_schema=vol.Schema({vol.Required(CONF_API_KEY): str}), errors=errors, ) - - async def async_step_import(self, config: dict[str, Any]) -> ConfigFlowResult: - """Import configuration from yaml.""" - async_create_issue( - self.hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.4.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "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]}, - ) diff --git a/homeassistant/components/aftership/sensor.py b/homeassistant/components/aftership/sensor.py index 055d31fc16d..f96281fce8f 100644 --- a/homeassistant/components/aftership/sensor.py +++ b/homeassistant/components/aftership/sensor.py @@ -5,24 +5,16 @@ import logging from typing import Any, Final from pyaftership import AfterShip, AfterShipException -import voluptuous as vol -from homeassistant.components.sensor import ( - PLATFORM_SCHEMA as BASE_PLATFORM_SCHEMA, - SensorEntity, -) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_NAME +from homeassistant.components.sensor import SensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, ServiceCall -from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import Throttle from .const import ( @@ -33,7 +25,6 @@ from .const import ( CONF_SLUG, CONF_TITLE, CONF_TRACKING_NUMBER, - DEFAULT_NAME, DOMAIN, MIN_TIME_BETWEEN_UPDATES, REMOVE_TRACKING_SERVICE_SCHEMA, @@ -44,47 +35,7 @@ from .const import ( _LOGGER: Final = logging.getLogger(__name__) -PLATFORM_SCHEMA: Final = BASE_PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_API_KEY): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the AfterShip sensor platform.""" - aftership = AfterShip( - api_key=config[CONF_API_KEY], session=async_get_clientsession(hass) - ) - try: - await aftership.trackings.list() - except AfterShipException: - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_import_issue_cannot_connect", - breaks_in_ha_version="2024.4.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml_import_issue_cannot_connect", - translation_placeholders={ - "integration_title": "AfterShip", - "url": "/config/integrations/dashboard/add?domain=aftership", - }, - ) - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=config - ) - ) +PLATFORM_SCHEMA: Final = cv.removed(DOMAIN, raise_if_present=False) async def async_setup_entry( diff --git a/tests/components/aftership/test_config_flow.py b/tests/components/aftership/test_config_flow.py index 4668e7a61e4..8e9f1a34d31 100644 --- a/tests/components/aftership/test_config_flow.py +++ b/tests/components/aftership/test_config_flow.py @@ -4,13 +4,10 @@ from unittest.mock import AsyncMock, patch from pyaftership import AfterShipException from homeassistant.components.aftership.const import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from homeassistant.helpers import issue_registry as ir - -from tests.common import MockConfigEntry async def test_full_user_flow(hass: HomeAssistant, mock_setup_entry) -> None: @@ -75,40 +72,3 @@ async def test_flow_cannot_connect(hass: HomeAssistant, mock_setup_entry) -> Non assert result["data"] == { CONF_API_KEY: "mock-api-key", } - - -async def test_import_flow( - hass: HomeAssistant, issue_registry: ir.IssueRegistry, mock_setup_entry -) -> None: - """Test importing yaml config.""" - - with patch( - "homeassistant.components.aftership.config_flow.AfterShip", - return_value=AsyncMock(), - ) as mock_aftership: - mock_aftership.return_value.trackings.return_value.list.return_value = {} - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={CONF_API_KEY: "yaml-api-key"}, - ) - assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == "AfterShip" - assert result["data"] == { - CONF_API_KEY: "yaml-api-key", - } - assert len(issue_registry.issues) == 1 - - -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) - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_API_KEY: "yaml-api-key"} - ) - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "already_configured" - assert len(issue_registry.issues) == 1