From 7bad27c4122c0165ff2cd9ca0d1cd7e75c2bfe64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 24 May 2026 12:16:28 -0500 Subject: [PATCH] Trigger active scan when picking a snooz device in the config flow (#172073) --- homeassistant/components/snooz/config_flow.py | 2 ++ tests/components/snooz/test_config_flow.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/snooz/config_flow.py b/homeassistant/components/snooz/config_flow.py index 0de188e0c98..e2748446db3 100644 --- a/homeassistant/components/snooz/config_flow.py +++ b/homeassistant/components/snooz/config_flow.py @@ -7,6 +7,7 @@ from typing import Any from pysnooz.advertisement import SnoozAdvertisementData import voluptuous as vol +from homeassistant.components import bluetooth from homeassistant.components.bluetooth import ( BluetoothScanningMode, BluetoothServiceInfo, @@ -94,6 +95,7 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() return self._create_snooz_entry(discovered) + await bluetooth.async_request_active_scan(self.hass) configured_addresses = self._async_current_ids(include_ignore=False) for info in async_discovered_service_info(self.hass): diff --git a/tests/components/snooz/test_config_flow.py b/tests/components/snooz/test_config_flow.py index abb95571be6..558af9ad23f 100644 --- a/tests/components/snooz/test_config_flow.py +++ b/tests/components/snooz/test_config_flow.py @@ -88,9 +88,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.snooz.config_flow.async_discovered_service_info", - return_value=[SNOOZ_SERVICE_INFO_PAIRING], + with ( + patch( + "homeassistant.components.snooz.config_flow.async_discovered_service_info", + return_value=[SNOOZ_SERVICE_INFO_PAIRING], + ), + patch( + "homeassistant.components.snooz.config_flow.bluetooth.async_request_active_scan" + ) as mock_request_active_scan, ): result = await hass.config_entries.flow.async_init( DOMAIN, @@ -101,6 +106,7 @@ async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None: assert result["data_schema"] # ensure discovered devices are listed as options assert result["data_schema"].schema["name"].container == [TEST_SNOOZ_DISPLAY_NAME] + mock_request_active_scan.assert_awaited_once_with(hass) await _test_setup_entry( hass, result["flow_id"], {CONF_NAME: TEST_SNOOZ_DISPLAY_NAME} )