Allow ignored xiaomi_ble devices to be set up from the user flow (#137115)

This commit is contained in:
J. Nick Koston 2025-02-01 13:16:39 -06:00 committed by Paulus Schoutsen
parent 4c8f716320
commit 21a85c014a
2 changed files with 33 additions and 1 deletions

View File

@ -306,7 +306,7 @@ class XiaomiConfigFlow(ConfigFlow, domain=DOMAIN):
return self._async_get_or_create_entry()
current_addresses = self._async_current_ids()
current_addresses = self._async_current_ids(include_ignore=False)
for discovery_info in async_discovered_service_info(self.hass, False):
address = discovery_info.address
if address in current_addresses or address in self._discovered_devices:

View File

@ -634,6 +634,38 @@ async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None:
assert result2["result"].unique_id == "58:2D:34:35:93:21"
async def test_async_step_user_replace_ignored_entry(hass: HomeAssistant) -> None:
"""Test setup from service info can replace an ignored entry."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=LYWSDCGQ_SERVICE_INFO.address,
data={},
source=config_entries.SOURCE_IGNORE,
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.xiaomi_ble.config_flow.async_discovered_service_info",
return_value=[LYWSDCGQ_SERVICE_INFO],
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
with patch(
"homeassistant.components.xiaomi_ble.async_setup_entry", return_value=True
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={"address": "58:2D:34:35:93:21"},
)
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == "Temperature/Humidity Sensor 9321 (LYWSDCGQ)"
assert result2["data"] == {}
assert result2["result"].unique_id == "58:2D:34:35:93:21"
async def test_async_step_user_short_payload(hass: HomeAssistant) -> None:
"""Test setup from service info cache with devices found but short payloads."""
with patch(