From c65de7521fed0cb8d0c1906bbaa6ad7f645f13a4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 24 May 2026 12:20:48 -0500 Subject: [PATCH] Trigger active scan when picking a tilt_ble device in the config flow (#172053) --- homeassistant/components/tilt_ble/config_flow.py | 2 ++ tests/components/tilt_ble/test_config_flow.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tilt_ble/config_flow.py b/homeassistant/components/tilt_ble/config_flow.py index 36acfc652d08..9a762b82460f 100644 --- a/homeassistant/components/tilt_ble/config_flow.py +++ b/homeassistant/components/tilt_ble/config_flow.py @@ -5,6 +5,7 @@ from typing import Any from tilt_ble import TiltBluetoothDeviceData as DeviceData import voluptuous as vol +from homeassistant.components import bluetooth from homeassistant.components.bluetooth import ( BluetoothServiceInfoBleak, async_discovered_service_info, @@ -70,6 +71,7 @@ class TiltConfigFlow(ConfigFlow, domain=DOMAIN): title=self._discovered_devices[address], data={} ) + await bluetooth.async_request_active_scan(self.hass) current_addresses = self._async_current_ids(include_ignore=False) for discovery_info in async_discovered_service_info(self.hass, False): address = discovery_info.address diff --git a/tests/components/tilt_ble/test_config_flow.py b/tests/components/tilt_ble/test_config_flow.py index 9c9450f39961..79d5df0aa956 100644 --- a/tests/components/tilt_ble/test_config_flow.py +++ b/tests/components/tilt_ble/test_config_flow.py @@ -56,9 +56,14 @@ async def test_async_step_user_no_devices_found(hass: HomeAssistant) -> None: async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None: """Test setup from service info cache with devices found.""" - with patch( - "homeassistant.components.tilt_ble.config_flow.async_discovered_service_info", - return_value=[TILT_GREEN_SERVICE_INFO], + with ( + patch( + "homeassistant.components.tilt_ble.config_flow.async_discovered_service_info", + return_value=[TILT_GREEN_SERVICE_INFO], + ), + patch( + "homeassistant.components.tilt_ble.config_flow.bluetooth.async_request_active_scan" + ) as mock_request_active_scan, ): result = await hass.config_entries.flow.async_init( DOMAIN, @@ -66,6 +71,7 @@ async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None: ) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" + mock_request_active_scan.assert_awaited_once_with(hass) with patch( "homeassistant.components.tilt_ble.async_setup_entry", return_value=True ):