Skip to content

Commit 10439ee

Browse files
authored
Allow ignored sensorpro devices to be set up from the user flow (home-assistant#155628)
1 parent 75cc866 commit 10439ee

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

homeassistant/components/sensorpro/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def async_step_user(
7272
title=self._discovered_devices[address], data={}
7373
)
7474

75-
current_addresses = self._async_current_ids()
75+
current_addresses = self._async_current_ids(include_ignore=False)
7676
for discovery_info in async_discovered_service_info(self.hass, False):
7777
address = discovery_info.address
7878
if address in current_addresses or address in self._discovered_devices:

tests/components/sensorpro/test_config_flow.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from homeassistant import config_entries
66
from homeassistant.components.sensorpro.const import DOMAIN
7+
from homeassistant.config_entries import SOURCE_IGNORE
78
from homeassistant.core import HomeAssistant
89
from homeassistant.data_entry_flow import FlowResultType
910

@@ -203,3 +204,39 @@ async def test_async_step_user_takes_precedence_over_discovery(
203204

204205
# Verify the original one was aborted
205206
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

Comments
 (0)