Remove YAML import from lcl integration after 6 months deprecation (#130305)

This commit is contained in:
Jan Bouwhuis
2024-11-10 21:10:18 +01:00
committed by GitHub
parent f7f1830b7e
commit c52a893e21
5 changed files with 3 additions and 274 deletions
+1 -82
View File
@@ -23,9 +23,7 @@ from homeassistant.const import (
CONF_PORT,
CONF_USERNAME,
)
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers import issue_registry as ir
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@@ -48,83 +46,6 @@ IMPORT_DATA = {
}
async def test_step_import(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test for import step."""
with (
patch("homeassistant.components.lcn.PchkConnectionManager.async_connect"),
patch("homeassistant.components.lcn.async_setup", return_value=True),
patch("homeassistant.components.lcn.async_setup_entry", return_value=True),
):
data = IMPORT_DATA.copy()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=data
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "pchk"
assert result["data"] == IMPORT_DATA
assert issue_registry.async_get_issue(
HOMEASSISTANT_DOMAIN, f"deprecated_yaml_{DOMAIN}"
)
async def test_step_import_existing_host(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test for update of config_entry if imported host already exists."""
# Create config entry and add it to hass
mock_data = IMPORT_DATA.copy()
mock_data.update({CONF_SK_NUM_TRIES: 3, CONF_DIM_MODE: 50})
mock_entry = MockConfigEntry(domain=DOMAIN, data=mock_data)
mock_entry.add_to_hass(hass)
# Initialize a config flow with different data but same host address
with patch("homeassistant.components.lcn.PchkConnectionManager.async_connect"):
imported_data = IMPORT_DATA.copy()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=imported_data
)
# Check if config entry was updated
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "existing_configuration_updated"
assert mock_entry.source == config_entries.SOURCE_IMPORT
assert mock_entry.data == IMPORT_DATA
assert issue_registry.async_get_issue(
HOMEASSISTANT_DOMAIN, f"deprecated_yaml_{DOMAIN}"
)
@pytest.mark.parametrize(
("error", "reason"),
[
(PchkAuthenticationError, "authentication_error"),
(PchkLicenseError, "license_error"),
(TimeoutError, "connection_refused"),
],
)
async def test_step_import_error(
hass: HomeAssistant, issue_registry: ir.IssueRegistry, error, reason
) -> None:
"""Test for error in import is handled correctly."""
with patch(
"homeassistant.components.lcn.PchkConnectionManager.async_connect",
side_effect=error,
):
data = IMPORT_DATA.copy()
data.update({CONF_HOST: "pchk"})
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=data
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == reason
assert issue_registry.async_get_issue(DOMAIN, reason)
async def test_show_form(hass: HomeAssistant) -> None:
"""Test that the form is served with no input."""
flow = LcnFlowHandler()
@@ -140,7 +61,6 @@ async def test_step_user(hass: HomeAssistant) -> None:
"""Test for user step."""
with (
patch("homeassistant.components.lcn.PchkConnectionManager.async_connect"),
patch("homeassistant.components.lcn.async_setup", return_value=True),
patch("homeassistant.components.lcn.async_setup_entry", return_value=True),
):
data = CONNECTION_DATA.copy()
@@ -210,7 +130,6 @@ async def test_step_reconfigure(hass: HomeAssistant, entry: MockConfigEntry) ->
with (
patch("homeassistant.components.lcn.PchkConnectionManager.async_connect"),
patch("homeassistant.components.lcn.async_setup", return_value=True),
patch("homeassistant.components.lcn.async_setup_entry", return_value=True),
):
result = await hass.config_entries.flow.async_configure(
-27
View File
@@ -16,7 +16,6 @@ from .conftest import (
MockPchkConnectionManager,
create_config_entry,
init_integration,
setup_component,
)
@@ -83,18 +82,6 @@ async def test_async_setup_entry_update(
assert dummy_entity in entity_registry.entities.values()
assert dummy_device in device_registry.devices.values()
# setup new entry with same data via import step (should cleanup dummy device)
with patch(
"homeassistant.components.lcn.config_flow.validate_connection",
return_value=None,
):
await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=entry.data
)
assert dummy_device not in device_registry.devices.values()
assert dummy_entity not in entity_registry.entities.values()
@pytest.mark.parametrize(
"exception", [PchkAuthenticationError, PchkLicenseError, TimeoutError]
@@ -114,20 +101,6 @@ async def test_async_setup_entry_raises_authentication_error(
assert entry.state is ConfigEntryState.SETUP_ERROR
async def test_async_setup_from_configuration_yaml(hass: HomeAssistant) -> None:
"""Test a successful setup using data from configuration.yaml."""
with (
patch(
"homeassistant.components.lcn.config_flow.validate_connection",
return_value=None,
),
patch("homeassistant.components.lcn.async_setup_entry") as async_setup_entry,
):
await setup_component(hass)
assert async_setup_entry.await_count == 2
@patch("homeassistant.components.lcn.PchkConnectionManager", MockPchkConnectionManager)
async def test_migrate_1_1(hass: HomeAssistant, entry) -> None:
"""Test migration config entry."""