Skip to content

Commit 0145f52

Browse files
committed
Remove deprecated import from stiebel_eltron
1 parent 38c5e48 commit 0145f52

File tree

3 files changed

+8
-261
lines changed

3 files changed

+8
-261
lines changed

homeassistant/components/stiebel_eltron/__init__.py

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,22 @@
11
"""The component for STIEBEL ELTRON heat pumps with ISGWeb Modbus module."""
22

33
import logging
4-
from typing import Any
54

65
from pymodbus.client import ModbusTcpClient
76
from pystiebeleltron.pystiebeleltron import StiebelEltronAPI
8-
import voluptuous as vol
9-
10-
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
11-
from homeassistant.const import (
12-
CONF_HOST,
13-
CONF_NAME,
14-
CONF_PORT,
15-
DEVICE_DEFAULT_NAME,
16-
Platform,
17-
)
7+
8+
from homeassistant.config_entries import ConfigEntry
9+
from homeassistant.const import CONF_HOST, CONF_PORT, Platform
1810
from homeassistant.core import HomeAssistant
19-
from homeassistant.data_entry_flow import FlowResultType
2011
from homeassistant.exceptions import ConfigEntryNotReady
21-
from homeassistant.helpers import config_validation as cv, issue_registry as ir
2212
from homeassistant.helpers.typing import ConfigType
2313

24-
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN
25-
26-
MODBUS_DOMAIN = "modbus"
27-
28-
CONFIG_SCHEMA = vol.Schema(
29-
{
30-
DOMAIN: vol.Schema(
31-
{
32-
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string,
33-
vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string,
34-
}
35-
)
36-
},
37-
extra=vol.ALLOW_EXTRA,
38-
)
39-
4014
_LOGGER = logging.getLogger(__name__)
4115
_PLATFORMS: list[Platform] = [Platform.CLIMATE]
4216

4317

44-
async def _async_import(hass: HomeAssistant, config: ConfigType) -> None:
45-
"""Set up the STIEBEL ELTRON component."""
46-
hub_config: dict[str, Any] | None = None
47-
if MODBUS_DOMAIN in config:
48-
for hub in config[MODBUS_DOMAIN]:
49-
if hub[CONF_NAME] == config[DOMAIN][CONF_HUB]:
50-
hub_config = hub
51-
break
52-
if hub_config is None:
53-
ir.async_create_issue(
54-
hass,
55-
DOMAIN,
56-
"deprecated_yaml_import_issue_missing_hub",
57-
breaks_in_ha_version="2025.11.0",
58-
is_fixable=False,
59-
issue_domain=DOMAIN,
60-
severity=ir.IssueSeverity.WARNING,
61-
translation_key="deprecated_yaml_import_issue_missing_hub",
62-
translation_placeholders={
63-
"domain": DOMAIN,
64-
"integration_title": "Stiebel Eltron",
65-
},
66-
)
67-
return
68-
result = await hass.config_entries.flow.async_init(
69-
DOMAIN,
70-
context={"source": SOURCE_IMPORT},
71-
data={
72-
CONF_HOST: hub_config[CONF_HOST],
73-
CONF_PORT: hub_config[CONF_PORT],
74-
CONF_NAME: config[DOMAIN][CONF_NAME],
75-
},
76-
)
77-
if (
78-
result.get("type") is FlowResultType.ABORT
79-
and result.get("reason") != "already_configured"
80-
):
81-
ir.async_create_issue(
82-
hass,
83-
DOMAIN,
84-
f"deprecated_yaml_import_issue_{result['reason']}",
85-
breaks_in_ha_version="2025.11.0",
86-
is_fixable=False,
87-
issue_domain=DOMAIN,
88-
severity=ir.IssueSeverity.WARNING,
89-
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
90-
translation_placeholders={
91-
"domain": DOMAIN,
92-
"integration_title": "Stiebel Eltron",
93-
},
94-
)
95-
return
96-
97-
ir.async_create_issue(
98-
hass,
99-
DOMAIN,
100-
"deprecated_yaml",
101-
breaks_in_ha_version="2025.11.0",
102-
is_fixable=False,
103-
issue_domain=DOMAIN,
104-
severity=ir.IssueSeverity.WARNING,
105-
translation_key="deprecated_yaml",
106-
translation_placeholders={
107-
"domain": DOMAIN,
108-
"integration_title": "Stiebel Eltron",
109-
},
110-
)
111-
112-
11318
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
11419
"""Set up the STIEBEL ELTRON component."""
115-
if DOMAIN in config:
116-
hass.async_create_task(_async_import(hass, config))
11720
return True
11821

11922

tests/components/stiebel_eltron/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from homeassistant.components.stiebel_eltron import DOMAIN
8+
from homeassistant.components.stiebel_eltron.const import DOMAIN
99
from homeassistant.const import CONF_HOST, CONF_PORT
1010

1111
from tests.common import MockConfigEntry
Lines changed: 4 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,21 @@
11
"""Tests for the STIEBEL ELTRON integration."""
22

3-
from unittest.mock import AsyncMock
4-
5-
import pytest
6-
7-
from homeassistant.components.stiebel_eltron.const import CONF_HUB, DEFAULT_HUB, DOMAIN
8-
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
3+
from homeassistant.components.stiebel_eltron.const import DOMAIN
94
from homeassistant.core import HomeAssistant
105
from homeassistant.helpers import issue_registry as ir
116
from homeassistant.setup import async_setup_component
127

138

14-
@pytest.mark.usefixtures("mock_stiebel_eltron_client")
159
async def test_async_setup_success(
1610
hass: HomeAssistant,
1711
issue_registry: ir.IssueRegistry,
1812
) -> None:
1913
"""Test successful async_setup."""
20-
config = {
21-
DOMAIN: {
22-
CONF_NAME: "Stiebel Eltron",
23-
CONF_HUB: DEFAULT_HUB,
24-
},
25-
"modbus": [
26-
{
27-
CONF_NAME: DEFAULT_HUB,
28-
CONF_HOST: "1.1.1.1",
29-
CONF_PORT: 502,
30-
}
31-
],
32-
}
33-
34-
assert await async_setup_component(hass, DOMAIN, config)
35-
await hass.async_block_till_done()
36-
37-
# Verify the issue is created
38-
issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml")
39-
assert issue
40-
assert issue.active is True
41-
assert issue.severity == ir.IssueSeverity.WARNING
42-
43-
44-
@pytest.mark.usefixtures("mock_stiebel_eltron_client")
45-
async def test_async_setup_already_configured(
46-
hass: HomeAssistant,
47-
issue_registry: ir.IssueRegistry,
48-
mock_config_entry,
49-
) -> None:
50-
"""Test we handle already configured."""
51-
mock_config_entry.add_to_hass(hass)
52-
53-
config = {
54-
DOMAIN: {
55-
CONF_NAME: "Stiebel Eltron",
56-
CONF_HUB: DEFAULT_HUB,
57-
},
58-
"modbus": [
59-
{
60-
CONF_NAME: DEFAULT_HUB,
61-
CONF_HOST: "1.1.1.1",
62-
CONF_PORT: 502,
63-
}
64-
],
65-
}
14+
config = {}
6615

6716
assert await async_setup_component(hass, DOMAIN, config)
6817
await hass.async_block_till_done()
6918

70-
# Verify the issue is created
19+
# No issue should be created by the new async_setup
7120
issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml")
72-
assert issue
73-
assert issue.active is True
74-
assert issue.severity == ir.IssueSeverity.WARNING
75-
76-
77-
async def test_async_setup_with_non_existing_hub(
78-
hass: HomeAssistant, issue_registry: ir.IssueRegistry
79-
) -> None:
80-
"""Test async_setup with non-existing modbus hub."""
81-
config = {
82-
DOMAIN: {
83-
CONF_NAME: "Stiebel Eltron",
84-
CONF_HUB: "non_existing_hub",
85-
},
86-
}
87-
88-
assert await async_setup_component(hass, DOMAIN, config)
89-
await hass.async_block_till_done()
90-
91-
# Verify the issue is created
92-
issue = issue_registry.async_get_issue(
93-
DOMAIN, "deprecated_yaml_import_issue_missing_hub"
94-
)
95-
assert issue
96-
assert issue.active is True
97-
assert issue.is_fixable is False
98-
assert issue.is_persistent is False
99-
assert issue.translation_key == "deprecated_yaml_import_issue_missing_hub"
100-
assert issue.severity == ir.IssueSeverity.WARNING
101-
102-
103-
async def test_async_setup_import_failure(
104-
hass: HomeAssistant,
105-
issue_registry: ir.IssueRegistry,
106-
mock_stiebel_eltron_client: AsyncMock,
107-
) -> None:
108-
"""Test async_setup with import failure."""
109-
config = {
110-
DOMAIN: {
111-
CONF_NAME: "Stiebel Eltron",
112-
CONF_HUB: DEFAULT_HUB,
113-
},
114-
"modbus": [
115-
{
116-
CONF_NAME: DEFAULT_HUB,
117-
CONF_HOST: "invalid_host",
118-
CONF_PORT: 502,
119-
}
120-
],
121-
}
122-
123-
# Simulate an import failure
124-
mock_stiebel_eltron_client.update.side_effect = Exception("Import failure")
125-
126-
assert await async_setup_component(hass, DOMAIN, config)
127-
await hass.async_block_till_done()
128-
129-
# Verify the issue is created
130-
issue = issue_registry.async_get_issue(
131-
DOMAIN, "deprecated_yaml_import_issue_unknown"
132-
)
133-
assert issue
134-
assert issue.active is True
135-
assert issue.is_fixable is False
136-
assert issue.is_persistent is False
137-
assert issue.translation_key == "deprecated_yaml_import_issue_unknown"
138-
assert issue.severity == ir.IssueSeverity.WARNING
139-
140-
141-
@pytest.mark.usefixtures("mock_modbus")
142-
async def test_async_setup_cannot_connect(
143-
hass: HomeAssistant,
144-
issue_registry: ir.IssueRegistry,
145-
mock_stiebel_eltron_client: AsyncMock,
146-
) -> None:
147-
"""Test async_setup with import failure."""
148-
config = {
149-
DOMAIN: {
150-
CONF_NAME: "Stiebel Eltron",
151-
CONF_HUB: DEFAULT_HUB,
152-
},
153-
"modbus": [
154-
{
155-
CONF_NAME: DEFAULT_HUB,
156-
CONF_HOST: "invalid_host",
157-
CONF_PORT: 502,
158-
}
159-
],
160-
}
161-
162-
# Simulate a cannot connect error
163-
mock_stiebel_eltron_client.update.return_value = False
164-
165-
assert await async_setup_component(hass, DOMAIN, config)
166-
await hass.async_block_till_done()
167-
168-
# Verify the issue is created
169-
issue = issue_registry.async_get_issue(
170-
DOMAIN, "deprecated_yaml_import_issue_cannot_connect"
171-
)
172-
assert issue
173-
assert issue.active is True
174-
assert issue.is_fixable is False
175-
assert issue.is_persistent is False
176-
assert issue.translation_key == "deprecated_yaml_import_issue_cannot_connect"
177-
assert issue.severity == ir.IssueSeverity.WARNING
21+
assert issue is None

0 commit comments

Comments
 (0)