|
1 | 1 | """Tests for the STIEBEL ELTRON integration.""" |
2 | 2 |
|
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 |
9 | 4 | from homeassistant.core import HomeAssistant |
10 | 5 | from homeassistant.helpers import issue_registry as ir |
11 | 6 | from homeassistant.setup import async_setup_component |
12 | 7 |
|
13 | 8 |
|
14 | | -@pytest.mark.usefixtures("mock_stiebel_eltron_client") |
15 | 9 | async def test_async_setup_success( |
16 | 10 | hass: HomeAssistant, |
17 | 11 | issue_registry: ir.IssueRegistry, |
18 | 12 | ) -> None: |
19 | 13 | """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 = {} |
66 | 15 |
|
67 | 16 | assert await async_setup_component(hass, DOMAIN, config) |
68 | 17 | await hass.async_block_till_done() |
69 | 18 |
|
70 | | - # Verify the issue is created |
| 19 | + # No issue should be created by the new async_setup |
71 | 20 | 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