|
8 | 8 | from homeassistant.components.kulersky.config_flow import DOMAIN |
9 | 9 | from homeassistant.config_entries import ( |
10 | 10 | SOURCE_BLUETOOTH, |
| 11 | + SOURCE_IGNORE, |
11 | 12 | SOURCE_INTEGRATION_DISCOVERY, |
12 | 13 | SOURCE_USER, |
13 | 14 | ) |
14 | 15 | from homeassistant.const import CONF_ADDRESS |
15 | 16 | from homeassistant.core import HomeAssistant |
16 | 17 | from homeassistant.data_entry_flow import FlowResultType |
17 | 18 |
|
| 19 | +from tests.common import MockConfigEntry |
18 | 20 | from tests.components.bluetooth import generate_advertisement_data, generate_ble_device |
19 | 21 |
|
20 | 22 | KULERSKY_SERVICE_INFO = BluetoothServiceInfoBleak( |
@@ -180,3 +182,44 @@ async def test_unexpected_error(hass: HomeAssistant) -> None: |
180 | 182 |
|
181 | 183 | assert result["type"] is FlowResultType.FORM |
182 | 184 | assert result["errors"]["base"] == "unknown" |
| 185 | + |
| 186 | + |
| 187 | +async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None: |
| 188 | + """Test the user flow can replace an ignored device.""" |
| 189 | + entry = MockConfigEntry( |
| 190 | + domain=DOMAIN, |
| 191 | + unique_id="AA:BB:CC:DD:EE:FF", |
| 192 | + source=SOURCE_IGNORE, |
| 193 | + data={}, |
| 194 | + ) |
| 195 | + entry.add_to_hass(hass) |
| 196 | + |
| 197 | + with patch( |
| 198 | + "homeassistant.components.kulersky.config_flow.async_discovered_service_info", |
| 199 | + return_value=[KULERSKY_SERVICE_INFO], |
| 200 | + ): |
| 201 | + result = await hass.config_entries.flow.async_init( |
| 202 | + DOMAIN, |
| 203 | + context={"source": SOURCE_USER}, |
| 204 | + ) |
| 205 | + await hass.async_block_till_done() |
| 206 | + |
| 207 | + assert result["type"] is FlowResultType.FORM |
| 208 | + assert result["step_id"] == "user" |
| 209 | + |
| 210 | + # Verify the ignored device is in the dropdown |
| 211 | + assert "AA:BB:CC:DD:EE:FF" in result["data_schema"].schema[CONF_ADDRESS].container |
| 212 | + |
| 213 | + with patch("pykulersky.Light", Mock(return_value=AsyncMock())): |
| 214 | + result2 = await hass.config_entries.flow.async_configure( |
| 215 | + result["flow_id"], |
| 216 | + {CONF_ADDRESS: "AA:BB:CC:DD:EE:FF"}, |
| 217 | + ) |
| 218 | + await hass.async_block_till_done() |
| 219 | + |
| 220 | + assert result2["type"] is FlowResultType.CREATE_ENTRY |
| 221 | + assert result2["title"] == "KulerLight (EEFF)" |
| 222 | + assert result2["data"] == { |
| 223 | + CONF_ADDRESS: "AA:BB:CC:DD:EE:FF", |
| 224 | + } |
| 225 | + assert result2["result"].unique_id == "AA:BB:CC:DD:EE:FF" |
0 commit comments