diff --git a/homeassistant/components/snooz/config_flow.py b/homeassistant/components/snooz/config_flow.py index 0fe776451571..ff635539c5c2 100644 --- a/homeassistant/components/snooz/config_flow.py +++ b/homeassistant/components/snooz/config_flow.py @@ -19,7 +19,7 @@ from homeassistant.components.bluetooth import ( async_process_advertisements, ) from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_TOKEN +from homeassistant.const import CONF_ADDRESS, CONF_TOKEN from .const import DOMAIN @@ -87,18 +87,13 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Handle the user step to pick discovered device.""" if user_input is not None: - name = user_input[CONF_NAME] - - discovered = self._discovered_devices[name] - - assert discovered is not None - + address = user_input[CONF_ADDRESS] + discovered = self._discovered_devices[address] self._discovery = discovered if not discovered.device.is_pairing: return await self.async_step_wait_for_pairing_mode() - address = discovered.info.address await self.async_set_unique_id(address, raise_on_progress=False) self._abort_if_unique_id_configured() return self._create_snooz_entry(discovered) @@ -111,8 +106,7 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN): if address in configured_addresses: continue if (device := parse_snooz_advertisement(info)) is not None: - discovered = DiscoveredSnooz(info, device) - self._discovered_devices[discovered.display_name] = discovered + self._discovered_devices[address] = DiscoveredSnooz(info, device) if not self._discovered_devices: return self.async_abort(reason="no_devices_found") @@ -121,10 +115,11 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN): step_id="user", data_schema=probatio.Schema( { - # Name field is no longer allowed in config flow schemas - # pylint: disable-next=home-assistant-config-flow-name-field - probatio.Required(CONF_NAME): probatio.In( - [d.display_name for d in self._discovered_devices.values()] + probatio.Required(CONF_ADDRESS): probatio.In( + { + address: discovered.display_name + for address, discovered in self._discovered_devices.items() + } ) } ), diff --git a/homeassistant/components/snooz/strings.json b/homeassistant/components/snooz/strings.json index f6247efa8e92..4c8fca0f4553 100644 --- a/homeassistant/components/snooz/strings.json +++ b/homeassistant/components/snooz/strings.json @@ -17,8 +17,7 @@ }, "user": { "data": { - "address": "[%key:common::config_flow::data::device%]", - "name": "[%key:common::config_flow::data::name%]" + "address": "[%key:common::config_flow::data::device%]" }, "description": "[%key:component::bluetooth::config::step::user::description%]" } diff --git a/tests/components/snooz/test_config_flow.py b/tests/components/snooz/test_config_flow.py index 1e90070c99bf..cca18d7f30a6 100644 --- a/tests/components/snooz/test_config_flow.py +++ b/tests/components/snooz/test_config_flow.py @@ -8,7 +8,7 @@ from pytest_homeassistant.common import MockConfigEntry from homeassistant import config_entries from homeassistant.components.snooz.const import DOMAIN from homeassistant.config_entries import SOURCE_IGNORE -from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_TOKEN +from homeassistant.const import CONF_ADDRESS, CONF_TOKEN from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -105,11 +105,11 @@ async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None: assert result["step_id"] == "user" assert result["data_schema"] # ensure discovered devices are listed as options - assert result["data_schema"].schema["name"].container == [TEST_SNOOZ_DISPLAY_NAME] + assert result["data_schema"].schema["address"].container == { + TEST_ADDRESS: 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} - ) + await _test_setup_entry(hass, result["flow_id"], {CONF_ADDRESS: TEST_ADDRESS}) async def test_async_step_user_with_found_devices_waits_to_pair( @@ -127,7 +127,7 @@ async def test_async_step_user_with_found_devices_waits_to_pair( assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" - await _test_pairs(hass, result["flow_id"], {CONF_NAME: TEST_SNOOZ_DISPLAY_NAME}) + await _test_pairs(hass, result["flow_id"], {CONF_ADDRESS: TEST_ADDRESS}) async def test_async_step_user_with_found_devices_retries_pairing( @@ -145,7 +145,7 @@ async def test_async_step_user_with_found_devices_retries_pairing( assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" - user_input = {CONF_NAME: TEST_SNOOZ_DISPLAY_NAME} + user_input = {CONF_ADDRESS: TEST_ADDRESS} retry_id = await _test_pairs_timeout(hass, result["flow_id"], user_input) await _test_pairs(hass, retry_id, user_input) @@ -167,14 +167,14 @@ async def test_async_step_user_device_added_between_steps(hass: HomeAssistant) - entry = MockConfigEntry( domain=DOMAIN, unique_id=TEST_ADDRESS, - data={CONF_NAME: TEST_SNOOZ_DISPLAY_NAME, CONF_TOKEN: TEST_PAIRING_TOKEN}, + data={CONF_ADDRESS: TEST_ADDRESS, CONF_TOKEN: TEST_PAIRING_TOKEN}, ) entry.add_to_hass(hass) with patch("homeassistant.components.snooz.async_setup_entry", return_value=None): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - user_input={CONF_NAME: TEST_SNOOZ_DISPLAY_NAME}, + user_input={CONF_ADDRESS: TEST_ADDRESS}, ) assert result2["type"] is FlowResultType.ABORT assert result2["reason"] == "already_configured" @@ -187,7 +187,7 @@ async def test_async_step_user_with_found_devices_already_setup( entry = MockConfigEntry( domain=DOMAIN, unique_id=TEST_ADDRESS, - data={CONF_NAME: TEST_SNOOZ_DISPLAY_NAME, CONF_TOKEN: TEST_PAIRING_TOKEN}, + data={CONF_ADDRESS: TEST_ADDRESS, CONF_TOKEN: TEST_PAIRING_TOKEN}, ) entry.add_to_hass(hass) @@ -208,7 +208,7 @@ async def test_async_step_bluetooth_devices_already_setup(hass: HomeAssistant) - entry = MockConfigEntry( domain=DOMAIN, unique_id=TEST_ADDRESS, - data={CONF_NAME: TEST_SNOOZ_DISPLAY_NAME, CONF_TOKEN: TEST_PAIRING_TOKEN}, + data={CONF_ADDRESS: TEST_ADDRESS, CONF_TOKEN: TEST_PAIRING_TOKEN}, ) entry.add_to_hass(hass) @@ -262,9 +262,7 @@ async def test_async_step_user_takes_precedence_over_discovery( ) assert result["type"] is FlowResultType.FORM - await _test_setup_entry( - hass, result["flow_id"], {CONF_NAME: TEST_SNOOZ_DISPLAY_NAME} - ) + await _test_setup_entry(hass, result["flow_id"], {CONF_ADDRESS: TEST_ADDRESS}) # Verify the original one was aborted assert not hass.config_entries.flow.async_progress() @@ -291,11 +289,11 @@ async def test_user_setup_replaces_ignored_device(hass: HomeAssistant) -> None: assert result["step_id"] == "user" # Verify the ignored device is in the dropdown - assert result["data_schema"].schema["name"].container == [TEST_SNOOZ_DISPLAY_NAME] + assert result["data_schema"].schema["address"].container == { + TEST_ADDRESS: TEST_SNOOZ_DISPLAY_NAME + } - await _test_setup_entry( - hass, result["flow_id"], {CONF_NAME: TEST_SNOOZ_DISPLAY_NAME} - ) + await _test_setup_entry(hass, result["flow_id"], {CONF_ADDRESS: TEST_ADDRESS}) async def _test_pairs(