Allow ignored keymitt_ble devices to be set up from the user flow (#155616)

This commit is contained in:
J. Nick Koston
2025-11-01 10:51:52 -05:00
committed by GitHub
parent 9f8c9940bd
commit f04bb69dbc
2 changed files with 51 additions and 2 deletions

View File

@@ -85,7 +85,7 @@ class MicroBotConfigFlow(ConfigFlow, domain=DOMAIN):
if discovery := self._discovered_adv:
self._discovered_advs[discovery.address] = discovery
else:
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):
self._ble_device = discovery_info.device
address = discovery_info.address

View File

@@ -2,7 +2,7 @@
from unittest.mock import ANY, AsyncMock, patch
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_IGNORE, SOURCE_USER
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_ADDRESS
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@@ -188,3 +188,52 @@ async def test_no_link(hass: HomeAssistant) -> None:
assert result3["errors"] == {"base": "linking"}
assert len(mock_setup_entry.mock_calls) == 0
async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None:
"""Test the user initiated form can replace an ignored device."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="aa:bb:cc:dd:ee:ff",
source=SOURCE_IGNORE,
data={},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.keymitt_ble.config_flow.async_discovered_service_info",
return_value=[SERVICE_INFO],
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
# Verify the ignored device is in the dropdown
assert "aa:bb:cc:dd:ee:ff" in result["data_schema"].schema["address"].container
with patch_microbot_api():
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
USER_INPUT,
)
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.FORM
assert result2["step_id"] == "link"
with patch_microbot_api(), patch_async_setup_entry() as mock_setup_entry:
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"],
USER_INPUT,
)
await hass.async_block_till_done()
assert result3["type"] is FlowResultType.CREATE_ENTRY
assert result3["result"].data == {
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
CONF_ACCESS_TOKEN: ANY,
}
assert result3["result"].unique_id == "aa:bb:cc:dd:ee:ff"
assert len(mock_setup_entry.mock_calls) == 1