1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Remove deprecated import from stiebel_eltron (#158110)

This commit is contained in:
Manuel Stahl
2025-12-23 22:05:22 +01:00
committed by GitHub
parent b07b699e79
commit 7c71c0377f
3 changed files with 7 additions and 266 deletions

View File

@@ -1,122 +1,19 @@
"""The component for STIEBEL ELTRON heat pumps with ISGWeb Modbus module."""
import logging
from typing import Any
from pymodbus.client import ModbusTcpClient
from pystiebeleltron.pystiebeleltron import StiebelEltronAPI
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_PORT,
DEVICE_DEFAULT_NAME,
Platform,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT, Platform
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv, issue_registry as ir
from homeassistant.helpers.typing import ConfigType
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN
MODBUS_DOMAIN = "modbus"
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string,
vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
_LOGGER = logging.getLogger(__name__)
_PLATFORMS: list[Platform] = [Platform.CLIMATE]
async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
"""Set up the STIEBEL ELTRON component."""
hub_config: dict[str, Any] | None = None
if MODBUS_DOMAIN in config:
for hub in config[MODBUS_DOMAIN]:
if hub[CONF_NAME] == config[DOMAIN][CONF_HUB]:
hub_config = hub
break
if hub_config is None:
ir.async_create_issue(
hass,
DOMAIN,
"deprecated_yaml_import_issue_missing_hub",
breaks_in_ha_version="2025.11.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key="deprecated_yaml_import_issue_missing_hub",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Stiebel Eltron",
},
)
return
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_HOST: hub_config[CONF_HOST],
CONF_PORT: hub_config[CONF_PORT],
CONF_NAME: config[DOMAIN][CONF_NAME],
},
)
if (
result.get("type") is FlowResultType.ABORT
and result.get("reason") != "already_configured"
):
ir.async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
breaks_in_ha_version="2025.11.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": "Stiebel Eltron",
},
)
return
ir.async_create_issue(
hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version="2025.11.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=ir.IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Stiebel Eltron",
},
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the STIEBEL ELTRON component."""
if DOMAIN in config:
hass.async_create_task(_async_import(hass, config))
return True
type StiebelEltronConfigEntry = ConfigEntry[StiebelEltronAPI]

View File

@@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch
import pytest
from homeassistant.components.stiebel_eltron import DOMAIN
from homeassistant.components.stiebel_eltron.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_PORT
from tests.common import MockConfigEntry

View File

@@ -1,177 +1,21 @@
"""Tests for the STIEBEL ELTRON integration."""
from unittest.mock import AsyncMock
import pytest
from homeassistant.components.stiebel_eltron.const import CONF_HUB, DEFAULT_HUB, DOMAIN
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.components.stiebel_eltron.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
@pytest.mark.usefixtures("mock_stiebel_eltron_client")
async def test_async_setup_success(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test successful async_setup."""
config = {
DOMAIN: {
CONF_NAME: "Stiebel Eltron",
CONF_HUB: DEFAULT_HUB,
},
"modbus": [
{
CONF_NAME: DEFAULT_HUB,
CONF_HOST: "1.1.1.1",
CONF_PORT: 502,
}
],
}
config = {}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
# Verify the issue is created
# No issue should be created by the new async_setup
issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml")
assert issue
assert issue.active is True
assert issue.severity == ir.IssueSeverity.WARNING
@pytest.mark.usefixtures("mock_stiebel_eltron_client")
async def test_async_setup_already_configured(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
mock_config_entry,
) -> None:
"""Test we handle already configured."""
mock_config_entry.add_to_hass(hass)
config = {
DOMAIN: {
CONF_NAME: "Stiebel Eltron",
CONF_HUB: DEFAULT_HUB,
},
"modbus": [
{
CONF_NAME: DEFAULT_HUB,
CONF_HOST: "1.1.1.1",
CONF_PORT: 502,
}
],
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
# Verify the issue is created
issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml")
assert issue
assert issue.active is True
assert issue.severity == ir.IssueSeverity.WARNING
async def test_async_setup_with_non_existing_hub(
hass: HomeAssistant, issue_registry: ir.IssueRegistry
) -> None:
"""Test async_setup with non-existing modbus hub."""
config = {
DOMAIN: {
CONF_NAME: "Stiebel Eltron",
CONF_HUB: "non_existing_hub",
},
}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
# Verify the issue is created
issue = issue_registry.async_get_issue(
DOMAIN, "deprecated_yaml_import_issue_missing_hub"
)
assert issue
assert issue.active is True
assert issue.is_fixable is False
assert issue.is_persistent is False
assert issue.translation_key == "deprecated_yaml_import_issue_missing_hub"
assert issue.severity == ir.IssueSeverity.WARNING
async def test_async_setup_import_failure(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
mock_stiebel_eltron_client: AsyncMock,
) -> None:
"""Test async_setup with import failure."""
config = {
DOMAIN: {
CONF_NAME: "Stiebel Eltron",
CONF_HUB: DEFAULT_HUB,
},
"modbus": [
{
CONF_NAME: DEFAULT_HUB,
CONF_HOST: "invalid_host",
CONF_PORT: 502,
}
],
}
# Simulate an import failure
mock_stiebel_eltron_client.update.side_effect = Exception("Import failure")
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
# Verify the issue is created
issue = issue_registry.async_get_issue(
DOMAIN, "deprecated_yaml_import_issue_unknown"
)
assert issue
assert issue.active is True
assert issue.is_fixable is False
assert issue.is_persistent is False
assert issue.translation_key == "deprecated_yaml_import_issue_unknown"
assert issue.severity == ir.IssueSeverity.WARNING
@pytest.mark.usefixtures("mock_modbus")
async def test_async_setup_cannot_connect(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
mock_stiebel_eltron_client: AsyncMock,
) -> None:
"""Test async_setup with import failure."""
config = {
DOMAIN: {
CONF_NAME: "Stiebel Eltron",
CONF_HUB: DEFAULT_HUB,
},
"modbus": [
{
CONF_NAME: DEFAULT_HUB,
CONF_HOST: "invalid_host",
CONF_PORT: 502,
}
],
}
# Simulate a cannot connect error
mock_stiebel_eltron_client.update.return_value = False
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
# Verify the issue is created
issue = issue_registry.async_get_issue(
DOMAIN, "deprecated_yaml_import_issue_cannot_connect"
)
assert issue
assert issue.active is True
assert issue.is_fixable is False
assert issue.is_persistent is False
assert issue.translation_key == "deprecated_yaml_import_issue_cannot_connect"
assert issue.severity == ir.IssueSeverity.WARNING
assert issue is None