@@ -7616,3 +7616,63 @@ async def test_add_description_placeholder_automatically_not_overwrites(
7616
7616
result = await hass .config_entries .flow .async_configure (flows [0 ]["flow_id" ], None )
7617
7617
assert result ["type" ] == FlowResultType .FORM
7618
7618
assert result ["description_placeholders" ] == {"name" : "Custom title" }
7619
+
7620
+
7621
+ @pytest .mark .parametrize (
7622
+ ("domain" , "expected_log" ),
7623
+ [
7624
+ ("some_integration" , True ),
7625
+ ("mobile_app" , False ),
7626
+ ],
7627
+ )
7628
+ async def test_create_entry_existing_unique_id (
7629
+ hass : HomeAssistant ,
7630
+ domain : str ,
7631
+ expected_log : bool ,
7632
+ caplog : pytest .LogCaptureFixture ,
7633
+ ) -> None :
7634
+ """Test to highlight unexpected behavior on create_entry."""
7635
+ entry = MockConfigEntry (
7636
+ title = "From config flow" ,
7637
+ domain = domain ,
7638
+ entry_id = "01J915Q6T9F6G5V0QJX6HBC94T" ,
7639
+ data = {"host" : "any" , "port" : 123 },
7640
+ unique_id = "mock-unique-id" ,
7641
+ )
7642
+ entry .add_to_hass (hass )
7643
+
7644
+ assert len (hass .config_entries .async_entries (domain )) == 1
7645
+
7646
+ mock_setup_entry = AsyncMock (return_value = True )
7647
+
7648
+ mock_integration (hass , MockModule (domain , async_setup_entry = mock_setup_entry ))
7649
+ mock_platform (hass , f"{ domain } .config_flow" , None )
7650
+
7651
+ class TestFlow (config_entries .ConfigFlow ):
7652
+ """Test flow."""
7653
+
7654
+ VERSION = 1
7655
+
7656
+ async def async_step_user (self , user_input = None ):
7657
+ """Test user step."""
7658
+ await self .async_set_unique_id ("mock-unique-id" )
7659
+ return self .async_create_entry (title = "mock-title" , data = {})
7660
+
7661
+ with (
7662
+ mock_config_flow (domain , TestFlow ),
7663
+ patch .object (frame , "_REPORTED_INTEGRATIONS" , set ()),
7664
+ ):
7665
+ result = await hass .config_entries .flow .async_init (
7666
+ domain , context = {"source" : config_entries .SOURCE_USER }
7667
+ )
7668
+ await hass .async_block_till_done ()
7669
+ assert result ["type" ] is FlowResultType .CREATE_ENTRY
7670
+
7671
+ assert len (hass .config_entries .async_entries (domain )) == 1
7672
+
7673
+ log_text = (
7674
+ f"Detected that integration '{ domain } ' creates a config entry "
7675
+ "when another entry with the same unique ID exists. Please "
7676
+ "create a bug report at https:"
7677
+ )
7678
+ assert (log_text in caplog .text ) == expected_log
0 commit comments