diff --git a/tests/common.py b/tests/common.py index 523bd12d590..c2d561551ca 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1054,7 +1054,12 @@ class MockConfigEntry(config_entries.ConfigEntry): """ self._async_set_state(hass, state, reason) - async def start_reauth_flow(self, hass: HomeAssistant) -> ConfigFlowResult: + async def start_reauth_flow( + self, + hass: HomeAssistant, + context: dict[str, Any] | None = None, + data: dict[str, Any] | None = None, + ) -> ConfigFlowResult: """Start a reauthentication flow.""" return await hass.config_entries.flow.async_init( self.domain, @@ -1063,8 +1068,9 @@ class MockConfigEntry(config_entries.ConfigEntry): "entry_id": self.entry_id, "title_placeholders": {"name": self.title}, "unique_id": self.unique_id, - }, - data=self.data, + } + | (context or {}), + data=self.data | (data or {}), ) diff --git a/tests/components/broadlink/test_config_flow.py b/tests/components/broadlink/test_config_flow.py index 2def8c0b3b9..f31cb380631 100644 --- a/tests/components/broadlink/test_config_flow.py +++ b/tests/components/broadlink/test_config_flow.py @@ -734,13 +734,9 @@ async def test_flow_reauth_works(hass: HomeAssistant) -> None: mock_entry.add_to_hass(hass) mock_api = device.get_mock_api() mock_api.auth.side_effect = blke.AuthenticationError() - data = {"name": device.name, **device.get_entry_data()} with patch(DEVICE_FACTORY, return_value=mock_api): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data - ) - + result = await mock_entry.start_reauth_flow(hass, data={"name": device.name}) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "reset" @@ -770,12 +766,8 @@ async def test_flow_reauth_invalid_host(hass: HomeAssistant) -> None: mock_entry.add_to_hass(hass) mock_api = device.get_mock_api() mock_api.auth.side_effect = blke.AuthenticationError() - data = {"name": device.name, **device.get_entry_data()} - with patch(DEVICE_FACTORY, return_value=mock_api): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data - ) + result = await mock_entry.start_reauth_flow(hass, data={"name": device.name}) device.mac = get_device("Office").mac mock_api = device.get_mock_api() @@ -804,12 +796,9 @@ async def test_flow_reauth_valid_host(hass: HomeAssistant) -> None: mock_entry.add_to_hass(hass) mock_api = device.get_mock_api() mock_api.auth.side_effect = blke.AuthenticationError() - data = {"name": device.name, **device.get_entry_data()} with patch(DEVICE_FACTORY, return_value=mock_api): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data - ) + result = await mock_entry.start_reauth_flow(hass, data={"name": device.name}) device.host = "192.168.1.128" mock_api = device.get_mock_api() diff --git a/tests/components/bthome/test_config_flow.py b/tests/components/bthome/test_config_flow.py index acf490d341e..faf2f1c9ef5 100644 --- a/tests/components/bthome/test_config_flow.py +++ b/tests/components/bthome/test_config_flow.py @@ -563,16 +563,7 @@ async def test_async_step_reauth_abort_early(hass: HomeAssistant) -> None: device = DeviceData() - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={ - "source": config_entries.SOURCE_REAUTH, - "entry_id": entry.entry_id, - "title_placeholders": {"name": entry.title}, - "unique_id": entry.unique_id, - }, - data=entry.data | {"device": device}, - ) + result = await entry.start_reauth_flow(hass, data={"device": device}) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reauth_successful"