|
7 | 7 | import pytest |
8 | 8 | from syrupy.assertion import SnapshotAssertion |
9 | 9 |
|
10 | | -from homeassistant.components import automation, script |
11 | | -from homeassistant.components.automation import automations_with_entity |
12 | | -from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN |
13 | | -from homeassistant.components.script import scripts_with_entity |
14 | | -from homeassistant.components.smartthings import DOMAIN, MAIN |
15 | 10 | from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform |
16 | 11 | from homeassistant.core import HomeAssistant |
17 | | -from homeassistant.helpers import entity_registry as er, issue_registry as ir |
18 | | -from homeassistant.setup import async_setup_component |
| 12 | +from homeassistant.helpers import entity_registry as er |
19 | 13 |
|
20 | 14 | from . import ( |
21 | 15 | setup_integration, |
@@ -105,172 +99,3 @@ async def test_availability_at_start( |
105 | 99 | hass.states.get("binary_sensor.refrigerator_fridge_door").state |
106 | 100 | == STATE_UNAVAILABLE |
107 | 101 | ) |
108 | | - |
109 | | - |
110 | | -@pytest.mark.parametrize( |
111 | | - ("device_fixture", "unique_id", "suggested_object_id", "issue_string", "entity_id"), |
112 | | - [ |
113 | | - ( |
114 | | - "virtual_valve", |
115 | | - f"612ab3c2-3bb0-48f7-b2c0-15b169cb2fc3_{MAIN}_{Capability.VALVE}_{Attribute.VALVE}_{Attribute.VALVE}", |
116 | | - "volvo_valve", |
117 | | - "valve", |
118 | | - "binary_sensor.volvo_valve", |
119 | | - ), |
120 | | - ( |
121 | | - "da_ref_normal_000001", |
122 | | - f"7db87911-7dce-1cf2-7119-b953432a2f09_{MAIN}_{Capability.CONTACT_SENSOR}_{Attribute.CONTACT}_{Attribute.CONTACT}", |
123 | | - "refrigerator_door", |
124 | | - "fridge_door", |
125 | | - "binary_sensor.refrigerator_door", |
126 | | - ), |
127 | | - ], |
128 | | -) |
129 | | -async def test_create_issue_with_items( |
130 | | - hass: HomeAssistant, |
131 | | - devices: AsyncMock, |
132 | | - mock_config_entry: MockConfigEntry, |
133 | | - entity_registry: er.EntityRegistry, |
134 | | - issue_registry: ir.IssueRegistry, |
135 | | - unique_id: str, |
136 | | - suggested_object_id: str, |
137 | | - issue_string: str, |
138 | | - entity_id: str, |
139 | | -) -> None: |
140 | | - """Test we create an issue when an automation or script is using a deprecated entity.""" |
141 | | - issue_id = f"deprecated_binary_{issue_string}_{entity_id}" |
142 | | - |
143 | | - entity_entry = entity_registry.async_get_or_create( |
144 | | - BINARY_SENSOR_DOMAIN, |
145 | | - DOMAIN, |
146 | | - unique_id, |
147 | | - suggested_object_id=suggested_object_id, |
148 | | - original_name=suggested_object_id, |
149 | | - ) |
150 | | - |
151 | | - assert await async_setup_component( |
152 | | - hass, |
153 | | - automation.DOMAIN, |
154 | | - { |
155 | | - automation.DOMAIN: { |
156 | | - "id": "test", |
157 | | - "alias": "test", |
158 | | - "trigger": {"platform": "state", "entity_id": entity_id}, |
159 | | - "action": { |
160 | | - "action": "automation.turn_on", |
161 | | - "target": { |
162 | | - "entity_id": "automation.test", |
163 | | - }, |
164 | | - }, |
165 | | - } |
166 | | - }, |
167 | | - ) |
168 | | - assert await async_setup_component( |
169 | | - hass, |
170 | | - script.DOMAIN, |
171 | | - { |
172 | | - script.DOMAIN: { |
173 | | - "test": { |
174 | | - "sequence": [ |
175 | | - { |
176 | | - "condition": "state", |
177 | | - "entity_id": entity_id, |
178 | | - "state": "on", |
179 | | - }, |
180 | | - ], |
181 | | - } |
182 | | - } |
183 | | - }, |
184 | | - ) |
185 | | - |
186 | | - await setup_integration(hass, mock_config_entry) |
187 | | - |
188 | | - assert hass.states.get(entity_id).state == STATE_OFF |
189 | | - |
190 | | - assert automations_with_entity(hass, entity_id)[0] == "automation.test" |
191 | | - assert scripts_with_entity(hass, entity_id)[0] == "script.test" |
192 | | - |
193 | | - issue = issue_registry.async_get_issue(DOMAIN, issue_id) |
194 | | - assert issue is not None |
195 | | - assert issue.translation_key == f"deprecated_binary_{issue_string}_scripts" |
196 | | - assert issue.translation_placeholders == { |
197 | | - "entity_id": entity_id, |
198 | | - "entity_name": suggested_object_id, |
199 | | - "items": "- [test](/config/automation/edit/test)\n- [test](/config/script/edit/test)", |
200 | | - } |
201 | | - |
202 | | - entity_registry.async_update_entity( |
203 | | - entity_entry.entity_id, |
204 | | - disabled_by=er.RegistryEntryDisabler.USER, |
205 | | - ) |
206 | | - |
207 | | - await hass.config_entries.async_reload(mock_config_entry.entry_id) |
208 | | - await hass.async_block_till_done() |
209 | | - |
210 | | - # Assert the issue is no longer present |
211 | | - assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
212 | | - |
213 | | - |
214 | | -@pytest.mark.parametrize( |
215 | | - ("device_fixture", "unique_id", "suggested_object_id", "issue_string", "entity_id"), |
216 | | - [ |
217 | | - ( |
218 | | - "virtual_valve", |
219 | | - f"612ab3c2-3bb0-48f7-b2c0-15b169cb2fc3_{MAIN}_{Capability.VALVE}_{Attribute.VALVE}_{Attribute.VALVE}", |
220 | | - "volvo_valve", |
221 | | - "valve", |
222 | | - "binary_sensor.volvo_valve", |
223 | | - ), |
224 | | - ( |
225 | | - "da_ref_normal_000001", |
226 | | - f"7db87911-7dce-1cf2-7119-b953432a2f09_{MAIN}_{Capability.CONTACT_SENSOR}_{Attribute.CONTACT}_{Attribute.CONTACT}", |
227 | | - "refrigerator_door", |
228 | | - "fridge_door", |
229 | | - "binary_sensor.refrigerator_door", |
230 | | - ), |
231 | | - ], |
232 | | -) |
233 | | -async def test_create_issue( |
234 | | - hass: HomeAssistant, |
235 | | - devices: AsyncMock, |
236 | | - mock_config_entry: MockConfigEntry, |
237 | | - entity_registry: er.EntityRegistry, |
238 | | - issue_registry: ir.IssueRegistry, |
239 | | - unique_id: str, |
240 | | - suggested_object_id: str, |
241 | | - issue_string: str, |
242 | | - entity_id: str, |
243 | | -) -> None: |
244 | | - """Test we create an issue when an automation or script is using a deprecated entity.""" |
245 | | - issue_id = f"deprecated_binary_{issue_string}_{entity_id}" |
246 | | - |
247 | | - entity_entry = entity_registry.async_get_or_create( |
248 | | - BINARY_SENSOR_DOMAIN, |
249 | | - DOMAIN, |
250 | | - unique_id, |
251 | | - suggested_object_id=suggested_object_id, |
252 | | - original_name=suggested_object_id, |
253 | | - ) |
254 | | - |
255 | | - await setup_integration(hass, mock_config_entry) |
256 | | - |
257 | | - assert hass.states.get(entity_id).state == STATE_OFF |
258 | | - |
259 | | - issue = issue_registry.async_get_issue(DOMAIN, issue_id) |
260 | | - assert issue is not None |
261 | | - assert issue.translation_key == f"deprecated_binary_{issue_string}" |
262 | | - assert issue.translation_placeholders == { |
263 | | - "entity_id": entity_id, |
264 | | - "entity_name": suggested_object_id, |
265 | | - } |
266 | | - |
267 | | - entity_registry.async_update_entity( |
268 | | - entity_entry.entity_id, |
269 | | - disabled_by=er.RegistryEntryDisabler.USER, |
270 | | - ) |
271 | | - |
272 | | - await hass.config_entries.async_reload(mock_config_entry.entry_id) |
273 | | - await hass.async_block_till_done() |
274 | | - |
275 | | - # Assert the issue is no longer present |
276 | | - assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
0 commit comments