Skip to content

Commit

Permalink
Allow ignored switchbot devices to be set up from the user flow (home…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Feb 1, 2025
1 parent 84e15e1 commit 64d2f84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/switchbot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ async def async_step_encrypted_key(

@callback
def _async_discover_devices(self) -> None:
current_addresses = self._async_current_ids()
current_addresses = self._async_current_ids(include_ignore=False)
for connectable in (True, False):
for discovery_info in async_discovered_service_info(self.hass, connectable):
address = discovery_info.address
Expand Down
35 changes: 34 additions & 1 deletion tests/components/switchbot/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CONF_LOCK_NIGHTLATCH,
CONF_RETRY_COUNT,
)
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_ADDRESS,
CONF_NAME,
Expand Down Expand Up @@ -303,6 +303,39 @@ async def test_user_setup_wohand_already_configured(hass: HomeAssistant) -> None
assert result["reason"] == "no_devices_found"


async def test_user_setup_wohand_replaces_ignored(hass: HomeAssistant) -> None:
"""Test setting up a switchbot replaces an ignored entry."""
entry = MockConfigEntry(
domain=DOMAIN, data={}, unique_id="aabbccddeeff", source=SOURCE_IGNORE
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
return_value=[WOHAND_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"] == "confirm"

with patch_async_setup_entry() as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
)
await hass.async_block_till_done()

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Bot EEFF"
assert result["data"] == {
CONF_ADDRESS: "AA:BB:CC:DD:EE:FF",
CONF_SENSOR_TYPE: "bot",
}

assert len(mock_setup_entry.mock_calls) == 1


async def test_user_setup_wocurtain(hass: HomeAssistant) -> None:
"""Test the user initiated form with password and valid mac."""

Expand Down

0 comments on commit 64d2f84

Please sign in to comment.