mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Remove yaml import from incomfort integration after deprecation time (#132275)
* Remove yaml import from incomfort integration after deprecation time * Cleanup CONFIG_SCHEMA * restore missing DOMAIN import * Import DOMAIN from const
This commit is contained in:
parent
f4896f7b09
commit
5fdd705edf
@ -4,33 +4,15 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from aiohttp import ClientResponseError
|
from aiohttp import ClientResponseError
|
||||||
from incomfortclient import IncomfortError, InvalidHeaterList
|
from incomfortclient import IncomfortError, InvalidHeaterList
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
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 .coordinator import InComfortDataCoordinator, async_connect_gateway
|
from .coordinator import InComfortDataCoordinator, async_connect_gateway
|
||||||
from .errors import InConfortTimeout, InConfortUnknownError, NoHeaters, NotFound
|
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 = (
|
PLATFORMS = (
|
||||||
Platform.WATER_HEATER,
|
Platform.WATER_HEATER,
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -43,53 +25,6 @@ INTEGRATION_TITLE = "Intergas InComfort/Intouch Lan2RF gateway"
|
|||||||
type InComfortConfigEntry = ConfigEntry[InComfortDataCoordinator]
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
try:
|
try:
|
||||||
|
@ -81,11 +81,3 @@ class InComfortConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=CONFIG_SCHEMA, errors=errors
|
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)
|
|
||||||
|
@ -7,7 +7,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
from incomfortclient import DisplayCode
|
from incomfortclient import DisplayCode
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.incomfort import DOMAIN
|
from homeassistant.components.incomfort.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ from aiohttp import ClientResponseError
|
|||||||
from incomfortclient import IncomfortError, InvalidHeaterList
|
from incomfortclient import IncomfortError, InvalidHeaterList
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.incomfort import DOMAIN
|
from homeassistant.components.incomfort.const 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.const import CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -38,50 +38,6 @@ async def test_form(
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
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:
|
async def test_entry_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test aborting if the entry is already configured."""
|
"""Test aborting if the entry is already configured."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user