|
4 | 4 |
|
5 | 5 | from homeassistant import config_entries |
6 | 6 | from homeassistant.components.sensorpro.const import DOMAIN |
| 7 | +from homeassistant.config_entries import SOURCE_IGNORE |
7 | 8 | from homeassistant.core import HomeAssistant |
8 | 9 | from homeassistant.data_entry_flow import FlowResultType |
9 | 10 |
|
@@ -203,3 +204,39 @@ async def test_async_step_user_takes_precedence_over_discovery( |
203 | 204 |
|
204 | 205 | # Verify the original one was aborted |
205 | 206 | assert not hass.config_entries.flow.async_progress(DOMAIN) |
| 207 | + |
| 208 | + |
| 209 | +async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None: |
| 210 | + """Test the user initiated form can replace an ignored device.""" |
| 211 | + entry = MockConfigEntry( |
| 212 | + domain=DOMAIN, |
| 213 | + unique_id="aa:bb:cc:dd:ee:ff", |
| 214 | + source=SOURCE_IGNORE, |
| 215 | + data={}, |
| 216 | + ) |
| 217 | + entry.add_to_hass(hass) |
| 218 | + |
| 219 | + with patch( |
| 220 | + "homeassistant.components.sensorpro.config_flow.async_discovered_service_info", |
| 221 | + return_value=[SENSORPRO_SERVICE_INFO], |
| 222 | + ): |
| 223 | + result = await hass.config_entries.flow.async_init( |
| 224 | + DOMAIN, context={"source": config_entries.SOURCE_USER} |
| 225 | + ) |
| 226 | + assert result["type"] is FlowResultType.FORM |
| 227 | + assert result["step_id"] == "user" |
| 228 | + |
| 229 | + # Verify the ignored device is in the dropdown |
| 230 | + assert "aa:bb:cc:dd:ee:ff" in result["data_schema"].schema["address"].container |
| 231 | + |
| 232 | + with patch( |
| 233 | + "homeassistant.components.sensorpro.async_setup_entry", return_value=True |
| 234 | + ): |
| 235 | + result2 = await hass.config_entries.flow.async_configure( |
| 236 | + result["flow_id"], |
| 237 | + user_input={"address": "aa:bb:cc:dd:ee:ff"}, |
| 238 | + ) |
| 239 | + assert result2["type"] is FlowResultType.CREATE_ENTRY |
| 240 | + assert result2["title"] == "T201 EEFF" |
| 241 | + assert result2["data"] == {} |
| 242 | + assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff" |
0 commit comments