Remove deprecated YAML import from seventeentrack (#125852)
parent
ff31efdbf7
commit
590b3d0fd4
|
@ -97,38 +97,6 @@ class SeventeenTrackConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Import 17Track config from configuration.yaml."""
|
||||
|
||||
client = self._get_client()
|
||||
|
||||
try:
|
||||
login_result = await client.profile.login(
|
||||
import_data[CONF_USERNAME], import_data[CONF_PASSWORD]
|
||||
)
|
||||
except SeventeenTrackError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
if not login_result:
|
||||
return self.async_abort(reason="invalid_auth")
|
||||
|
||||
account_id = client.profile.account_id
|
||||
|
||||
await self.async_set_unique_id(account_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=import_data[CONF_USERNAME],
|
||||
data=import_data,
|
||||
options={
|
||||
CONF_SHOW_ARCHIVED: import_data.get(
|
||||
CONF_SHOW_ARCHIVED, DEFAULT_SHOW_ARCHIVED
|
||||
),
|
||||
CONF_SHOW_DELIVERED: import_data.get(
|
||||
CONF_SHOW_DELIVERED, DEFAULT_SHOW_DELIVERED
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
@callback
|
||||
def _get_client(self):
|
||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||
|
|
|
@ -4,31 +4,15 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_LOCATION,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
entity_registry as er,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_LOCATION
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import SeventeenTrackCoordinator
|
||||
|
@ -43,8 +27,6 @@ from .const import (
|
|||
ATTR_TRACKING_INFO_LANGUAGE,
|
||||
ATTR_TRACKING_NUMBER,
|
||||
ATTRIBUTION,
|
||||
CONF_SHOW_ARCHIVED,
|
||||
CONF_SHOW_DELIVERED,
|
||||
DEPRECATED_KEY,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
|
@ -54,59 +36,6 @@ from .const import (
|
|||
VALUE_DELIVERED,
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_SHOW_ARCHIVED, default=False): cv.boolean,
|
||||
vol.Optional(CONF_SHOW_DELIVERED, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=seventeentrack"}
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Initialize 17Track import from config."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
if (
|
||||
result["type"] == FlowResultType.CREATE_ENTRY
|
||||
or result["reason"] == "already_configured"
|
||||
):
|
||||
async_create_issue(
|
||||
hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
is_fixable=False,
|
||||
breaks_in_ha_version="2024.10.0",
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": "17Track",
|
||||
},
|
||||
)
|
||||
else:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"deprecated_yaml_import_issue_{result['reason']}",
|
||||
breaks_in_ha_version="2024.10.0",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
|
||||
translation_placeholders=ISSUE_PLACEHOLDER,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -38,14 +38,6 @@
|
|||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml_import_issue_cannot_connect": {
|
||||
"title": "The 17Track YAML configuration import cannot connect to server",
|
||||
"description": "Configuring 17Track using YAML is being removed but there was a connection error importing your YAML configuration.\n\nThings you can try:\nMake sure your home assistant can reach the web.\n\nThen restart Home Assistant to try importing this integration again.\n\nAlternatively, you may remove the 17Track configuration from your YAML configuration entirely, restart Home Assistant, and add the 17Track integration manually."
|
||||
},
|
||||
"deprecated_yaml_import_issue_invalid_auth": {
|
||||
"title": "The 17Track YAML configuration import request failed due to invalid authentication",
|
||||
"description": "Configuring 17Track using YAML is being removed but there were invalid credentials provided while importing your existing configuration.\nSetup will not proceed.\n\nVerify that your 17Track credentials are correct and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the 17Track configuration from your YAML configuration entirely, restart Home Assistant, and add the 17Track integration manually."
|
||||
},
|
||||
"deprecate_sensor": {
|
||||
"title": "17Track package sensors are being deprecated",
|
||||
"fix_flow": {
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.seventeentrack.const import (
|
|||
CONF_SHOW_ARCHIVED,
|
||||
CONF_SHOW_DELIVERED,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
@ -105,55 +105,6 @@ async def test_flow_fails(
|
|||
}
|
||||
|
||||
|
||||
async def test_import_flow(hass: HomeAssistant, mock_seventeentrack: AsyncMock) -> None:
|
||||
"""Test the import configuration flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=VALID_CONFIG_OLD,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "someemail@gmail.com"
|
||||
assert result["data"][CONF_USERNAME] == "someemail@gmail.com"
|
||||
assert result["data"][CONF_PASSWORD] == "edc3eee7330e4fdda04489e3fbc283d0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("return_value", "side_effect", "error"),
|
||||
[
|
||||
(
|
||||
False,
|
||||
None,
|
||||
"invalid_auth",
|
||||
),
|
||||
(
|
||||
True,
|
||||
SeventeenTrackError(),
|
||||
"cannot_connect",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_import_flow_cannot_connect_error(
|
||||
hass: HomeAssistant,
|
||||
mock_seventeentrack: AsyncMock,
|
||||
return_value,
|
||||
side_effect,
|
||||
error,
|
||||
) -> None:
|
||||
"""Test the import configuration flow with error."""
|
||||
mock_seventeentrack.return_value.profile.login.return_value = return_value
|
||||
mock_seventeentrack.return_value.profile.login.side_effect = side_effect
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=VALID_CONFIG_OLD,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == error
|
||||
|
||||
|
||||
async def test_option_flow(hass: HomeAssistant, mock_seventeentrack: AsyncMock) -> None:
|
||||
"""Test option flow."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -181,28 +132,3 @@ async def test_option_flow(hass: HomeAssistant, mock_seventeentrack: AsyncMock)
|
|||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][CONF_SHOW_ARCHIVED]
|
||||
assert not result["data"][CONF_SHOW_DELIVERED]
|
||||
|
||||
|
||||
async def test_import_flow_already_configured(
|
||||
hass: HomeAssistant, mock_seventeentrack: AsyncMock
|
||||
) -> None:
|
||||
"""Test the import configuration flow with error."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=VALID_CONFIG,
|
||||
unique_id=ACCOUNT_ID,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
result_aborted = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
VALID_CONFIG,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result_aborted["type"] is FlowResultType.ABORT
|
||||
assert result_aborted["reason"] == "already_configured"
|
||||
|
|
|
@ -8,7 +8,6 @@ from freezegun.api import FrozenDateTimeFactory
|
|||
from pyseventeentrack.errors import SeventeenTrackError
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import goto_future, init_integration
|
||||
|
@ -306,15 +305,3 @@ async def test_non_valid_platform_config(
|
|||
assert await async_setup_component(hass, "sensor", VALID_PLATFORM_CONFIG_FULL)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) == 0
|
||||
|
||||
|
||||
async def test_full_valid_platform_config(
|
||||
hass: HomeAssistant,
|
||||
mock_seventeentrack: AsyncMock,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Ensure everything starts correctly."""
|
||||
assert await async_setup_component(hass, "sensor", VALID_PLATFORM_CONFIG_FULL)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) == len(DEFAULT_SUMMARY.keys())
|
||||
assert len(issue_registry.issues) == 2
|
||||
|
|
Loading…
Reference in New Issue