From 1e91ad6e230efaabaef3839711a6c31348700702 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Sat, 18 Oct 2025 20:49:26 +0200 Subject: [PATCH] Make sure user flow replace ignored in gardena_blueooth (#154778) --- .../gardena_bluetooth/config_flow.py | 2 +- .../components/gardena_bluetooth/conftest.py | 4 ++- .../gardena_bluetooth/test_config_flow.py | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/gardena_bluetooth/config_flow.py b/homeassistant/components/gardena_bluetooth/config_flow.py index 613d0cf21db..47db758c789 100644 --- a/homeassistant/components/gardena_bluetooth/config_flow.py +++ b/homeassistant/components/gardena_bluetooth/config_flow.py @@ -128,7 +128,7 @@ class GardenaBluetoothConfigFlow(ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() return await self.async_step_confirm() - 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): address = discovery_info.address if address in current_addresses or not _is_supported(discovery_info): diff --git a/tests/components/gardena_bluetooth/conftest.py b/tests/components/gardena_bluetooth/conftest.py index 0f877fce7db..6726525a317 100644 --- a/tests/components/gardena_bluetooth/conftest.py +++ b/tests/components/gardena_bluetooth/conftest.py @@ -25,7 +25,9 @@ from tests.common import MockConfigEntry, async_fire_time_changed def mock_entry(): """Create hass config fixture.""" return MockConfigEntry( - domain=DOMAIN, data={CONF_ADDRESS: WATER_TIMER_SERVICE_INFO.address} + domain=DOMAIN, + data={CONF_ADDRESS: WATER_TIMER_SERVICE_INFO.address}, + unique_id=WATER_TIMER_SERVICE_INFO.address, ) diff --git a/tests/components/gardena_bluetooth/test_config_flow.py b/tests/components/gardena_bluetooth/test_config_flow.py index b20395ec40f..3181e602d59 100644 --- a/tests/components/gardena_bluetooth/test_config_flow.py +++ b/tests/components/gardena_bluetooth/test_config_flow.py @@ -8,7 +8,9 @@ from syrupy.assertion import SnapshotAssertion from homeassistant import config_entries from homeassistant.components.gardena_bluetooth.const import DOMAIN +from homeassistant.const import CONF_ADDRESS from homeassistant.core import HomeAssistant +from homeassistant.data_entry_flow import FlowResultType from . import ( MISSING_MANUFACTURER_DATA_SERVICE_INFO, @@ -18,6 +20,7 @@ from . import ( WATER_TIMER_UNNAMED_SERVICE_INFO, ) +from tests.common import MockConfigEntry from tests.components.bluetooth import inject_bluetooth_service_info pytestmark = pytest.mark.usefixtures("mock_setup_entry") @@ -51,6 +54,39 @@ async def test_user_selection( assert result == snapshot +async def test_user_selection_replaces_ignored(hass: HomeAssistant) -> None: + """Test setup from service info cache replaces an ignored entry.""" + entry = MockConfigEntry( + domain=DOMAIN, + unique_id=WATER_TIMER_SERVICE_INFO.address, + ) + entry.source = config_entries.SOURCE_IGNORE + entry.add_to_hass(hass) + + inject_bluetooth_service_info(hass, WATER_TIMER_SERVICE_INFO) + await hass.async_block_till_done(wait_background_tasks=True) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] == FlowResultType.FORM + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_ADDRESS: WATER_TIMER_SERVICE_INFO.address}, + ) + + assert result["type"] == FlowResultType.FORM + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={}, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + + async def test_failed_connect( hass: HomeAssistant, mock_client: Mock,