@@ -37,6 +37,98 @@ async def test_full_user_flow_implementation(hass: HomeAssistant) -> None:
3737 assert result ["result" ].unique_id == "aabbccddeeff"
3838
3939
40+ @pytest .mark .usefixtures ("mock_setup_entry" , "mock_wled" )
41+ async def test_full_reconfigure_flow_success (
42+ hass : HomeAssistant , mock_config_entry : MockConfigEntry , mock_wled : MagicMock
43+ ) -> None :
44+ """Test the full reconfigure flow from start to finish."""
45+ mock_config_entry .add_to_hass (hass )
46+
47+ result = await mock_config_entry .start_reconfigure_flow (hass )
48+
49+ # Assert show form initially
50+ assert result .get ("step_id" ) == "user"
51+ assert result .get ("type" ) is FlowResultType .FORM
52+ result = await hass .config_entries .flow .async_configure (
53+ result ["flow_id" ], user_input = {CONF_HOST : "10.10.0.10" }
54+ )
55+
56+ # Assert show text message and close flow
57+ assert result .get ("type" ) is FlowResultType .ABORT
58+ assert result .get ("reason" ) == "reconfigure_successful"
59+
60+ # Assert config entry has been updated.
61+ assert mock_config_entry .data [CONF_HOST ] == "10.10.0.10"
62+
63+
64+ @pytest .mark .usefixtures ("mock_setup_entry" , "mock_wled" )
65+ async def test_full_reconfigure_flow_unique_id_mismatch (
66+ hass : HomeAssistant , mock_config_entry : MockConfigEntry , mock_wled : MagicMock
67+ ) -> None :
68+ """Test reconfiguration failure when the unique ID changes."""
69+ mock_config_entry .add_to_hass (hass )
70+
71+ # Change mac address
72+ device = mock_wled .update .return_value
73+ device .info .mac_address = "invalid"
74+
75+ result = await mock_config_entry .start_reconfigure_flow (hass )
76+
77+ # Assert show form initially
78+ assert result .get ("step_id" ) == "user"
79+ assert result .get ("type" ) is FlowResultType .FORM
80+
81+ # Input new host value
82+ result = await hass .config_entries .flow .async_configure (
83+ result ["flow_id" ], user_input = {CONF_HOST : "10.10.0.10" }
84+ )
85+
86+ # Assert Show text message and close flow
87+ assert result .get ("type" ) is FlowResultType .ABORT
88+ assert result .get ("reason" ) == "unique_id_mismatch"
89+
90+
91+ @pytest .mark .usefixtures ("mock_setup_entry" , "mock_wled" )
92+ async def test_full_reconfigure_flow_connection_error_and_success (
93+ hass : HomeAssistant , mock_config_entry : MockConfigEntry , mock_wled : MagicMock
94+ ) -> None :
95+ """Test we show user form on WLED connection error and allows user to change host."""
96+ mock_config_entry .add_to_hass (hass )
97+
98+ # Mock connection error
99+ mock_wled .update .side_effect = WLEDConnectionError
100+
101+ result = await mock_config_entry .start_reconfigure_flow (hass )
102+
103+ # Assert show form initially
104+ assert result .get ("step_id" ) == "user"
105+ assert result .get ("type" ) is FlowResultType .FORM
106+
107+ # Input new host value
108+ result = await hass .config_entries .flow .async_configure (
109+ result ["flow_id" ], user_input = {CONF_HOST : "10.10.0.10" }
110+ )
111+
112+ # Assert form with errors
113+ assert result .get ("type" ) is FlowResultType .FORM
114+ assert result .get ("step_id" ) == "user"
115+ assert result .get ("errors" ) == {"base" : "cannot_connect" }
116+
117+ # Remove mock for connection error
118+ mock_wled .update .side_effect = None
119+
120+ result = await hass .config_entries .flow .async_configure (
121+ result ["flow_id" ], user_input = {CONF_HOST : "10.10.0.10" }
122+ )
123+
124+ # Assert show text message and close flow
125+ assert result .get ("type" ) is FlowResultType .ABORT
126+ assert result .get ("reason" ) == "reconfigure_successful"
127+
128+ # Assert config entry has been updated.
129+ assert mock_config_entry .data [CONF_HOST ] == "10.10.0.10"
130+
131+
40132@pytest .mark .usefixtures ("mock_setup_entry" , "mock_wled" )
41133async def test_full_zeroconf_flow_implementation (hass : HomeAssistant ) -> None :
42134 """Test the full manual user flow from start to finish."""
0 commit comments