Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove yaml import from incomfort integration after deprecation time #132275

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 4 additions & 68 deletions homeassistant/components/incomfort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,16 @@

from aiohttp import ClientResponseError
from incomfortclient import IncomfortError, InvalidHeaterList
import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import config_validation as cv, issue_registry as ir
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN
from .const import DOMAIN # noqa: F401 # ignore unused
jbouwh marked this conversation as resolved.
Show resolved Hide resolved
from .coordinator import InComfortDataCoordinator, async_connect_gateway
from .errors import InConfortTimeout, InConfortUnknownError, NoHeaters, NotFound

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Inclusive(CONF_USERNAME, "credentials"): cv.string,
vol.Inclusive(CONF_PASSWORD, "credentials"): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)

PLATFORMS = (
Platform.WATER_HEATER,
Platform.BINARY_SENSOR,
Expand All @@ -43,53 +26,6 @@
type InComfortConfigEntry = ConfigEntry[InComfortDataCoordinator]


async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
"""Import config entry from configuration.yaml."""
if not hass.config_entries.async_entries(DOMAIN):
# Start import flow
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
if result["type"] == FlowResultType.ABORT:
ir.async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
breaks_in_ha_version="2025.1.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
translation_placeholders={
"domain": DOMAIN,
"integration_title": INTEGRATION_TITLE,
},
)
return

ir.async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2025.1.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": INTEGRATION_TITLE,
},
)


async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool:
"""Create an Intergas InComfort/Intouch system."""
if config := hass_config.get(DOMAIN):
hass.async_create_task(_async_import(hass, config))
return True


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a config entry."""
try:
Expand Down
8 changes: 0 additions & 8 deletions homeassistant/components/incomfort/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,3 @@ async def async_step_user(
return self.async_show_form(
step_id="user", data_schema=CONFIG_SCHEMA, errors=errors
)

async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import `incomfort` config entry from configuration.yaml."""
errors: dict[str, str] | None = None
if (errors := await async_try_connect_gateway(self.hass, import_data)) is None:
return self.async_create_entry(title=TITLE, data=import_data)
reason = next(iter(errors.items()))[1]
return self.async_abort(reason=reason)
46 changes: 1 addition & 45 deletions tests/components/incomfort/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest

from homeassistant.components.incomfort import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -38,50 +38,6 @@ async def test_form(
assert len(mock_setup_entry.mock_calls) == 1


async def test_import(
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_incomfort: MagicMock
) -> None:
"""Test we van import from YAML."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_CONFIG
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Intergas InComfort/Intouch Lan2RF gateway"
assert result["data"] == MOCK_CONFIG
assert len(mock_setup_entry.mock_calls) == 1


@pytest.mark.parametrize(
("exc", "abort_reason"),
[
(IncomfortError(ClientResponseError(None, None, status=401)), "auth_error"),
(IncomfortError(ClientResponseError(None, None, status=404)), "not_found"),
(IncomfortError(ClientResponseError(None, None, status=500)), "unknown"),
(IncomfortError, "unknown"),
(InvalidHeaterList, "no_heaters"),
(ValueError, "unknown"),
(TimeoutError, "timeout_error"),
],
)
async def test_import_fails(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
mock_incomfort: MagicMock,
exc: Exception,
abort_reason: str,
) -> None:
"""Test YAML import fails."""
mock_incomfort().heaters.side_effect = exc
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_CONFIG
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == abort_reason
assert len(mock_setup_entry.mock_calls) == 0


async def test_entry_already_configured(hass: HomeAssistant) -> None:
"""Test aborting if the entry is already configured."""
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
Expand Down